fade: Abort on client command failures.
authorAndre Noll <maan@systemlinux.org>
Mon, 2 Jul 2012 06:40:31 +0000 (08:40 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 7 Oct 2012 09:12:07 +0000 (11:12 +0200)
Currently, we check only the exit code of wait(), but do not look
at the exit status of the child. So the fade command continues
even if all para_client commands fail.

Fix this by investigating the termination status of the child
process.

fade.c

diff --git a/fade.c b/fade.c
index ca9f08a..36ff1fc 100644 (file)
--- a/fade.c
+++ b/fade.c
@@ -176,7 +176,7 @@ out:
 
 static void client_cmd(const char *cmd)
 {
-       int ret, fds[3] = {0, 0, 0};
+       int ret, status, fds[3] = {0, 0, 0};
        pid_t pid;
        char *cmdline = make_message(BINDIR "/para_client %s", cmd);
 
@@ -184,12 +184,22 @@ static void client_cmd(const char *cmd)
        ret = para_exec_cmdline_pid(&pid, cmdline, fds);
        free(cmdline);
        if (ret < 0) {
-               PARA_EMERG_LOG("%s\n", para_strerror(-ret));
-               exit(EXIT_FAILURE);
+               PARA_ERROR_LOG("%s\n", para_strerror(-ret));
+               goto fail;
        }
        do
-               ret = wait(NULL);
-       while (ret != -1 && errno != ECHILD);
+               pid = waitpid(pid, &status, 0);
+       while (pid == -1 && errno == EINTR);
+       if (pid < 0) {
+               PARA_ERROR_LOG("%s\n", strerror(errno));
+               goto fail;
+       }
+       if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+               goto fail;
+       return;
+fail:
+       PARA_EMERG_LOG("command \"%s\" failed\n", cmd);
+       exit(EXIT_FAILURE);
 }
 
 static void change_afs_mode_and_play(char *afs_mode)