pid_is_cmd() would call "die" if it got a stale file.
readdir() will fail if a file becomes stale, detect this and
move on.

This patch is aginst bb 1.8.2 gentoo version so it might not apply
cleanly. I hope that wont be a problem.

 Jocke

--- debianutils/start_stop_daemon.c.org 2008-04-17 16:02:51.000000000 +0200
+++ debianutils/start_stop_daemon.c     2008-04-17 18:30:56.000000000 +0200
@@ -62,16 +62,17 @@
        return (sb.st_uid == uid);
 }
 
+#define MAX_READ 1024
 static int pid_is_cmd(pid_t pid, const char *name)
 {
        char fname[sizeof("/proc//stat") + sizeof(int)*3];
-       char *buf;
+       char buf[MAX_READ+1], *p;
        int r = 0;
 
        sprintf(fname, "/proc/%u/stat", pid);
-       buf = xmalloc_open_read_close(fname, NULL);
-       if (buf) {
-               char *p = strchr(buf, '(');
+       if (open_read_close(fname, buf, MAX_READ) > 0) {
+               buf[MAX_READ] = 0;
+               p = strchr(buf, '(');
                if (p) {
                        char *pe = strrchr(++p, ')');
                        if (pe) {
@@ -79,7 +80,6 @@
                                r = !strcmp(p, name);
                        }
                }
-               free(buf);
        }
        return r;
 }
@@ -131,11 +131,17 @@
        procdir = xopendir("/proc");
 
        foundany = 0;
-       while ((entry = readdir(procdir)) != NULL) {
-               pid = bb_strtou(entry->d_name, NULL, 10);
-               if (errno)
+       while(1) {
+               errno = 0;
+               entry = readdir(procdir);
+               if (errno) /* Stale file ? */
                        continue;
+               if (!entry)
+                       break;
+               pid = bb_strtou(entry->d_name, NULL, 10);
                foundany++;
+               if (pid == UINT_MAX) /* NaN */
+                       continue;
                check(pid);
        }
        closedir(procdir);

_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to