From 62241668df792dd47a66ed8413ce38ff45464a25 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 3 Jun 2021 12:18:08 +0200 Subject: [PATCH] Drop SIGSTOP/TSTP/CONT handlers, not needed anymore Once upon a time, SIGSTOP was used to pause Finit during flashing (MTD) of a system image. This to prevent Finit from accidentally starting any programs, i.e., reading from flash disk during or after upgrade. This was quite intrusive, and has possible nasty side effects, e.g., any process with root access sends SIGSTOP prevents TTY login. So this patch now removes the functionality and recommends using a dedcicated runlevel for such critical tasks instead. Signed-off-by: Joachim Wiberg --- src/exec.c | 11 +---------- src/service.c | 3 +-- src/sig.c | 44 -------------------------------------------- src/sig.h | 2 -- 4 files changed, 2 insertions(+), 58 deletions(-) diff --git a/src/exec.c b/src/exec.c index 87fcbd6c..e7ba451d 100644 --- a/src/exec.c +++ b/src/exec.c @@ -301,29 +301,20 @@ static int activate_console(int noclear, int nowait) tcsetattr(STDIN_FILENO, TCSAFLUSH, &c); } - while (!fexist(SYNC_SHUTDOWN)) { + if (!fexist(SYNC_SHUTDOWN)) { char c; static const char clr[] = "\r\e[2K"; static const char cup[] = "\e[A"; static const char msg[] = "\nPlease press Enter to activate this console."; - if (fexist(SYNC_STOPPED)) { - sleep(5); - continue; - } - dprint(STDERR_FILENO, clr, strlen(clr)); dprint(STDERR_FILENO, msg, strlen(msg)); while (read(STDIN_FILENO, &c, 1) == 1 && c != '\r') continue; - if (fexist(SYNC_STOPPED)) - continue; - dprint(STDERR_FILENO, clr, strlen(clr)); dprint(STDERR_FILENO, cup, strlen(cup)); ret = 1; - break; } /* Restore TTY */ diff --git a/src/service.c b/src/service.c index bdb1324a..c86e33f2 100644 --- a/src/service.c +++ b/src/service.c @@ -347,8 +347,7 @@ static void source_env(svc_t *svc) static int is_norespawn(void) { - return sig_stopped() || - fexist("/mnt/norespawn") || + return fexist("/mnt/norespawn") || fexist("/tmp/norespawn"); } diff --git a/src/sig.c b/src/sig.c index 0d002464..06fb3798 100644 --- a/src/sig.c +++ b/src/sig.c @@ -96,11 +96,9 @@ extern svc_t *wdog; */ shutop_t halt = SHUT_DEFAULT; -static int stopped = 0; static uev_t sigterm_watcher, sigusr1_watcher, sigusr2_watcher; static uev_t sighup_watcher, sigint_watcher, sigpwr_watcher; static uev_t sigchld_watcher; -static uev_t sigstop_watcher, sigtstp_watcher, sigcont_watcher; static struct sigmap { int num; @@ -416,42 +414,6 @@ static void sigchld_cb(uev_t *w, void *arg, int events) } } -/* - * SIGSTOP/SIGTSTP: Paused by user or netflash - */ -static void sigstop_cb(uev_t *w, void *arg, int events) -{ - if (UEV_ERROR == events) { - _e("Unrecoverable error in signal watcher"); - return; - } - - touch(SYNC_STOPPED); - stopped++; -} - -/* - * SIGCONT: Restart service monitor - */ -static void sigcont_cb(uev_t *w, void *arg, int events) -{ - if (UEV_ERROR == events) { - _e("Unrecoverable error in signal watcher"); - return; - } - - stopped = 0; - erase(SYNC_STOPPED); -} - -/* - * Is SIGSTOP asserted? - */ -int sig_stopped(void) -{ - return stopped; -} - /* * Convert SIGFOO to a number, if it exists */ @@ -541,7 +503,6 @@ void sig_setup(uev_ctx_t *ctx) /* Cleanup any stale finit control files */ erase(SYNC_SHUTDOWN); - erase(SYNC_STOPPED); /* * Standard SysV init calls ctrl-alt-delete handler @@ -565,11 +526,6 @@ void sig_setup(uev_ctx_t *ctx) /* After initial bootstrap of Finit we call the service monitor to reap children */ uev_signal_init(ctx, &sigchld_watcher, sigchld_cb, NULL, SIGCHLD); - /* Stopping init is a bit tricky. */ - uev_signal_init(ctx, &sigstop_watcher, sigstop_cb, NULL, SIGSTOP); - uev_signal_init(ctx, &sigtstp_watcher, sigstop_cb, NULL, SIGTSTP); - uev_signal_init(ctx, &sigcont_watcher, sigcont_cb, NULL, SIGCONT); - setsid(); } diff --git a/src/sig.h b/src/sig.h index 62e17c13..a8820ab0 100644 --- a/src/sig.h +++ b/src/sig.h @@ -29,7 +29,6 @@ #include #define SYNC_SHUTDOWN "/var/run/finit/.shutdown" -#define SYNC_STOPPED "/var/run/finit/.stopped" #define SETSIG(sa, sig, fun, flags) \ do { \ @@ -69,7 +68,6 @@ typedef enum { extern shutop_t halt; void do_shutdown (shutop_t op); -int sig_stopped (void); int sig_num (const char *name); void sig_init (void); void sig_unblock (void);