summaryrefslogtreecommitdiffstats
path: root/web/attachments/202053-check_swap.c.patch
blob: 34e6a5da80c96a504e2d7878523a1584a151b8ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
*** check_swap.c.orig	Fri Oct 20 00:53:28 2006
--- check_swap.c	Tue Nov  7 14:54:35 2006
***************
*** 37,42 ****
--- 37,48 ----
  const char *copyright = "2000-2006";
  const char *email = "nagiosplug-devel@lists.sourceforge.net";
  
+ /* required to work correctly on solaris (else gets 'Bad Address' errors) */
+ /* #ifdef HAVE_SYS_STAT_H - using this one doesnt work on solaris */
+ #ifdef __sun__
+ #include <sys/stat.h>
+ #endif
+ 
  #include "common.h"
  #include "popen.h"
  #include "utils.h"
***************
*** 236,257 ****
  #  ifdef CHECK_SWAP_SWAPCTL_SVR4
  
  	/* get the number of active swap devices */
! 	nswaps=swapctl(SC_GETNSWP, NULL);
  
  	/* initialize swap table + entries */
  	tbl=(swaptbl_t*)malloc(sizeof(swaptbl_t)+(sizeof(swapent_t)*nswaps));
  	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);
  	}
  
  	/* and now, tally 'em up */
  	swapctl_res=swapctl(SC_LIST, tbl);
  	if(swapctl_res < 0){
! 		perror(_("swapctl failed: "));
! 		result = STATE_WARNING;
  	}
  
  	for(i=0;i<nswaps;i++){
--- 242,273 ----
  #  ifdef CHECK_SWAP_SWAPCTL_SVR4
  
  	/* get the number of active swap devices */
! 	if((nswaps=swapctl(SC_GETNSWP, NULL))== -1)
! 		perror(_(argv[0])), exit(STATE_UNKNOWN);
  
+ 	if(nswaps == 0)
+ 		(void)printf("No swap devices defined\n"), exit(STATE_OK);
+ 
+ 	if(verbose > 0)
+ 		(void)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)
+ 		perror(_(argv[0])), exit(STATE_UNKNOWN);
+ 
  	memset(tbl, 0, sizeof(swaptbl_t)+(sizeof(swapent_t)*nswaps));
  	tbl->swt_n=nswaps;
  	for(i=0;i<nswaps;i++){
! 		if((tbl->swt_ent[i].ste_path=(char*)malloc(sizeof(char)*MAXPATHLEN)) == NULL)
! 			perror(_(argv[0])), exit(STATE_UNKNOWN);
  	}
  
  	/* and now, tally 'em up */
  	swapctl_res=swapctl(SC_LIST, tbl);
  	if(swapctl_res < 0){
! 		perror(_("swapctl failed")), exit(STATE_UNKNOWN);
  	}
  
  	for(i=0;i<nswaps;i++){
***************
*** 292,299 ****
  	/* and now, tally 'em up */
  	swapctl_res=swapctl(SWAP_STATS, ent, nswaps);
  	if(swapctl_res < 0){
! 		perror(_("swapctl failed: "));
! 		result = STATE_WARNING;
  	}
  
  	for(i=0;i<nswaps;i++){
--- 308,314 ----
  	/* and now, tally 'em up */
  	swapctl_res=swapctl(SWAP_STATS, ent, nswaps);
  	if(swapctl_res < 0){
! 		perror(_("swapctl failed")), exit(STATE_UNKNOWN);
  	}
  
  	for(i=0;i<nswaps;i++){