Package: dpkg
Version: 1.13.11
When I run :
start-stop-daemon --start --chroot /var/chroot/somewhere -c
someuser:somegroup --exec /bin/somebin
And I get a start-stop-daemon: stat /bin/somebin: No such file or directory
Because the /bin/somebin doesn't exist in my real tree, only in chroot,
and start-stop-daemon does the stat on file before the chroot...
I made a previous patch (not take in care and lot tested) to do the
check after chroot.
This time I make a new bug report with attached patch and new improvement.
My patch support now to search the binary in the PATH.
Please apply this patch I have tested it a lot, if you don't want PATH
support, just reduce the execstat() fuction to this (as it was before):
if (execname && stat(execname, &exec_stat))
fatal("stat %s: %s", execname, strerror(errno));
This bug is related to (but this bug report, only complain about stat in
chroot without path support):
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=318771
diff -urNp dpkg-1.13.11/utils/start-stop-daemon.c.orig dpkg-1.13.11/utils/start-stop-daemon.c
--- dpkg-1.13.11/utils/start-stop-daemon.c.orig 2005-10-10 09:42:06.196042944 +0200
+++ dpkg-1.13.11/utils/start-stop-daemon.c 2005-10-10 09:45:38.539761792 +0200
@@ -1166,6 +1166,46 @@ x_finished:
}
}
+static int
+execstat(void)
+{
+ if (execname && stat(execname, &exec_stat))
+ {
+ char* tmp;
+ char* path = strdup((const char *)getenv("PATH"));
+ if (path[0] == 0)
+ return 1;
+ else
+ {
+ if (strchr(path, ':') != NULL)
+ {
+ while ((tmp = strsep(&path, ":")))
+ {
+ char* buf = malloc((strlen(tmp)+strlen(execname)+2)*sizeof(char));
+ sprintf(buf, "%s/%s", tmp, execname);
+ if (execname && !stat(buf, &exec_stat))
+ {
+ startas = buf;
+ return 0;
+ }
+ }
+ }
+ else
+ {
+ char* buf = malloc((strlen(path)+strlen(execname)+2)*sizeof(char));
+ sprintf(buf, "%s/%s", path, execname);
+ if (execname && !stat(buf, &exec_stat))
+ {
+ startas = buf;
+ return 0;
+ }
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
int
main(int argc, char **argv)
@@ -1180,7 +1220,7 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
- if (execname && stat(execname, &exec_stat))
+ if (changeroot == NULL && execstat())
fatal("stat %s: %s", execname, strerror(errno));
if (userspec && sscanf(userspec, "%d", &user_id) != 1) {
@@ -1283,6 +1323,8 @@ main(int argc, char **argv)
fatal("Unable to chdir() to %s", changeroot);
if (chroot(changeroot) < 0)
fatal("Unable to chroot() to %s", changeroot);
+ if (execstat())
+ fatal("stat %s: %s", execname, strerror(errno));
}
if (chdir(changedir) < 0)
fatal("Unable to chdir() to %s", changedir);