From b089f896dad33b7c455fcdeeb915e573d6178e73 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Thu, 3 Jul 2025 03:49:02 +0300 Subject: [PATCH] pikvm/pikvm#312: --exit-on-device-error --- man/ustreamer.1 | 3 +++ src/ustreamer/options.c | 3 +++ src/ustreamer/stream.c | 4 ++++ src/ustreamer/stream.h | 1 + 4 files changed, 11 insertions(+) diff --git a/man/ustreamer.1 b/man/ustreamer.1 index 7307d64..2014483 100644 --- a/man/ustreamer.1 +++ b/man/ustreamer.1 @@ -276,6 +276,9 @@ Timeout for lock. Default: 1. .BR \-\-exit\-on\-parent\-death Exit the program if the parent process is dead. Required \fBWITH_PDEATHSIG\fR feature. Default: disabled. .TP +.BR \-\-exit\-on\-device\-error +Exit on any device error instead of polling until success. Default: disabled. +.TP .BR \-\-exit\-on\-no\-clients \fIsec Exit the program if there have been no stream or sink clients or any HTTP requests in the last N seconds. Default: 0 (disabled). .TP diff --git a/src/ustreamer/options.c b/src/ustreamer/options.c index 506fdb1..248899d 100644 --- a/src/ustreamer/options.c +++ b/src/ustreamer/options.c @@ -117,6 +117,7 @@ enum _US_OPT_VALUES { # ifdef WITH_PDEATHSIG _O_EXIT_ON_PARENT_DEATH, # endif + _O_EXIT_ON_DEVICE_ERROR, _O_EXIT_ON_NO_CLIENTS, # ifdef WITH_SETPROCTITLE _O_PROCESS_NAME_PREFIX, @@ -227,6 +228,7 @@ static const struct option _LONG_OPTS[] = { # ifdef WITH_PDEATHSIG {"exit-on-parent-death", no_argument, NULL, _O_EXIT_ON_PARENT_DEATH}, # endif + {"exit-on-device-error", no_argument, NULL, _O_EXIT_ON_DEVICE_ERROR}, {"exit-on-no-clients", required_argument, NULL, _O_EXIT_ON_NO_CLIENTS}, # ifdef WITH_SETPROCTITLE {"process-name-prefix", required_argument, NULL, _O_PROCESS_NAME_PREFIX}, @@ -490,6 +492,7 @@ int options_parse(us_options_s *options, us_capture_s *cap, us_encoder_s *enc, u }; break; # endif + case _O_EXIT_ON_DEVICE_ERROR: OPT_SET(stream->exit_on_device_error, true); case _O_EXIT_ON_NO_CLIENTS: OPT_NUMBER("--exit-on-no-clients", stream->exit_on_no_clients, 0, 86400, 0); # ifdef WITH_SETPROCTITLE case _O_PROCESS_NAME_PREFIX: OPT_SET(process_name_prefix, optarg); diff --git a/src/ustreamer/stream.c b/src/ustreamer/stream.c index 700939e..7916e88 100644 --- a/src/ustreamer/stream.c +++ b/src/ustreamer/stream.c @@ -612,6 +612,10 @@ static int _stream_init_loop(us_stream_s *stream) { goto offline_and_retry; offline_and_retry: + if (stream->exit_on_device_error) { + US_LOG_INFO("Device error, exiting ..."); + us_process_suicide(); + } for (uint count = 0; count < stream->error_delay * 10; ++count) { if (atomic_load(&run->stop)) { break; diff --git a/src/ustreamer/stream.h b/src/ustreamer/stream.h index 8c98037..c56424f 100644 --- a/src/ustreamer/stream.h +++ b/src/ustreamer/stream.h @@ -80,6 +80,7 @@ typedef struct { bool notify_parent; bool slowdown; uint error_delay; + bool exit_on_device_error; uint exit_on_no_clients; us_memsink_s *jpeg_sink;