Code

Fix coredump on 64bit Solaris. Also adds more error conditions and moves
authorTon Voon <tonvoon@users.sourceforge.net>
Thu, 7 Dec 2006 16:07:42 +0000 (16:07 +0000)
committerTon Voon <tonvoon@users.sourceforge.net>
Thu, 7 Dec 2006 16:07:42 +0000 (16:07 +0000)
swap specific includes out of common.h (Duncan Ferguson - 1588031)

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1546 f882894a-f735-0410-b71e-b25c423dba1c

THANKS.in
plugins/check_disk.c
plugins/check_swap.c
plugins/common.h
plugins/netutils.h

index 9d880e4548c4bd704635367136604cb623d9e812..4c8641103b8a43af5c2c295f31a7928d5b9dac75 100644 (file)
--- a/THANKS.in
+++ b/THANKS.in
@@ -201,3 +201,4 @@ Henning Schmiedehausen
 Markus Baertschi
 Florian Gleixner
 Pawel Malachowski
+Duncan Ferguson
index 8f980a4948934c42bf1360e47fd8b87aaa1effe8..51e8e850e53070cf165d2ac7252cb6c9af985358 100644 (file)
@@ -39,6 +39,9 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 
 #include "common.h"
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
 #if HAVE_INTTYPES_H
 # include <inttypes.h>
 #endif
index db8ebf953668fb450fc3e59e41633e415f7a96ca..59c1ecf6ce2d902d7298de4fd25e67d659dff427 100644 (file)
@@ -41,6 +41,22 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
 #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 @@ main (int argc, char **argv)
 #  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 @@ main (int argc, char **argv)
        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++){
index ac3b8339d9d50849f64d1e50c5b74eed0abafea7..b3357431a5d7ce4f4dba7359d049292fb370f9ed 100644 (file)
 #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>
 #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 1168f9f82eb688579da061cb891a434739f0fdac..3fc4ef8060615932e9a9ed82f12f7aa364772f67 100644 (file)
@@ -35,7 +35,6 @@
 #ifndef _NETUTILS_H_
 #define _NETUTILS_H_
 
-#include "config.h"
 #include "common.h"
 #include "utils.h"
 #include <netinet/in.h>