[PATCH 2/2] start-stop-daemon - find processes better

Denys Vlasenko vda.linux at googlemail.com
Wed May 7 14:50:09 UTC 2008


On Wednesday 30 April 2008 16:27, Roy Marples wrote:
> On Wednesday 30 April 2008 14:37:31 Denys Vlasenko wrote:
> > On Wednesday 30 April 2008 13:40, Joakim Tjernlund wrote:
> > > On Wed, 2008-04-30 at 12:18 +0100, Roy Marples wrote:
> > > > start-stop-daemon uses stat to match running binaries.
> > > > This is not good as the binary in question could be moved or deleted
> > > > during an upgrade.
> >
> > When it is moved or deleted, and replaced by a new file with the same name,
> > is this the same binary or not?
> >
> > I bet if you do a poll, results will be split about 50:50.
> 
> But the intent of start-stop-daemon is to start and stop daemons.
> s-s-d --stop --exec /usr/sbin/ntpd
> I would that expect it to stop the currently running ntpd process regardless 
> of if the binary itself still exists or not.
> 
> > > It
> > > wont work when cmdline i a symlink. Should you not use --name instead
> > > to handle the deleted case?
> 
> But this is good :)
> Consider busybox - loads of things symlink into it, like udhcpd. So are you 
> stopping udhcpd or all instances of busybox daemons?

The following text is added as a comment to start-stop-daemon.c now.
Roy, please rediff the patch against svn. It should also include
edits to this comment, explaining rationale for this change.

So far it seems that --exec indeed is the wrong tool for searching
for the processes by name.




This is how it is supposed to work:

start-stop-daemon [OPTIONS] [--start|--stop] [[--] arguments...]

One (only) of these must be given:
        -S,--start              Start
        -K,--stop               Stop

Search for matching processes.
If --stop is given, stop all matching processes (by sending a signal).
If --start if given, start a new process unless a matching process was found.

Options controlling process matching:
        -u,--user USERNAME|UID  Only consider this user's processes
        -n,--name PROCESS_NAME  Look for processes with matching argv[0]
                                or /proc/$PID/exe or /proc/$PID/stat (comm field).
                                Only basename is compared:
                                "ntpd" == "./ntpd" == "/path/to/ntpd".

[TODO: can PROCESS_NAME be a full pathname? Should we require full match then
with /proc/$PID/exe or argv[0] (comm can't be matched, it never contains path)]

        -x,--exec EXECUTABLE    Look for processes with matching /proc/$PID/exe.
                                Match is performed using device+inode.
        -p,--pidfile PID_FILE   Look for processes with PID from this file

Options which are valid for --start only:
        -x,--exec EXECUTABLE    Program to run (1st arg of execvp). Mandatory.
        -a,--startas NAME       argv[0] (defaults to EXECUTABLE)
        -b,--background         Put process into background
        -N,--nicelevel N        Add N to process' nice level
        -c,--chuid USER[:[GRP]] Change to specified user [and group]
        -m,--make-pidfile       Write PID to the pidfile
                                (both -m and -p must be given!)
Misc options:
        -s,--signal SIG         Signal to send (default:TERM)
        -o,--oknodo             Exit with status 0 if nothing is done
        -q,--quiet              Quiet
        -v,--verbose            Verbose


--
vda



More information about the busybox mailing list