start_stop_daemon: do not stop /proc scan prematurely
authorDenis Vlasenko <vda.linux@googlemail.com>
Sat, 19 Apr 2008 20:19:45 +0000 (20:19 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sat, 19 Apr 2008 20:19:45 +0000 (20:19 -0000)
function                                             old     new   delta
do_procinit                                          185     196     +11

debianutils/start_stop_daemon.c

index 2f8e04a7814d8af317cbd1b55e7ed9fe33e360d8..b6b30e7cc3c20549f927be8b7f98195df347e9e9 100644 (file)
@@ -145,11 +145,18 @@ static void do_procinit(void)
        procdir = xopendir("/proc");
 
        pid = 0;
-       while ((entry = readdir(procdir)) != NULL) {
-               pid = bb_strtou(entry->d_name, NULL, 10);
-               if (errno)
-                       continue;
-               check(pid);
+       while(1) {
+               errno = 0; /* clear any previous error */
+               entry = readdir(procdir);
+// TODO: check for exact errno(s) which mean that we got stale entry
+               if (errno) /* Stale entry, process has died after opendir */
+                       continue;
+               if (!entry) /* EOF, no more entries */
+                       break;
+               pid = bb_strtou(entry->d_name, NULL, 10);
+               if (errno) /* NaN */
+                       continue;
+               check(pid);
        }
        closedir(procdir);
        if (!pid)