Skip to content

Commit

Permalink
privsep: Log script exit status.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsmarples committed Oct 9, 2023
1 parent 45fb8fd commit 617a3ae
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 617a3ae

Please sign in to comment.