[PATCH] start-stop-daemon fails to stop processes and sometimes fails to start them.
Joakim Tjernlund
Joakim.Tjernlund at transmode.se
Sat Apr 19 14:24:31 UTC 2008
> -----Original Message-----
> From: Denys Vlasenko [mailto:vda.linux at googlemail.com]
> Sent: den 19 april 2008 05:13
> To: busybox at busybox.net; joakim.tjernlund at transmode.se
> Subject: Re: [PATCH] start-stop-daemon fails to stop processes and sometimes fails to start them.
>
> On Thursday 17 April 2008 19:02, Joakim Tjernlund wrote:
> > pid_is_cmd() would call "die" if it got a stale file.
> > readdir() will fail if a file becomes stale, detect this and
> > move on.
> >
> > This patch is aginst bb 1.8.2 gentoo version so it might not apply
> > cleanly. I hope that wont be a problem.
>
> Hrm :(
>
> > --- debianutils/start_stop_daemon.c.org 2008-04-17 16:02:51.000000000 +0200
> > +++ debianutils/start_stop_daemon.c 2008-04-17 18:30:56.000000000 +0200
> > @@ -62,16 +62,17 @@
> > return (sb.st_uid == uid);
> > }
> >
> > +#define MAX_READ 1024
> > static int pid_is_cmd(pid_t pid, const char *name)
> > {
> > char fname[sizeof("/proc//stat") + sizeof(int)*3];
> > - char *buf;
> > + char buf[MAX_READ+1], *p;
> > int r = 0;
> >
> > sprintf(fname, "/proc/%u/stat", pid);
> > - buf = xmalloc_open_read_close(fname, NULL);
> > - if (buf) {
> > - char *p = strchr(buf, '(');
> > + if (open_read_close(fname, buf, MAX_READ) > 0) {
>
> I think that it's better to fix xmalloc_open_read_close
> to not die if fie does not exist. After all, it is not called
> xmalloc_xopen_read_close, right?
hmm, xmalloc_open_read_close do use xopen though, but even if
this was fixed, it can die. The other users expects this too.
It does not make sense to fail open/lseek/read and return
a ptr with garbage in it. If you make sizep mandatory, it might make
sense if you do *sizep =-1 in case of error.
Feels a lot safer to use open_read_close() in start-stop-daemon and
skip the extra | 0x3ff.
Jocke
PS.
Side note, not sure if bb uses errno correctly at all times. Usally one
must zero errno before calling a function that can set it because most libc/system functions
does not clear it when it succeeds.
More information about the busybox
mailing list