summaryrefslogtreecommitdiffstats
path: root/plugins/check_swap.c
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2006-12-07 16:07:42 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2006-12-07 16:07:42 +0000
commitdf3662bf3ac0d071b6f0b2d4e5bd45942667e75e (patch)
treef168820b481cad2b9a37325efb7382f26b9e85a7 /plugins/check_swap.c
parent26725ccd159105e38e5ab4ddc9ef848a5253e6d2 (diff)
downloadmonitoring-plugins-df3662bf3ac0d071b6f0b2d4e5bd45942667e75e.tar.gz
Fix coredump on 64bit Solaris. Also adds more error conditions and moves
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
Diffstat (limited to 'plugins/check_swap.c')
-rw-r--r--plugins/check_swap.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index db8ebf95..59c1ecf6 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -41,6 +41,22 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
41#include "popen.h" 41#include "popen.h"
42#include "utils.h" 42#include "utils.h"
43 43
44#ifdef HAVE_DECL_SWAPCTL
45# ifdef HAVE_SYS_SWAP_H
46# include <sys/swap.h>
47# endif
48# ifdef HAVE_SYS_STAT_H
49# include <sys/stat.h>
50# endif
51# ifdef HAVE_SYS_PARAM_H
52# include <sys/param.h>
53# endif
54#endif
55
56#ifndef SWAP_CONVERSION
57# define SWAP_CONVERSION 1
58#endif
59
44int check_swap (int usp, float free_swap_mb); 60int check_swap (int usp, float free_swap_mb);
45int process_arguments (int argc, char **argv); 61int process_arguments (int argc, char **argv);
46int validate_arguments (void); 62int validate_arguments (void);
@@ -236,22 +252,33 @@ main (int argc, char **argv)
236# ifdef CHECK_SWAP_SWAPCTL_SVR4 252# ifdef CHECK_SWAP_SWAPCTL_SVR4
237 253
238 /* get the number of active swap devices */ 254 /* get the number of active swap devices */
239 nswaps=swapctl(SC_GETNSWP, NULL); 255 if((nswaps=swapctl(SC_GETNSWP, NULL))== -1)
256 die(STATE_UNKNOWN, _("Error getting swap devices\n") );
257
258 if(nswaps == 0)
259 die(STATE_OK, _("SWAP OK: No swap devices defined\n"));
260
261 if(verbose >= 3)
262 printf("Found %d swap device(s)\n", nswaps);
240 263
241 /* initialize swap table + entries */ 264 /* initialize swap table + entries */
242 tbl=(swaptbl_t*)malloc(sizeof(swaptbl_t)+(sizeof(swapent_t)*nswaps)); 265 tbl=(swaptbl_t*)malloc(sizeof(swaptbl_t)+(sizeof(swapent_t)*nswaps));
266
267 if(tbl==NULL)
268 die(STATE_UNKNOWN, _("malloc() failed!\n"));
269
243 memset(tbl, 0, sizeof(swaptbl_t)+(sizeof(swapent_t)*nswaps)); 270 memset(tbl, 0, sizeof(swaptbl_t)+(sizeof(swapent_t)*nswaps));
244 tbl->swt_n=nswaps; 271 tbl->swt_n=nswaps;
245 for(i=0;i<nswaps;i++){ 272 for(i=0;i<nswaps;i++){
246 ent=&tbl->swt_ent[i]; 273 if((tbl->swt_ent[i].ste_path=(char*)malloc(sizeof(char)*MAXPATHLEN)) == NULL)
247 ent->ste_path=(char*)malloc(sizeof(char)*MAXPATHLEN); 274 die(STATE_UNKNOWN, _("malloc() failed!\n"));
248 } 275 }
249 276
250 /* and now, tally 'em up */ 277 /* and now, tally 'em up */
251 swapctl_res=swapctl(SC_LIST, tbl); 278 swapctl_res=swapctl(SC_LIST, tbl);
252 if(swapctl_res < 0){ 279 if(swapctl_res < 0){
253 perror(_("swapctl failed: ")); 280 perror(_("swapctl failed: "));
254 result = STATE_WARNING; 281 die(STATE_UNKNOWN, _("Error in swapctl call\n"));
255 } 282 }
256 283
257 for(i=0;i<nswaps;i++){ 284 for(i=0;i<nswaps;i++){
@@ -293,7 +320,7 @@ main (int argc, char **argv)
293 swapctl_res=swapctl(SWAP_STATS, ent, nswaps); 320 swapctl_res=swapctl(SWAP_STATS, ent, nswaps);
294 if(swapctl_res < 0){ 321 if(swapctl_res < 0){
295 perror(_("swapctl failed: ")); 322 perror(_("swapctl failed: "));
296 result = STATE_WARNING; 323 die(STATE_UNKNOWN, _("Error in swapctl call\n"));
297 } 324 }
298 325
299 for(i=0;i<nswaps;i++){ 326 for(i=0;i<nswaps;i++){