supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
* PATCH: bug in readdir() error-handling (at least for Linux)
@ 2004-03-12 20:39 Bob Vincent
  2004-03-13  2:00 ` Laurent Bercot
  0 siblings, 1 reply; 2+ messages in thread
From: Bob Vincent @ 2004-03-12 20:39 UTC (permalink / raw)


I was experiencing errors when using runsvdir under glibc.

Looks like the code assumes that when readdir() sets errno to any
non-zero value, that means "unable to read".

In Linux glibc at least, readdir() sets errno to EOF when it reads the
last directory entry.  And EOF is non-zero.

The only other legal return value is EBADF, which is what you're
really looking for.

The following one-liner fixed the problem:

--- admin/runit-1.0.1/src/runsvdir.c~   Fri Mar 12 13:58:12 2004
+++ admin/runit-1.0.1/src/runsvdir.c    Fri Mar 12 14:17:21 2004
@@ -119,7 +119,7 @@
       runsv(i, d->d_name);
     }
   }
-  if (errno) {
+  if (errno==EBADF) {
     warn("unable to read directory ", svdir);
     closedir(dir);
     return;


-- 
Robert August Vincent, II
(pronounced "Bob" or "Bob-Vee")
The web is like usenet, but
the elephants are untrained.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PATCH: bug in readdir() error-handling (at least for Linux)
  2004-03-12 20:39 PATCH: bug in readdir() error-handling (at least for Linux) Bob Vincent
@ 2004-03-13  2:00 ` Laurent Bercot
  0 siblings, 0 replies; 2+ messages in thread
From: Laurent Bercot @ 2004-03-13  2:00 UTC (permalink / raw)


> Looks like the code assumes that when readdir() sets errno to any
> non-zero value, that means "unable to read".
> 
> In Linux glibc at least, readdir() sets errno to EOF when it reads the
> last directory entry.  And EOF is non-zero.
> 
> The only other legal return value is EBADF, which is what you're
> really looking for.

 No. Here is what SUSv3 says about readdir() :

++ Upon successful completion, readdir() shall return a pointer to an
++ object of type struct dirent. When an error is encountered, a null
++ pointer shall be returned and errno shall be set to indicate the
++ error. When the end of the directory is encountered, a null pointer
++ shall be returned and errno is not changed.

 runsvdir's way of testing is SUSv3-compliant, and the behaviour you're
experiencing is a glibc bug or misfeature. The right way to correct
this is to ask the glibc-dev team to fix the glibc. In the meantime, a
workaround could be handy, but your patch will break SUSv3-compliant
systems. (Other possible errors include EOVERFLOW and ENOENT.)

-- 
 Ska


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-03-13  2:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-12 20:39 PATCH: bug in readdir() error-handling (at least for Linux) Bob Vincent
2004-03-13  2:00 ` Laurent Bercot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).