]> git.tuebingen.mpg.de Git - dss.git/blobdiff - signal.c
Make the dss log facility C89 conform.
[dss.git] / signal.c
index c82e58b29af65fff20b77d5180217cd9c01b8bea..cc1a3ef8a52033d9d645bebf39f71b98b9eb970e 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004-2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2004-2010 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -16,6 +16,7 @@
 #include <unistd.h>
 #include <signal.h>
 #include <stdlib.h>
+#include <sys/select.h>
 
 
 #include "gcc-compat.h"
@@ -23,6 +24,7 @@
 #include "log.h"
 #include "string.h"
 #include "fd.h"
+#include "signal.h"
 
 static int signal_pipe[2];
 
@@ -59,7 +61,7 @@ int signal_init(void)
                goto err_out;
        return signal_pipe[0];
 err_out:
-       DSS_EMERG_LOG("%s\n", dss_strerror(-ret));
+       DSS_EMERG_LOG(("%s\n", dss_strerror(-ret)));
        exit(EXIT_FAILURE);
 }
 
@@ -69,7 +71,6 @@ err_out:
 static void generic_signal_handler(int s)
 {
        write(signal_pipe[1], &s, sizeof(int));
-       //fprintf(stderr, "got sig %i\n", s);
 }
 
 /**
@@ -86,23 +87,22 @@ static void generic_signal_handler(int s)
  *
  * \sa waitpid(2)
  */
-int reap_child(pid_t *pid)
+int reap_child(pid_t *pid, int *status)
 {
-       int status;
-       *pid = waitpid(-1, &status, WNOHANG);
+       *pid = waitpid(-1, status, WNOHANG);
 
        if (!*pid)
                return 0;
        if (*pid < 0)
                return -ERRNO_TO_DSS_ERROR(errno);
-       if (WIFEXITED(status))
-               DSS_DEBUG_LOG("child %i exited. Exit status: %i\n", (int)*pid,
-                       WEXITSTATUS(status));
-       else if (WIFSIGNALED(status))
-               DSS_DEBUG_LOG("child %i was killed by signal %i\n", (int)*pid,
-                       WTERMSIG(status));
+       if (WIFEXITED(*status))
+               DSS_DEBUG_LOG(("child %i exited. Exit status: %i\n", (int)*pid,
+                       WEXITSTATUS(*status)));
+       else if (WIFSIGNALED(*status))
+               DSS_DEBUG_LOG(("child %i was killed by signal %i\n", (int)*pid,
+                       WTERMSIG(*status)));
        else
-               DSS_WARNING_LOG("child %i terminated abormally\n", (int)*pid);
+               DSS_WARNING_LOG(("child %i terminated abormally\n", (int)*pid));
        return 1;
 }
 
@@ -118,10 +118,9 @@ int reap_child(pid_t *pid)
  */
 int install_sighandler(int sig)
 {
-       DSS_DEBUG_LOG("catching signal %d\n", sig);
+       DSS_DEBUG_LOG(("catching signal %d\n", sig));
        if (signal(sig, &generic_signal_handler) != SIG_ERR)
                return 1;
-       make_err_msg("signal %d", sig);
        return -E_SIGNAL_SIG_ERR;
 }
 
@@ -141,14 +140,14 @@ int next_signal(void)
 
        r = read(signal_pipe[0], &s, sizeof(s));
        if (r == sizeof(s)) {
-               DSS_DEBUG_LOG("next signal: %d\n", s);
+               DSS_DEBUG_LOG(("next signal: %d\n", s));
                return s;
        }
        err = errno;
        assert(r < 0);
        if (err == EAGAIN)
                return 0;
-       make_err_msg("failed to read from signal pipe");
+       DSS_ERROR_LOG(("failed to read from signal pipe\n"));
        return -ERRNO_TO_DSS_ERROR(err);
 }