Simplify terminate_workers() in the KDC
authorGreg Hudson <ghudson@mit.edu>
Wed, 14 Sep 2011 16:12:39 +0000 (16:12 +0000)
committerGreg Hudson <ghudson@mit.edu>
Wed, 14 Sep 2011 16:12:39 +0000 (16:12 +0000)
Fixes a bug where we wait for one too many workers to terminate after
one of them crashes.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25178 dc483132-0cff-0310-8789-dd5450dbe970

src/kdc/main.c

index bee5bd95ac60fa66790131fd3f50b945d88db471..fbccdb90f0c5df8953bd4fb965961c8255600580 100644 (file)
@@ -509,15 +509,17 @@ on_monitor_sighup(int signo)
  * in the array.
  */
 static void
-terminate_workers(pid_t *pids, int bound, int num_active)
+terminate_workers(pid_t *pids, int bound)
 {
-    int i, status;
+    int i, status, num_active;
     pid_t pid;
 
     /* Kill the active worker pids. */
     for (i = 0; i < bound; i++) {
-        if (pids[i] != -1)
-            kill(pids[i], SIGTERM);
+        if (pids[i] == -1)
+            continue;
+        kill(pids[i], SIGTERM);
+        num_active++;
     }
 
     /* Wait for them to exit. */
@@ -537,7 +539,7 @@ static krb5_error_code
 create_workers(verto_ctx *ctx, int num)
 {
     krb5_error_code retval;
-    int i, status, numleft;
+    int i, status;
     pid_t pid, *pids;
 #ifdef POSIX_SIGNALS
     struct sigaction s_action;
@@ -590,7 +592,7 @@ create_workers(verto_ctx *ctx, int num)
         if (pid == -1) {
             /* Couldn't fork enough times. */
             status = errno;
-            terminate_workers(pids, i, i);
+            terminate_workers(pids, i);
             free(pids);
             return status;
         }
@@ -601,7 +603,6 @@ create_workers(verto_ctx *ctx, int num)
     loop_free(ctx);
 
     /* Supervise the worker processes. */
-    numleft = num;
     while (!signal_received) {
         /* Wait until a worker process exits or we get a signal. */
         pid = wait(&status);
@@ -633,7 +634,7 @@ create_workers(verto_ctx *ctx, int num)
         krb5_klog_syslog(LOG_INFO, _("signal %d received in supervisor"),
                          signal_received);
 
-    terminate_workers(pids, num, numleft);
+    terminate_workers(pids, num);
     free(pids);
     exit(0);
 }