main: handle execv failure

Log an error, exit daemon
This commit is contained in:
Wim Taymans 2020-01-08 12:38:46 +01:00
parent ffbb74c4af
commit aa36a72427
3 changed files with 13 additions and 4 deletions

View file

@ -28,6 +28,7 @@
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <sys/wait.h>
#include <pipewire/impl.h>
@ -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;
}

View file

@ -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;
}

View file

@ -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;
}