From: Roy Marples Date: Mon, 9 Oct 2023 11:20:08 +0000 (+0100) Subject: privsep: Log script exit status. X-Git-Tag: v10.0.4~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=617a3ae207898a968bccd1e40a299fbfa6a4cc52;p=thirdparty%2Fdhcpcd.git privsep: Log script exit status. --- diff --git a/src/script.c b/src/script.c index 2ef99e38..69297a46 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