another [patch] Solaris fix for cfg_dir Re: Bug: cfg_dir doesn't work on solaris..?
Andreas Ericsson
ae at op5.se
Wed Jan 23 14:04:43 CET 2008
Jan Grant wrote:
> Attached is a patch against nagios-2.10 which carefully cuts out the
> uses of d_type in dirent, if that's missing, and just falls back to
> using stat (which follows symlinks).
>
> This makes recursive cfg_dir structures work on Solaris 10.
>
> Excuse the hackery: I've just carefully inserted additional checks for
> _DIRENT_HAVE_D_TYPE around block ends.
>
Umm... This patch makes the code excessively hard to read, since block
starts and ends are now inside #ifdef's.
I was thinking something along the lines of
while (de = readdir(dirp)) {
struct stat st;
if (stat(de->d_name) < 0)
return -1; /* error */
switch (st.st_mode & S_IFMT) {
case S_IFDIR:
/* recurse */
break;
case S_IFREG:
/* read */
break;
default:
/* unhandled entry (socket, fifo, ... ) */
break;
}
}
which doesn't have any references to d_type at all. Note that you
don't need to check for S_IFLNK, as stat() will check the target
of the link rather than the link itself.
>
> PS. I'm reasonably certain that what nagios tries to do in the cfg_dir
> handling is unnecessarily clever; since stat() follows symlinks anyway,
> just checking for file or directory types with a single stat() call
> should be sufficient.
>
Yes, that's exactly what I meant. :)
Care to resend?
--
Andreas Ericsson andreas.ericsson at op5.se
OP5 AB www.op5.se
Tel: +46 8-230225 Fax: +46 8-230231
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
More information about the Developers
mailing list