]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Rationalise signal handling - HUP now rebinds, ALRM now releases, USR1 reapplies...
authorRoy Marples <roy@marples.name>
Fri, 7 Mar 2014 10:08:58 +0000 (10:08 +0000)
committerRoy Marples <roy@marples.name>
Fri, 7 Mar 2014 10:08:58 +0000 (10:08 +0000)
dhcpcd.c

index 6df6ff9ea673ed60b5caa4edde7195365f84e426..f4aa4ada6006ba53da2d1cd25df52cbb23f585ef 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -852,6 +852,7 @@ struct dhcpcd_siginfo {
        pid_t pid;
 } dhcpcd_siginfo;
 
+#define sigmsg "received signal %s from PID %d, %s"
 static void
 handle_signal1(void *arg)
 {
@@ -866,17 +867,17 @@ handle_signal1(void *arg)
        do_release = 0;
        switch (si->signo) {
        case SIGINT:
-               syslog(LOG_INFO, "received SIGINT from PID %d, stopping",
-                   (int)si->pid);
+               syslog(LOG_INFO, sigmsg, "INT", (int)si->pid, "stopping");
                break;
        case SIGTERM:
-               syslog(LOG_INFO, "received SIGTERM from PID %d, stopping",
-                   (int)si->pid);
+               syslog(LOG_INFO, sigmsg, "TERM", (int)si->pid, "stopping");
                break;
        case SIGALRM:
-               syslog(LOG_INFO, "received SIGALRM from PID %d, rebinding",
-                   (int)si->pid);
-
+               syslog(LOG_INFO, sigmsg, "ALRM", (int)si->pid, "releasing");
+               do_release = 1;
+               break;
+       case SIGHUP:
+               syslog(LOG_INFO, sigmsg, "HUP", (int)si->pid, "rebinding");
                free_globals(ctx);
                ifo = read_config(ctx, NULL, NULL, NULL);
                add_options(ctx, NULL, ifo, ctx->argc, ctx->argv);
@@ -892,20 +893,14 @@ handle_signal1(void *arg)
                reconf_reboot(ctx, 1, ctx->argc, ctx->argv,
                    ctx->argc - ctx->ifc);
                return;
-       case SIGHUP:
-               syslog(LOG_INFO, "received SIGHUP from PID %d, releasing",
-                   (int)si->pid);
-               do_release = 1;
-               break;
        case SIGUSR1:
-               syslog(LOG_INFO, "received SIGUSR from PID %d, reconfiguring",
-                   (int)si->pid);
+               syslog(LOG_INFO, sigmsg, "USR1", (int)si->pid, "reconfiguring");
                TAILQ_FOREACH(ifp, ctx->ifaces, next) {
                        ipv4_applyaddr(ifp);
                }
                return;
        case SIGPIPE:
-               syslog(LOG_WARNING, "received SIGPIPE");
+               syslog(LOG_WARNING, "received signal PIPE");
                return;
        default:
                syslog(LOG_ERR,
@@ -1118,6 +1113,7 @@ main(int argc, char **argv)
 #endif
 #ifdef USE_SIGNALS
        int sig;
+       const char *siga;
 #endif
        struct timespec ts;
 
@@ -1125,6 +1121,7 @@ main(int argc, char **argv)
 #ifdef USE_SIGNALS
        dhcpcd_ctx = &ctx;
        sig = 0;
+       siga = NULL;
 #endif
        closefrom(3);
        openlog(PACKAGE, LOG_PERROR | LOG_PID, LOG_DAEMON);
@@ -1166,15 +1163,19 @@ main(int argc, char **argv)
 #ifdef USE_SIGNALS
                case 'g':
                        sig = SIGUSR1;
+                       siga = "USR1";
                        break;
                case 'k':
-                       sig = SIGHUP;
+                       sig = SIGALRM;
+                       siga = "ARLM";
                        break;
                case 'n':
-                       sig = SIGALRM;
+                       sig = SIGHUP;
+                       siga = "HUP";
                        break;
                case 'x':
                        sig = SIGTERM;
+                       siga = "TERM";;
                        break;
 #endif
                case 'T':
@@ -1318,20 +1319,20 @@ main(int argc, char **argv)
        if (sig != 0) {
                pid = read_pid(pidfile);
                if (pid != 0)
-                       syslog(LOG_INFO, "sending signal %d to pid %d",
-                           sig, pid);
+                       syslog(LOG_INFO, "sending signal %s to pid %d",
+                           siga, pid);
                if (pid == 0 || kill(pid, sig) != 0) {
-                       if (sig != SIGALRM && errno != EPERM)
+                       if (sig != SIGHUP && errno != EPERM)
                                syslog(LOG_ERR, ""PACKAGE" not running");
                        if (pid != 0 && errno != ESRCH) {
                                syslog(LOG_ERR, "kill: %m");
                                goto exit_failure;
                        }
                        unlink(pidfile);
-                       if (sig != SIGALRM)
+                       if (sig != SIGHUP)
                                goto exit_failure;
                } else {
-                       if (sig == SIGALRM || sig == SIGUSR1)
+                       if (sig == SIGHUP || sig == SIGUSR1)
                                goto exit_success;
                        /* Spin until it exits */
                        syslog(LOG_INFO, "waiting for pid %d to exit", pid);