Xymon Mailing List Archive search

bbhostshow segfaults...

2 messages in this thread

list Kolbjørn Barmen · Wed, 7 Jun 2006 21:39:19 +0200 (CEST) ·
.. if bb-hosts has "directory" entries.

Works fine with "include" entries.

Hopefully reproduceable elsewhere as well :)

-- 
Kolbjørn Barmen
UNINETT Driftsenter
list Henrik Størner · Wed, 7 Jun 2006 22:44:35 +0200 ·
quoted from Kolbjørn Barmen
On Wed, Jun 07, 2006 at 09:39:19PM +0200, Kolbjørn Barmen wrote:
.. if bb-hosts has "directory" entries.

Works fine with "include" entries.

Hopefully reproduceable elsewhere as well :)
Very reproducible. Patch attached.


Henrik

-------------- next part --------------
--- lib/stackio.c	2006/05/03 21:12:33	1.18
+++ lib/stackio.c	2006/06/07 20:42:15
@@ -11,7 +11,7 @@
 /*                                                                            */
 /*----------------------------------------------------------------------------*/
 
-static char rcsid[] = "$Id: stackio.c,v 1.18 2006/05/03 21:12:33 henrik Exp $";
+static char rcsid[] = "$Id: stackio.c,v 1.19 2006/06/07 20:42:14 henrik Exp $";
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -327,7 +327,6 @@
 static void addtofnlist(char *dirname, void **v_listhead)
 {
 	filelist_t **listhead = (filelist_t **)v_listhead;
-	filelist_t *newlistitem;
 	DIR *dirfd;
 	struct dirent *d;
 	struct stat st;
@@ -344,13 +343,17 @@
 	}
 
 	/* Add the directory itself to the list of files we watch for modifications */
-	stat(dirfn, &st);
-	newlistitem = (filelist_t *)malloc(sizeof(filelist_t));
-	newlistitem->filename = strdup(dirfn);
-	newlistitem->mtime = st.st_mtime;
-	newlistitem->fsize = 0; /* We dont check sizes of directories */
-	newlistitem->next = *listhead;
-	*listhead = newlistitem;
+	if (listhead) {
+		filelist_t *newlistitem;
• +		stat(dirfn, &st);
+		newlistitem = (filelist_t *)malloc(sizeof(filelist_t));
+		newlistitem->filename = strdup(dirfn);
+		newlistitem->mtime = st.st_mtime;
+		newlistitem->fsize = 0; /* We dont check sizes of directories */
+		newlistitem->next = *listhead;
+		*listhead = newlistitem;
+	}
 
 	while ((d = readdir(dirfd)) != NULL) {
 		int fnlen = strlen(d->d_name);