[Nagios-devel] Small problem with configfile dirs on XFS on Linux

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] Small problem with configfile dirs on XFS on Linux

Post by Guest »

--=-4SCT70sEVtEBgcefIjW9
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi,

I was having some interesting problems today with one
of the latest CVS snapshot running on a Linux system with
XFS filesystems. The code in xodtemplate.c find out that
Linux supports Linux has _DIRENT_HAVE_D_TYPE but on XFS
the d_type is set to DT_UNKNOWN which means one should use
stat to figure out what type of file it really is. After
finding out this frustrating bug I went out and did a
quick and dirty patch. Attached is the patch which works
around the DT_UNKNOWN value and fixed my problems on XFS
filesystems with configfile directories.

Marco van Wieringen
ELM Consultancy B.V.



--=-4SCT70sEVtEBgcefIjW9
Content-Disposition: attachment; filename=nagios_xodtemplate.c.diff
Content-Type: text/x-patch; name=nagios_xodtemplate.c.diff; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

--- xodtemplate.c.org 2004-05-11 20:53:14.603841000 +0200
+++ xodtemplate.c 2004-05-11 20:54:42.015725000 +0200
@@ -358,16 +358,24 @@
x=strlen(dirfile->d_name);
if(x>4 && !strcmp(dirfile->d_name+(x-4),".cfg")){

-#ifdef _DIRENT_HAVE_D_TYPE
- /* only process normal files and symlinks */
- if(dirfile->d_type!=DT_REG && dirfile->d_type!=DT_LNK)
- continue;
-#endif
-
/* create the full path to the config file */
snprintf(config_file,sizeof(config_file)-1,"%s/%s",dirname,dirfile->d_name);
config_file[sizeof(config_file)-1]='\x0';

+#ifdef _DIRENT_HAVE_D_TYPE
+ /* only process normal files and symlinks */
+ if (dirfile->d_type==DT_UNKNOWN) {
+ x=stat(config_file,&stat_buf);
+ if(x!=0){
+ if(!S_ISREG(stat_buf.st_mode) && !S_ISLNK(stat_buf.st_mode))
+ continue;
+ }
+ } else {
+ if(dirfile->d_type!=DT_REG && dirfile->d_type!=DT_LNK)
+ continue;
+ }
+#endif
+
/* process the config file */
result=xodtemplate_process_config_file(config_file,options);

@@ -378,7 +386,16 @@

#ifdef _DIRENT_HAVE_D_TYPE
/* recurse into subdirectories... */
- if(dirfile->d_type==DT_DIR || dirfile->d_type==DT_LNK){
+ if(dirfile->d_type==DT_UNKNOWN || dirfile->d_type==DT_DIR || dirfile->d_type==DT_LNK){
+ if (dirfile->d_type==DT_UNKNOWN) {
+ x=stat(config_file,&stat_buf);
+ if(x!=0){
+ if(!S_ISDIR(stat_buf.st_mode) && !S_ISLNK(stat_buf.st_mode))
+ continue;
+ } else {
+ continue;
+ }
+ }

/* ignore current, parent and hidden directory entries */
if(dirfile->d_name[0]=='.')
@@ -386,7 +403,7 @@

/* check that a symlink points to a dir */

- if(dirfile->d_type==DT_LNK){
+ if(dirfile->d_type==DT_LNK || (dirfile->d_type==DT_UNKNOWN && S_ISLNK(stat_buf.st_mode))){

/* copy full path info to link buffer */
snprintf(file_name_buffer,sizeof(file_name_buffer)-1,"%s/%s",dirname,dirfile->d_name);
--- xodtemplate.c.org 2004-05-11 20:53:14.603841000 +0200
+++ xodtemplate.c 2004-05-11 20:54:42.015725000 +0200
@@ -358,16 +358,24 @@
x=strlen(dirfile->d_name);
if(x>4 && !strcmp(dirfile->d_name+(x-4),".cfg")){

-#ifdef _DIRENT_HAVE_D_TYPE
- /* only process normal files and symlinks */
- if(dirfile->d_type!=DT_REG && dirfile->d_type!=DT_LNK)
- continue;
-#endif
-
/* create the full path to the config file */
snprintf(config_file,sizeof(config_file)-1,"%s/%s",dirname,dirfile->d_name);
config_file[sizeof(config_file)-1]='\x0';

+#ifdef _DIRENT_HAVE_D_TYPE
+ /* only process normal files and symlinks */
+ if (dirfile->d_type==DT_UNKNOWN) {
+ x=stat(config_file,&stat_buf);
+ if(x!=0){
+ if(!S_ISREG(stat_buf.st_mode) && !S_ISLNK(stat_buf.st_mode))
+ continue;
+ }
+ } else {
+ if(dirfile->d_type!=DT_REG && dirfile->d_type!=DT_LNK)
+ continue;
+ }
+#endif
+
/* process the config file */
result=xodtemplate_process_config_file(config_file,options);

@@ -378,7 +386,16 @@

#ifdef _DIRENT_HAVE_D_TYPE
/* recurse into subdirectories... */
- if(dirfile->d_type==DT_DIR || dirfile->d_type==DT_LNK){
+ if(dirfile->d_type==DT_UNKNOWN || dirfile->d_type==DT_DIR || dirfile->d_type==DT_LNK){
+ if (dirfile->d_type==DT_UNKNOWN) {
+ x=stat(config_file,&stat_buf);
+ if(x!=0){
+ if(!S_ISDIR(stat_buf.st_mode

...[email truncated]...


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