Improved logging on failure to execvp() in forked child

The execvp() call always fails with -1, so only logging exit code when
collecting the PID is not enough.  When debugging the user needs to see
the errno from execvp(), e.g., "No such file or directory", when the
command was missing the absolute path to the executable.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-07-10 10:23:20 +02:00
parent 450f498061
commit 9c8cd6c024
+3 -1
View File
@@ -790,7 +790,7 @@ static int service_start(svc_t *svc)
*/
pid = setsid();
if (pid < 1)
logit(LOG_ERR, "failed setsid(), pid %d: %s", pid, strerror(errno));
syslog(LOG_ERR, "failed setsid(), pid %d: %s", pid, strerror(errno));
sig_unblock();
@@ -801,6 +801,8 @@ static int service_start(svc_t *svc)
else
status = execvp(args[0], &args[1]);
syslog(LOG_ERR, "failed starting %s, exit code %d: %s", svc_ident(svc, NULL, 0),
status, strerror(errno));
_exit(status);
} else if (debug) {
dbg("Starting PID %d: %s", svc->pid, cmdline);