X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=fade.c;h=36ff1fc1fdc1342f68590b3327a7fcfffe877ac4;hb=3a258056d2137c3a4c10d717c6bb2e92d91ee3e0;hp=1aced9df5ad732aa4208dcbd87105b555425303b;hpb=65453788515cd5f4c905b518745b4dd7f6f2da10;p=paraslash.git diff --git a/fade.c b/fade.c index 1aced9df..36ff1fc1 100644 --- a/fade.c +++ b/fade.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1998-2011 Andre Noll + * Copyright (C) 1998-2012 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -9,12 +9,7 @@ #include #include #include -#include -#include /* EXIT_SUCCESS */ -#include #include -#include -#include #include #include "fade.cmdline.h" @@ -181,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); @@ -189,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) @@ -204,7 +209,7 @@ static void change_afs_mode_and_play(char *afs_mode) client_cmd("stop"); if (!afs_mode) return; - cmd = make_message("select %s\n", afs_mode); + cmd = make_message("select %s", afs_mode); client_cmd(cmd); free(cmd); client_cmd("play"); @@ -288,11 +293,9 @@ static int sweet_dreams(void) static int snooze(void) { int ret; - unsigned sleep_time; if (conf.so_time_arg <= 0) return 1; - sleep_time = conf.so_time_arg; if (open_and_get_mixer_channel() < conf.so_vol_arg) ret = open_and_set_mixer_channel(conf.so_vol_arg); else @@ -301,7 +304,7 @@ static int snooze(void) return ret; client_cmd("pause"); PARA_NOTICE_LOG("%d seconds snooze time...\n", conf.snooze_time_arg); - sleep(sleep_time); + sleep(conf.snooze_time_arg); client_cmd("play"); return fade(conf.si_vol_arg, conf.si_time_arg); }