> -----Original Message-----
> From: Denys Vlasenko [mailto:[EMAIL PROTECTED]
> Sent: den 19 april 2008 05:13
> To: [email protected]; [EMAIL PROTECTED]
> 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 :(

 :):):), my 3 smiles outrank your one.

> 
> > --- 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?

Well, I don't know. I haven't been playing with bb much before and
I didn't want to mess with stuff outside start-stop-daemon. I 
don't wan't to do any damage to other stuff in bb.

> 
> >     foundany = 0;
> > -   while ((entry = readdir(procdir)) != NULL) {
> > -           pid = bb_strtou(entry->d_name, NULL, 10);
> > -           if (errno)
> > +   while(1) {
> > +           errno = 0;
> > +           entry = readdir(procdir);
> > +           if (errno) /* Stale file ? */
> >                     continue;
> 
> When exactly this happens? I would like to document it in comment.

Well, files comes and goes quickly in /proc so I guess that it
happens when a file/directory is deleted after /proc has been opened.

The man page for readdir is pretty clear though. Will return a
NULL ptr when either EOF or an error has been encountered so
you have to test for errno to know why NULL is returned.

> 
> > +           if (!entry)
> > +                   break;
> > +           pid = bb_strtou(entry->d_name, NULL, 10);
> >             foundany++;
> > +           if (pid == UINT_MAX) /* NaN */
> > +                   continue;
> 
> I think foundany++ must be after this check.

Depends, I read foundany as if there was ANY file in /proc and
then it should be before. I can live with either though.

> --
> vda


_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to