]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Spin until dhcpcd exits (timeout 10 seconds) to avoid this race:- dhcpcd -x eth0...
authorRoy Marples <roy@marples.name>
Tue, 12 Aug 2008 10:51:42 +0000 (10:51 +0000)
committerRoy Marples <roy@marples.name>
Tue, 12 Aug 2008 10:51:42 +0000 (10:51 +0000)
dhcpcd.c

index e32a5eb2888a82d45a2692c0d85f9e4a9d984147..8da13fbc44b761a4e8c05ba2395a083c2dfd1ef2 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -595,6 +595,7 @@ main(int argc, char **argv)
        FILE *f;
        char *cf = NULL;
        char *intf = NULL;
+       struct timespec ts;
 
        closefrom(3);
        /* Saves calling fflush(stream) in the logger */
@@ -863,8 +864,20 @@ main(int argc, char **argv)
                               ""PACKAGE" not running");
                        unlink(options->pidfile);
                }
-               if (i == 0) {
-                       retval = EXIT_SUCCESS;
+               if (i == 0 && (sig == SIGTERM || sig == SIGHUP)) {
+                       /* Spin until it exits */
+                       logger(LOG_INFO, "waiting for pid %d to exit", pid);
+                       ts.tv_sec = 0;
+                       ts.tv_nsec = 100000000; /* 10th of a second */
+                       for(i = 0; i < 100; i++) {
+                               nanosleep(&ts, NULL);
+                               if (read_pid(options->pidfile) == 0) {
+                                       retval = EXIT_SUCCESS;
+                                       break;
+                               }
+                       }
+                       if (retval != EXIT_SUCCESS)
+                               logger(LOG_ERR, "pid %d failed to exit", pid);
                        goto abort;
                }
                if (sig != SIGALRM)