From 04983269629f104a6ffb22b9d74f80041fb4059e Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 23 Nov 2022 21:49:30 +0100 Subject: [PATCH] Fix #318: only show "[ OK ] Calling foo" progress for `runparts ...` For all other run_parts() use-cases we just give the script control over stdout/stderr to prevent clobbering ANSI color escape codes. Signed-off-by: Joachim Wiberg --- plugins/resolvconf.c | 2 +- src/exec.c | 8 +++++--- src/finit.c | 2 +- src/helpers.h | 2 +- src/plugin.c | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/resolvconf.c b/plugins/resolvconf.c index fbc7c0a8..33f18f3c 100644 --- a/plugins/resolvconf.c +++ b/plugins/resolvconf.c @@ -45,7 +45,7 @@ static void setup(void *arg) touch("/etc/resolvconf/run/enable-updates"); chdir("/etc/resolvconf/run/interface"); - run_parts("/etc/resolvconf/update.d", "-i"); + run_parts("/etc/resolvconf/update.d", "-i", 0); chdir("/"); } diff --git a/src/exec.c b/src/exec.c index a725d952..4a16c7dd 100644 --- a/src/exec.c +++ b/src/exec.c @@ -441,7 +441,7 @@ pid_t run_sh(char *tty, int noclear, int nowait, struct rlimit rlimit[]) return rc; } -int run_parts(char *dir, char *cmd) +int run_parts(char *dir, char *cmd, int progress) { struct dirent **e; int i, num; @@ -490,7 +490,8 @@ int run_parts(char *dir, char *cmd) strlcat(path, cmd, sizeof(path)); } - print_desc("Calling ", path); + if (progress) + print_desc("Calling ", path); pid = fork(); if (!pid) { sig_unblock(); @@ -503,7 +504,8 @@ int run_parts(char *dir, char *cmd) warnx("%s exited with status %d", path, exit_status); else if (WIFSIGNALED(status)) warnx("%s terminated by signad %d", path, WTERMSIG(status)); - print_result(status); + if (progress) + print_result(status); } while (num--) diff --git a/src/finit.c b/src/finit.c index ffbf72a8..2451dd51 100644 --- a/src/finit.c +++ b/src/finit.c @@ -602,7 +602,7 @@ static void bootstrap_worker(void *work) * Run startup scripts in the runparts directory, if any. */ if (runparts && fisdir(runparts) && !rescue) - run_parts(runparts, NULL); + run_parts(runparts, NULL, 1); /* diff --git a/src/helpers.h b/src/helpers.h index 418e39b4..f3d9c010 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -86,7 +86,7 @@ int run_interactive (char *cmd, char *fmt, ...) __attribute__ ((format (prin int exec_runtask (char *cmd, char *args[]); pid_t run_getty (char *tty, char *cmd, char *args[], int noclear, int nowait, struct rlimit rlimit[]); pid_t run_sh (char *tty, int noclear, int nowait, struct rlimit rlimit[]); -int run_parts (char *dir, char *cmd); +int run_parts (char *dir, char *cmd, int progress); static inline int create(char *path, mode_t mode, uid_t uid, gid_t gid) { diff --git a/src/plugin.c b/src/plugin.c index 35be6a37..4fb4ddfa 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -208,7 +208,7 @@ void plugin_script_run(hook_point_t no) strlcat(path, PLUGIN_HOOK_SCRIPTS_PATH, sizeof(path)); strlcat(path, hscript_paths[no] + 4, sizeof(path)); - run_parts(path, NULL); + run_parts(path, NULL, 0); } #else void plugin_script_run(hook_point_t no)