[Nagios-devel] Nrpe and reiserfs

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] Nrpe and reiserfs

Post by Guest »

This is a multi-part message in MIME format.

------=_NextPart_000_0251_01C659C6.58F696F0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hi Ethan,

i stumbled over a bug in reiserfs, when i was desperately trying to find out
why an include_dir= statement in my nrpe.cfg was ignored.
In the read_config_dir function you wrote:

#ifdef _DIRENT_HAVE_D_TYPE
/* only process normal files */
if(dirfile->d_type!=DT_REG)
continue;
#endif

which is completely correct.
BUT:
- Linux defines _DIRENT_HAVE_D_TYPE
- readdir for a reiserfs ALWAYS returns DT_UNKNOWN as d_dtype
so always the continue statement will be executed and the configfile will be
ignored.
I made a patch which uses stat and the S_ISREG and S_ISDIR macros instead of
d_type, which also should work on systems without _DIRENT_HAVE_D_TYPE.

Greetings from Munich,
Gerhard

------=_NextPart_000_0251_01C659C6.58F696F0
Content-Type: application/octet-stream;
name="nrpe-2.5.reiserfs.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="nrpe-2.5.reiserfs.patch"

diff -Naur nrpe-2.5/src/nrpe.c nrpe-2.5.reiserfs/src/nrpe.c=0A=
--- nrpe-2.5/src/nrpe.c 2006-04-06 21:30:00.207859567 +0200=0A=
+++ nrpe-2.5.reiserfs/src/nrpe.c 2006-04-06 22:00:26.379158709 +0200=0A=
@@ -510,6 +510,7 @@=0A=
char config_file[MAX_FILENAME_LENGTH];=0A=
DIR *dirp;=0A=
struct dirent *dirfile;=0A=
+ struct stat buf;=0A=
int result=3DOK;=0A=
int x;=0A=
=0A=
@@ -523,19 +524,18 @@=0A=
/* process all files in the directory... */=0A=
while((dirfile=3Dreaddir(dirp))!=3DNULL){=0A=
=0A=
+ /* create the full path to the config file or subdirectory */=0A=
+ =
snprintf(config_file,sizeof(config_file)-1,"%s/%s",dirname,dirfile->d_nam=
e);=0A=
+ config_file[sizeof(config_file)-1]=3D'\x0';=0A=
+ stat(config_file, &buf);=0A=
+=0A=
/* process this if it's a config file... */=0A=
x=3Dstrlen(dirfile->d_name);=0A=
if(x>4 && !strcmp(dirfile->d_name+(x-4),".cfg")){=0A=
=0A=
-#ifdef _DIRENT_HAVE_D_TYPE=0A=
/* only process normal files */=0A=
- if(dirfile->d_type!=3DDT_REG)=0A=
+ if (! S_ISREG(buf.st_mode))=0A=
continue;=0A=
-#endif=0A=
-=0A=
- /* create the full path to the config file */=0A=
- =
snprintf(config_file,sizeof(config_file)-1,"%s/%s",dirname,dirfile->d_nam=
e);=0A=
- config_file[sizeof(config_file)-1]=3D'\x0';=0A=
=0A=
/* process the config file */=0A=
result=3Dread_config_file(config_file);=0A=
@@ -545,18 +545,13 @@=0A=
break;=0A=
}=0A=
=0A=
-#ifdef _DIRENT_HAVE_D_TYPE=0A=
/* recurse into subdirectories... */=0A=
- if(dirfile->d_type=3D=3DDT_DIR){=0A=
+ if(S_ISDIR(buf.st_mode)) {=0A=
=0A=
/* ignore current, parent and hidden directory entries */=0A=
if(dirfile->d_name[0]=3D=3D'.')=0A=
continue;=0A=
=0A=
- /* create the full path to the config directory */=0A=
- =
snprintf(config_file,sizeof(config_file)-1,"%s/%s",dirname,dirfile->d_nam=
e);=0A=
- config_file[sizeof(config_file)-1]=3D'\x0';=0A=
-=0A=
/* process the config directory */=0A=
result=3Dread_config_dir(config_file);=0A=
=0A=
@@ -564,7 +559,6 @@=0A=
if(result=3D=3DERROR)=0A=
break;=0A=
}=0A=
-#endif=0A=
}=0A=
=0A=
closedir(dirp);=0A=

------=_NextPart_000_0251_01C659C6.58F696F0--






This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked