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

Joakim Tjernlund Joakim.Tjernlund at transmode.se
Fri May 2 07:35:50 PDT 2008


> -----Original Message-----
> From: Denys Vlasenko [mailto:vda.linux at googlemail.com]
> Sent: den 2 maj 2008 10:43
> To: Roy Marples
> Cc: joakim.tjernlund at transmode.se; busybox at busybox.net
> Subject: Re: [PATCH 2/2] start-stop-daemon - find processes better
> 
> Hi Roy, Joakim.
> 
> Joakim, please scroll down to the end and let me know
> what you thing about proposed ssd documentation.
> 
> 
> On Thursday 01 May 2008 15:38, Roy Marples wrote:
> > > > > 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.
> >
> > No, I'm suggesting just to remap --startas to --exec
> 
> Don't see why it cannot be used as intended - as an argv[0] override.
> 
> > > > 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?
> >
> > That's the one hole really :)
> > It doesn't match, but then I don't expect it too either. ssd is normally used
> > in scripts, so the way it's started should match the way it's stopped.

yes it is a hole, but we could try rebuild the full path by
merging the CWD and cmdline in this case. I don't think this is a big
deal though.

> 
> I need this to be exactly spelled out.
> 
> > > > >         -n,--name process-name  Stop processes with this name
> > > > 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?
> >
> > -x is --exec, or did I miss something?
> 
> I meant "how --exec is different for --name?"
> 
> > > > 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.
> 
> Really? Must be documented. And if --make-pidfile indeed implies
> pidfile creation, then it makes no sense. Adding/removing
> --make-pidfile to command line chages nothing.
> 
> > Not so as --pidfile is used to check processes before the demon starts
> >
> > start-stop-daemon --start --exec /usr/bin/foo --pidfile /var/run/foo.pid
> >
> > Check that /usr/bin/foo is NOT running on the pidfile in /var/run/foo.pid.
> > If not running, start foo, otherwise error.
> > ssd should not stamp on pidfiles unless told.
> 
> 
> Please review proposed documentation below.
> 
> Please spell out how -n NAME and -x NAME are different in respect
> to stopping the processes. To reiterate: we nave 3 different
> ideas of "process name":
> 
> 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)
> 
> Which one(s) should be used by -n? -x?

I think we should use cmdline for all. The comm. field is too small to
hold a bigger file name so it would be hard to match such a file.

> 
> 
> 
> 
> start-stop-daemon [OPTIONS] [--start|--stop] ... [-- arguments...]
> 
> One (only) of these must be given:
>         -S,--start              Start
>         -K,--stop               Stop
> 
> start-stop-daemon will first search for matching processes,
> stop them (by sending a signal). If --start is given,
> it will then start a new process.

Perhaps this could read 
 start-stop-daemon will first search for matching processes.
 If --stop is given, then stop all matching processes(by sending a signal).
 If --start if given, start a new process unless a matching process was found.

> Stop options:
>         -u,--user USERNAME|UID  Stop this user's processes
>         -n,--name PROCESS_NAME  Stop processes with this name ??
>         -x,--exec EXECUTABLE    Stop processes with this name ??
Perhaps
         -n,--name PROCESS_NAME  Stop processes with matching basename(argv[0])
         -x,--exec EXECUTABLE    Stop processes with matching argv[0]

>         -p,--pidfile PID_FILE   Stop processes with PID from this file
>         -s,--signal SIG         Signal to send (default TERM)
> 
> Start options:
>         -x,--exec EXECUTABLE    Program to run (1st arg of execvp). Mandatory.
>         -a,--startas NAME       argv[0] (defults to EXECUTABLE)
>         -b,--background         Put process into background
>         -N,--nicelevel N        Add N to process's nice level
>         -c,--chuid user[:[grp]] Change to specified user/group
>         -m,--make-pidfile -p,--pidfile PID_FILE
>                                 Write PID to the file
>                                 (both -m and -p must be given!)
> Misc options:
>         -o,--oknodo             Exit status 0 if nothing done
>         -q,--quiet              Quiet
>         -v,--verbose            Verbose
> 
> 
> 
> --
> vda




More information about the busybox mailing list