Hi,

The start-stop-daemon --exec does a string compare with /proc/<pid>/exe
link target. This was introduced in a try to fix a "bug" where the
daemon is a link to /bin/busybox. For example:

  start-stop-daemon --start --exec /usr/sbin/inetd

ssd will check if the executable (which is busybox) is already running
and wil discover that it actually is (somebody is running the busybox
shell for example)

So strcmp and readlink was introduced in r16047.

However, the idea is flawed by design, since linux will not store the
link name in /proc/<pid>/exe but the real executable, so using readlink
and strcmp is completely useless. It is simply not possible to use
start-stop-daemon --exec with busybox applets, due to the nature of
linux.

So I suggest we go back to the origial behaviour, pre r16047, which
properly uses stat and compares st_dev and st_ino.

Patch attatched.

This could also close http://bugs.uclibc.org/view.php?id=324 

Natanael Copa
Index: debianutils/start_stop_daemon.c
===================================================================
--- debianutils/start_stop_daemon.c	(revision 18425)
+++ debianutils/start_stop_daemon.c	(working copy)
@@ -40,20 +40,17 @@
 static int pid_is_exec(pid_t pid, const char *name)
 {
 	char buf[sizeof("/proc//exe") + sizeof(int)*3];
-	char *execbuf;
-	int sz;
-	int equal;
+	struct stat sb, exec_stat;
 
-	sprintf(buf, "/proc/%d/exe", pid);
-	sz = strlen(name) + 1;
-	execbuf = xzalloc(sz);
-	readlink(buf, execbuf, sz);
+	if (name) {
+		xstat(name, &exec_stat);
+	}
 
-	/* if readlink fails, execbuf still contains "" */
-	equal = !strcmp(execbuf, name);
-	if (ENABLE_FEATURE_CLEAN_UP)
-		free(execbuf);
-	return equal;
+	sprintf(buf, "/proc/%d/exe", pid);
+	if (stat(buf, &sb) != 0) {
+		return 0;
+	}
+	return (sb.st_dev == exec_stat.st_dev && sb.st_ino == exec_stat.st_ino);
 }
 
 static int pid_is_user(int pid, int uid)
_______________________________________________
busybox mailing list
[EMAIL PROTECTED]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to