manual WITH_PDEATHSIG

This commit is contained in:
Maxim Devaev
2025-02-08 01:56:59 +02:00
parent f3e0613de3
commit b2d1a5612d
5 changed files with 23 additions and 22 deletions

View File

@@ -22,6 +22,7 @@ WITH_GPIO ?= 0
WITH_SYSTEMD ?= 0 WITH_SYSTEMD ?= 0
WITH_PTHREAD_NP ?= 1 WITH_PTHREAD_NP ?= 1
WITH_SETPROCTITLE ?= 1 WITH_SETPROCTITLE ?= 1
WITH_PDEATHSIG ?= 1
export export

View File

@@ -274,7 +274,7 @@ Timeout for lock. Default: 1.
.SS "Process options" .SS "Process options"
.TP .TP
.BR \-\-exit\-on\-parent\-death .BR \-\-exit\-on\-parent\-death
Exit the program if the parent process is dead. Required \fBHAS_PDEATHSIG\fR feature. Default: disabled. Exit the program if the parent process is dead. Required \fBWITH_PDEATHSIG\fR feature. Default: disabled.
.TP .TP
.BR \-\-exit\-on\-no\-clients \fIsec .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). Exit the program if there have been no stream or sink clients or any HTTP requests in the last N seconds. Default: 0 (disabled).

View File

@@ -73,6 +73,10 @@ override _USTR_LDFLAGS += -lbsd
endif endif
endif endif
ifneq ($(call optbool,$(WITH_PDEATHSIG)),)
override _CFLAGS += -DWITH_PDEATHSIG
endif
ifneq ($(call optbool,$(WITH_V4P)),) ifneq ($(call optbool,$(WITH_V4P)),)
override _TARGETS += $(_V4P) override _TARGETS += $(_V4P)
override _OBJS += $(_V4P_SRCS:%.c=$(_BUILD)/%.o) override _OBJS += $(_V4P_SRCS:%.c=$(_BUILD)/%.o)

View File

@@ -25,14 +25,8 @@
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#if defined(__FreeBSD__)
#if defined(__linux__)
# define HAS_PDEATHSIG
#elif defined(__FreeBSD__)
# include <sys/param.h> # include <sys/param.h>
# if __FreeBSD_version >= 1102000
# define HAS_PDEATHSIG
# endif
#endif #endif
@@ -49,20 +43,22 @@
# error setproctitle() not implemented, you can disable it using WITH_SETPROCTITLE=0 # error setproctitle() not implemented, you can disable it using WITH_SETPROCTITLE=0
# endif # endif
#endif #endif
#ifdef HAS_PDEATHSIG
#ifdef WITH_PDEATHSIG
# if defined(__linux__) # if defined(__linux__)
# include <sys/prctl.h> # include <sys/prctl.h>
# elif defined(__FreeBSD__) # elif defined(__FreeBSD__) && (__FreeBSD_version >= 1102000)
# include <sys/procctl.h> # include <sys/procctl.h>
# else
# error WITH_PDEATHSIG is not supported on your system
# endif # endif
#endif #endif
#include "types.h" #include "types.h"
#ifdef WITH_SETPROCTITLE #ifdef WITH_SETPROCTITLE
# include "tools.h" # include "tools.h"
#endif #endif
#ifdef HAS_PDEATHSIG #include "logging.h"
# include "logging.h"
#endif
#ifdef WITH_SETPROCTITLE #ifdef WITH_SETPROCTITLE
@@ -70,7 +66,7 @@ extern char **environ;
#endif #endif
#ifdef HAS_PDEATHSIG #ifdef WITH_PDEATHSIG
INLINE int us_process_track_parent_death(void) { INLINE int us_process_track_parent_death(void) {
const pid_t parent = getppid(); const pid_t parent = getppid();
int signum = SIGTERM; int signum = SIGTERM;

View File

@@ -114,7 +114,7 @@ enum _US_OPT_VALUES {
_O_GPIO_HAS_HTTP_CLIENTS, _O_GPIO_HAS_HTTP_CLIENTS,
# endif # endif
# ifdef HAS_PDEATHSIG # ifdef WITH_PDEATHSIG
_O_EXIT_ON_PARENT_DEATH, _O_EXIT_ON_PARENT_DEATH,
# endif # endif
_O_EXIT_ON_NO_CLIENTS, _O_EXIT_ON_NO_CLIENTS,
@@ -224,7 +224,7 @@ static const struct option _LONG_OPTS[] = {
{"gpio-has-http-clients", required_argument, NULL, _O_GPIO_HAS_HTTP_CLIENTS}, {"gpio-has-http-clients", required_argument, NULL, _O_GPIO_HAS_HTTP_CLIENTS},
# endif # endif
# ifdef HAS_PDEATHSIG # ifdef WITH_PDEATHSIG
{"exit-on-parent-death", no_argument, NULL, _O_EXIT_ON_PARENT_DEATH}, {"exit-on-parent-death", no_argument, NULL, _O_EXIT_ON_PARENT_DEATH},
# endif # endif
{"exit-on-no-clients", required_argument, NULL, _O_EXIT_ON_NO_CLIENTS}, {"exit-on-no-clients", required_argument, NULL, _O_EXIT_ON_NO_CLIENTS},
@@ -483,7 +483,7 @@ int options_parse(us_options_s *options, us_capture_s *cap, us_encoder_s *enc, u
case _O_GPIO_HAS_HTTP_CLIENTS: OPT_NUMBER("--gpio-has-http-clients", us_g_gpio.has_http_clients.pin, 0, 256, 0); case _O_GPIO_HAS_HTTP_CLIENTS: OPT_NUMBER("--gpio-has-http-clients", us_g_gpio.has_http_clients.pin, 0, 256, 0);
# endif # endif
# ifdef HAS_PDEATHSIG # ifdef WITH_PDEATHSIG
case _O_EXIT_ON_PARENT_DEATH: case _O_EXIT_ON_PARENT_DEATH:
if (us_process_track_parent_death() < 0) { if (us_process_track_parent_death() < 0) {
return -1; return -1;
@@ -611,10 +611,10 @@ static void _features(void) {
puts("- WITH_SETPROCTITLE"); puts("- WITH_SETPROCTITLE");
# endif # endif
# ifdef HAS_PDEATHSIG # ifdef WITH_PDEATHSIG
puts("+ HAS_PDEATHSIG"); puts("+ WITH_PDEATHSIG");
# else # else
puts("- HAS_PDEATHSIG"); puts("- WITH_PDEATHSIG");
# endif # endif
} }
@@ -746,11 +746,11 @@ static void _help(FILE *fp, const us_capture_s *cap, const us_encoder_s *enc, co
SAY(" --gpio-stream-online <pin> ──── Set 1 while streaming. Default: disabled.\n"); SAY(" --gpio-stream-online <pin> ──── Set 1 while streaming. Default: disabled.\n");
SAY(" --gpio-has-http-clients <pin> ─ Set 1 while stream has at least one client. Default: disabled.\n"); SAY(" --gpio-has-http-clients <pin> ─ Set 1 while stream has at least one client. Default: disabled.\n");
# endif # endif
# if (defined(HAS_PDEATHSIG) || defined(WITH_SETPROCTITLE)) # if (defined(WITH_PDEATHSIG) || defined(WITH_SETPROCTITLE))
SAY("Process options:"); SAY("Process options:");
SAY("════════════════"); SAY("════════════════");
# endif # endif
# ifdef HAS_PDEATHSIG # ifdef WITH_PDEATHSIG
SAY(" --exit-on-parent-death ─────── Exit the program if the parent process is dead. Default: disabled.\n"); SAY(" --exit-on-parent-death ─────── Exit the program if the parent process is dead. Default: disabled.\n");
# endif # endif
SAY(" --exit-on-no-clients <sec> ──── Exit the program if there have been no stream or sink clients"); SAY(" --exit-on-no-clients <sec> ──── Exit the program if there have been no stream or sink clients");