[PATCH] start-stop-daemon fails to stop processes and sometimes fails to start them.

Joakim Tjernlund joakim.tjernlund at transmode.se
Thu Apr 17 17:02:41 UTC 2008


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);




More information about the busybox mailing list