runsvdir: make it more robust against libc buglets (errno accidentally set to !0)
authorDenis Vlasenko <vda.linux@googlemail.com>
Sat, 31 May 2008 07:00:33 +0000 (07:00 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sat, 31 May 2008 07:00:33 +0000 (07:00 -0000)
closes bug 3514

function                                             old     new   delta
runsvdir_main                                       1672    1664      -8

runit/runsvdir.c

index b4450c00cb2970797de8c9251f527a22bc9248a1..df6b8869da6f79952028ae76fca291f0805c87b7 100644 (file)
@@ -141,8 +141,12 @@ static void runsvdir(void)
        }
        for (i = 0; i < svnum; i++)
                sv[i].isgone = 1;
-       errno = 0;
-       while ((d = readdir(dir))) {
+
+       while (1) {
+               errno = 0;
+               d = readdir(dir);
+               if (!d)
+                       break;
                if (d->d_name[0] == '.')
                        continue;
                if (stat(d->d_name, &s) == -1) {
@@ -194,6 +198,7 @@ static void runsvdir(void)
                if (sv[i].pid)
                        kill(sv[i].pid, SIGTERM);
                sv[i] = sv[--svnum];
+/* BUG? we deleted sv[i] by copying over sv[last], but we will not check this newly-copied one! */
                check = 1;
        }
 }