From aa36a72427382a22f7d65979c0405addeb324267 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 8 Jan 2020 12:38:46 +0100 Subject: [PATCH] main: handle execv failure Log an error, exit daemon --- src/daemon/command.c | 14 +++++++++++--- src/daemon/daemon-config.c | 2 +- src/daemon/main.c | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/daemon/command.c b/src/daemon/command.c index 295358010..b42521122 100644 --- a/src/daemon/command.c +++ b/src/daemon/command.c @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -216,16 +217,23 @@ no_mem: static int execute_command_exec(struct pw_command *command, struct pw_context *context, char **err) { - int pid; + int pid, res; pid = fork(); if (pid == 0) { pw_log_info("exec %s", command->args[1]); - execv(command->args[1], command->args); + res = execv(command->args[1], command->args); + if (res == -1) { + res = -errno; + asprintf(err, "'%s': %m", command->args[1]); + return res; + } } else { - pw_log_info("exec got pid %d", pid); + int status; + res = waitpid(pid, &status, WNOHANG); + pw_log_info("exec got pid %d res:%d status:%d", pid, res, status); } return 0; } diff --git a/src/daemon/daemon-config.c b/src/daemon/daemon-config.c index 909003e04..3b0ecc382 100644 --- a/src/daemon/daemon-config.c +++ b/src/daemon/daemon-config.c @@ -200,7 +200,7 @@ int pw_daemon_config_run_commands(struct pw_daemon_config *config, struct pw_con spa_list_for_each(command, &config->commands, link) { if ((ret = pw_command_run(command, context, &err)) < 0) { - pw_log_warn("could not run command %s: %s", command->args[0], err); + pw_log_error("could not run command %s: %s", command->args[0], err); free(err); break; } diff --git a/src/daemon/main.c b/src/daemon/main.c index 58f2aab9b..01eb2c717 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -120,6 +120,7 @@ int main(int argc, char *argv[]) if ((res = pw_daemon_config_run_commands(config, context)) < 0) { pw_log_error("failed to run config commands: %s", spa_strerror(res)); + pw_main_loop_quit(loop); return -1; }