[PATCH 2/2] start-stop-daemon - find processes better
Denys Vlasenko
vda.linux at googlemail.com
Thu May 1 06:18:40 PDT 2008
On Thursday 01 May 2008 13:09, Roy Marples wrote:
> > Let's see what help says, and whether it matches reality
> > (I deleted some obvious options):
> >
> > # start-stop-daemon --help
> > Usage: start-stop-daemon [OPTIONS] [--start|--stop] ... [-- arguments...]
> > Start and stop services
> > Options:
> > -S,--start Start
> > -K,--stop Stop
> > -a,--startas pathname Start process specified by pathname
> > WRONG? it seems to just set argv[0].
> > It's not a pathname, it's just a "name" (arbitrary)
>
> Correct. It's a crap option. Gentoo silently remaps it to --exec
Are you suggesting to drop it? This risks breaking
things for existing users.
> > -u,--user username|uid Stop this user's processes
> > Clarification? Will e.g. "ssd -K -u roy" stop
> > all roy's processes?
>
> Yes
And what does it mean for --start case?
ssd -S -u roy -x /usr/bin/sleep 1234
> > -x,--exec executable Program to either start or check
> > Waht does it mean "check"? "stop"?
> > How executable is searched for for "stop" case?
>
> My view is that it searches for programs started as that.
> So if the user launches /usr/sbin/ntpd then ssd should check /proc/pid/cmdline
> to see if it was started as /usr/sbin/ntpd and then match.
And what to do if cmdline contains just "ntpd"? or "./ntpd"?
Does that match?
Do we need to check /proc/$PID/stat? /proc/$PID/exec?
For more details, here is the comment from libbb/find_pid_by_name.c:
/*
In Linux we have three ways to determine "process name":
1. /proc/PID/stat has "...(name)...", among other things. It's so-called "comm" field.
2. /proc/PID/cmdline's first NUL-terminated string. It's argv[0] from exec syscall.
3. /proc/PID/exe symlink. Points to the running executable file.
kernel threads:
comm: thread name
cmdline: empty
exe: <readlink fails>
executable
comm: first 15 chars of base name
(if executable is a symlink, then first 15 chars of symlink name are used)
cmdline: argv[0] from exec syscall
exe: points to executable (resolves symlink, unlike comm)
script (an executable with #!/path/to/interpreter):
comm: first 15 chars of script's base name (symlinks are not resolved)
cmdline: /path/to/interpreter (symlinks are not resolved)
(script name is in argv[1], args are pushed into argv[2] etc)
exe: points to interpreter's executable (symlinks are resolved)
If FEATURE_PREFER_APPLETS=y (and more so if FEATURE_SH_STANDALONE=y),
some commands started from busybox shell, xargs or find are started by
execXXX("/proc/self/exe", applet_name, params....)
and therefore comm field contains "exe".
*/
> OpenRC extends this futher and also matches daemon arguments. Thus, this works
>
> start-stop-damon --start --exec /usr/sbin/daemon -- --hostname foo
> start-stop-damon --start --exec /usr/sbin/daemon -- --hostname bar
> start-stop-damon --stop --exec /usr/sbin/daemon -- --hostname foo
> the second daemon *should* still be running in my eyes.
> However, adding that will bloat ssd a little more, so may not be beneficial
> for busybox.
>
> > -n,--name process-name Stop processes with this name
> > Is it equivalent to "killall name"?
> > If not, what's the difference?
>
> Should be equivalent.
> This is a bad option to use as many daemon love to change their process name
Change process name? How?
> AND don't create a pidfile AND are scripts. Again, this is why we
> changed --exec to look at how it was started to solve this problem.
How it is different from -x?
> > -p,--pidfile pid-file Save or load pid using a pid-file
> > -m,--make-pidfile Create the -p file and enter pid in it
> > ?? How "save" is different from "create and enter pid in it"?
>
> In normal ssd, -p only matters when stopping. It reads the specified file and
> just stops that pid.
> However, ssd can also background some daemons which don't by default. Or which
> don't create a pidifle by default. So the solution is to run the daemon in
> foreground mode in a forked process. We then store that pid in the pidfile.
> Example
>
> start-stop-daemon --start --exec /usr/sbin/daemon --pidfile /var/run/daemon.pid --make-pidfile -- --foreground
> --foreground is an option specific to daemon and not start-stop-daemon.
But --make-pidfile seems to be superfluous here... --start + --pidfile FILE
imply pidfile creation.
--
vda
More information about the busybox
mailing list