[Nagiosplug-checkins] nagiosplug/plugins check_disk.c, 1.79, 1.80 check_swap.c, 1.56, 1.57 common.h, 1.24, 1.25 netutils.h, 1.16, 1.17

Ton Voon tonvoon at users.sourceforge.net
Thu Dec 7 17:07:44 CET 2006


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv5252/plugins

Modified Files:
	check_disk.c check_swap.c common.h netutils.h 
Log Message:
Fix coredump on 64bit Solaris. Also adds more error conditions and moves
swap specific includes out of common.h (Duncan Ferguson - 1588031)


Index: check_disk.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_disk.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- check_disk.c	26 Oct 2006 20:51:24 -0000	1.79
+++ check_disk.c	7 Dec 2006 16:07:42 -0000	1.80
@@ -39,6 +39,9 @@
 
 
 #include "common.h"
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
 #if HAVE_INTTYPES_H
 # include <inttypes.h>
 #endif

Index: netutils.h
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/netutils.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- netutils.h	31 Oct 2005 20:03:19 -0000	1.16
+++ netutils.h	7 Dec 2006 16:07:42 -0000	1.17
@@ -35,7 +35,6 @@
 #ifndef _NETUTILS_H_
 #define _NETUTILS_H_
 
-#include "config.h"
 #include "common.h"
 #include "utils.h"
 #include <netinet/in.h>

Index: common.h
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/common.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- common.h	29 Jul 2006 01:43:34 -0000	1.24
+++ common.h	7 Dec 2006 16:07:42 -0000	1.25
@@ -36,6 +36,12 @@
 #define _COMMON_H_
 
 #include "config.h"
+/* This needs to be removed for Solaris servers, where 64 bit files, but 32 bit architecture
+   This needs to be done early on because subsequent system includes use _FILE_OFFSET_BITS
+   Cannot remove from config.h because is included by regex.c from lib/ */
+#if __sun__ && !defined(_LP64) && _FILE_OFFSET_BITS == 64
+#undef _FILE_OFFSET_BITS
+#endif
 
 #ifdef HAVE_FEATURES_H
 #include <features.h>
@@ -114,27 +120,6 @@
 #include <locale.h>
 #endif
 
-/* Fixes "Cannot use swapctl in the large files compilation environment" error on Solaris */
-#ifdef _FILE_OFFSET_BITS
-#undef _FILE_OFFSET_BITS
-#endif
-
-#ifdef HAVE_DECL_SWAPCTL
-# ifdef HAVE_SYS_SWAP_H
-#  include <sys/swap.h>
-# endif
-# ifdef HAVE_SYS_STAT_H
-#  include <sys/stat.h>
-# endif
-# ifdef HAVE_SYS_PARAM_H
-#  include <sys/param.h>
-# endif
-#endif
-
-#ifndef SWAP_CONVERSION
-# define SWAP_CONVERSION 1
-#endif
-
 #ifdef HAVE_SYS_POLL_H
 # include "sys/poll.h"
 #endif

Index: check_swap.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_swap.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- check_swap.c	19 Oct 2006 23:53:28 -0000	1.56
+++ check_swap.c	7 Dec 2006 16:07:42 -0000	1.57
@@ -41,6 +41,22 @@
 #include "popen.h"
 #include "utils.h"
 
+#ifdef HAVE_DECL_SWAPCTL
+# ifdef HAVE_SYS_SWAP_H
+#  include <sys/swap.h>
+# endif
+# ifdef HAVE_SYS_STAT_H
+#  include <sys/stat.h>
+# endif
+# ifdef HAVE_SYS_PARAM_H
+#  include <sys/param.h>
+# endif
+#endif
+
+#ifndef SWAP_CONVERSION
+# define SWAP_CONVERSION 1
+#endif
+
 int check_swap (int usp, float free_swap_mb);
 int process_arguments (int argc, char **argv);
 int validate_arguments (void);
@@ -236,22 +252,33 @@
 #  ifdef CHECK_SWAP_SWAPCTL_SVR4
 
 	/* get the number of active swap devices */
-	nswaps=swapctl(SC_GETNSWP, NULL);
+	if((nswaps=swapctl(SC_GETNSWP, NULL))== -1)
+		die(STATE_UNKNOWN, _("Error getting swap devices\n") );
+
+	if(nswaps == 0)
+		die(STATE_OK, _("SWAP OK: No swap devices defined\n"));
+
+	if(verbose >= 3)
+		printf("Found %d swap device(s)\n", nswaps);
 
 	/* initialize swap table + entries */
 	tbl=(swaptbl_t*)malloc(sizeof(swaptbl_t)+(sizeof(swapent_t)*nswaps));
+
+	if(tbl==NULL)
+		die(STATE_UNKNOWN, _("malloc() failed!\n"));
+
 	memset(tbl, 0, sizeof(swaptbl_t)+(sizeof(swapent_t)*nswaps));
 	tbl->swt_n=nswaps;
 	for(i=0;i<nswaps;i++){
-		ent=&tbl->swt_ent[i];
-		ent->ste_path=(char*)malloc(sizeof(char)*MAXPATHLEN);
+		if((tbl->swt_ent[i].ste_path=(char*)malloc(sizeof(char)*MAXPATHLEN)) == NULL)
+			die(STATE_UNKNOWN, _("malloc() failed!\n"));
 	}
 
 	/* and now, tally 'em up */
 	swapctl_res=swapctl(SC_LIST, tbl);
 	if(swapctl_res < 0){
 		perror(_("swapctl failed: "));
-		result = STATE_WARNING;
+		die(STATE_UNKNOWN, _("Error in swapctl call\n"));
 	}
 
 	for(i=0;i<nswaps;i++){
@@ -293,7 +320,7 @@
 	swapctl_res=swapctl(SWAP_STATS, ent, nswaps);
 	if(swapctl_res < 0){
 		perror(_("swapctl failed: "));
-		result = STATE_WARNING;
+		die(STATE_UNKNOWN, _("Error in swapctl call\n"));
 	}
 
 	for(i=0;i<nswaps;i++){





More information about the Commits mailing list