From e97b512f79ce56c2537e548089558e3f4392c8bf Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Thu, 10 Oct 2019 02:18:37 +0300 Subject: [PATCH] refactoring --- src/options.c | 10 +++++----- src/process.h | 11 +++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/options.c b/src/options.c index 192a776..2636deb 100644 --- a/src/options.c +++ b/src/options.c @@ -108,7 +108,7 @@ enum _OPT_VALUES { _O_GPIO_WORKERS_BUSY_AT, #endif -#ifdef HAS_PROCESS_SET_SIGTERM_ON_PARENT_DEATH +#ifdef HAS_PDEATHSIG _O_EXIT_ON_PARENT_DEATH, #endif @@ -176,7 +176,7 @@ static const struct option _LONG_OPTS[] = { {"gpio-workers-busy-at", required_argument, NULL, _O_GPIO_WORKERS_BUSY_AT}, #endif -#ifdef HAS_PROCESS_SET_SIGTERM_ON_PARENT_DEATH +#ifdef HAS_PDEATHSIG {"exit-on-parent-death", no_argument, NULL, _O_EXIT_ON_PARENT_DEATH}, #endif @@ -342,8 +342,8 @@ int parse_options(int argc, char *argv[], struct device_t *dev, struct encoder_t case _O_GPIO_WORKERS_BUSY_AT: OPT_NUMBER("--gpio-workers-busy-at", gpio_pin_workers_busy_at, 0, 256, 0); # endif -# ifdef HAS_PROCESS_SET_SIGTERM_ON_PARENT_DEATH - case _O_EXIT_ON_PARENT_DEATH: process_set_sigterm_on_parent_death(); break; +# ifdef HAS_PDEATHSIG + case _O_EXIT_ON_PARENT_DEATH: process_set_pdeathsig_sigterm(); break; # endif case _O_LOG_LEVEL: OPT_NUMBER("--log-level", log_level, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, 0); @@ -552,7 +552,7 @@ static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_s printf(" --gpio-workers-busy-at ── Set 1 on (pin + N) while worker with number N has a job.\n"); printf(" The worker's numbering starts from 0. Default: disabled\n\n"); #endif -#ifdef HAS_PROCESS_SET_SIGTERM_ON_PARENT_DEATH +#ifdef HAS_PDEATHSIG printf("Process options:\n"); printf("════════════════\n"); printf(" --exit-on-parent-death ─ Exit the program if the parent process is dead. Default: disabled.\n\n"); diff --git a/src/process.h b/src/process.h index f4550ea..965e68a 100644 --- a/src/process.h +++ b/src/process.h @@ -23,15 +23,15 @@ #pragma once #if defined(__linux__) -# define HAS_PROCESS_SET_SIGTERM_ON_PARENT_DEATH +# define HAS_PDEATHSIG #elif defined(__FreeBSD__) # include # if __FreeBSD_version >= 1102000 -# define HAS_PROCESS_SET_SIGTERM_ON_PARENT_DEATH +# define HAS_PDEATHSIG # endif #endif -#ifdef HAS_PROCESS_SET_SIGTERM_ON_PARENT_DEATH +#ifdef HAS_PDEATHSIG # include # if defined(__linux__) @@ -42,8 +42,7 @@ # include "logging.h" - -INLINE void process_set_sigterm_on_parent_death(void) { +INLINE void process_set_pdeathsig_sigterm(void) { int signum = SIGTERM; # ifdef __linux__ int retval = prctl(PR_SET_PDEATHSIG, signum); @@ -57,4 +56,4 @@ INLINE void process_set_sigterm_on_parent_death(void) { } } -#endif +#endif // HAS_PDEATHSIG