From 617a3ae207898a968bccd1e40a299fbfa6a4cc52 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Mon, 9 Oct 2023 12:20:08 +0100 Subject: [PATCH] privsep: Log script exit status. --- src/script.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/script.c b/src/script.c index 2ef99e38f..69297a466 100644 --- a/src/script.c +++ b/src/script.c @@ -681,6 +681,21 @@ send_interface(struct fd_list *fd, const struct interface *ifp, int af) return retval; } +static int +script_status(const char *script, int status) +{ + + if (WIFEXITED(status)) { + if (WEXITSTATUS(status)) + logerrx("%s: %s: WEXITSTATUS %d", + __func__, script, WEXITSTATUS(status)); + } else if (WIFSIGNALED(status)) + logerrx("%s: %s: %s", + __func__, script, strsignal(WTERMSIG(status))); + + return WEXITSTATUS(status); +} + static int script_run(struct dhcpcd_ctx *ctx, char **argv) { @@ -699,13 +714,7 @@ script_run(struct dhcpcd_ctx *ctx, char **argv) break; } } - if (WIFEXITED(status)) { - if (WEXITSTATUS(status)) - logerrx("%s: %s: WEXITSTATUS %d", - __func__, argv[0], WEXITSTATUS(status)); - } else if (WIFSIGNALED(status)) - logerrx("%s: %s: %s", - __func__, argv[0], strsignal(WTERMSIG(status))); + status = script_status(argv[0], status); } return WEXITSTATUS(status); @@ -763,9 +772,13 @@ script_runreason(const struct interface *ifp, const char *reason) #ifdef PRIVSEP if (ctx->options & DHCPCD_PRIVSEP) { - if (ps_root_script(ctx, - ctx->script_buf, (size_t)buflen) == -1) + ssize_t err; + + err = ps_root_script(ctx, ctx->script_buf, (size_t)buflen); + if (err == -1) logerr(__func__); + else + script_status(ctx->script, (int)err); goto send_listeners; } #endif