diff options
| -rw-r--r-- | plugins/check_swap.d/swap.c | 39 | 
1 files changed, 30 insertions, 9 deletions
| diff --git a/plugins/check_swap.d/swap.c b/plugins/check_swap.d/swap.c index 7703fb3e..8dc7a4cc 100644 --- a/plugins/check_swap.d/swap.c +++ b/plugins/check_swap.d/swap.c | |||
| @@ -225,19 +225,41 @@ swap_result getSwapFromSwapCommand(swap_config config, const char swap_command[] | |||
| 225 | return result; | 225 | return result; | 
| 226 | } | 226 | } | 
| 227 | 227 | ||
| 228 | #ifdef CHECK_SWAP_SWAPCTL_BSD | 228 | #ifndef CHECK_SWAP_SWAPCTL_BSD | 
| 229 | swap_result getSwapFromSwapctl_BSD(swap_config config) { | 229 | #define CHECK_SWAP_SWAPCTL_BSD | 
| 230 | int i = 0, nswaps = 0, swapctl_res = 0; | 230 | |
| 231 | struct swapent *ent; | 231 | // Stub functionality for BSD stuff, so the compiler always sees the following BSD code | 
| 232 | |||
| 233 | #define SWAP_NSWAP 0 | ||
| 234 | #define SWAP_STATS 1 | ||
| 235 | |||
| 236 | int swapctl(int cmd, const void *arg, int misc) { | ||
| 237 | (void) cmd; | ||
| 238 | (void) arg; | ||
| 239 | (void) misc; | ||
| 240 | return 512; | ||
| 241 | } | ||
| 242 | |||
| 243 | struct swapent { | ||
| 244 | dev_t se_dev; /* device id */ | ||
| 245 | int se_flags; /* entry flags */ | ||
| 246 | int se_nblks; /* total blocks */ | ||
| 247 | int se_inuse; /* blocks in use */ | ||
| 248 | int se_priority; /* priority */ | ||
| 249 | char se_path[PATH_MAX]; /* path to entry */ | ||
| 250 | }; | ||
| 251 | |||
| 252 | #endif | ||
| 232 | 253 | ||
| 254 | swap_result getSwapFromSwapctl_BSD(swap_config config) { | ||
| 233 | /* get the number of active swap devices */ | 255 | /* get the number of active swap devices */ | 
| 234 | nswaps = swapctl(SWAP_NSWAP, NULL, 0); | 256 | int nswaps = swapctl(SWAP_NSWAP, NULL, 0); | 
| 235 | 257 | ||
| 236 | /* initialize swap table + entries */ | 258 | /* initialize swap table + entries */ | 
| 237 | ent = (struct swapent *)malloc(sizeof(struct swapent) * nswaps); | 259 | struct swapent *ent = (struct swapent *)malloc(sizeof(struct swapent) * nswaps); | 
| 238 | 260 | ||
| 239 | /* and now, tally 'em up */ | 261 | /* and now, tally 'em up */ | 
| 240 | swapctl_res = swapctl(SWAP_STATS, ent, nswaps); | 262 | int swapctl_res = swapctl(SWAP_STATS, ent, nswaps); | 
| 241 | if (swapctl_res < 0) { | 263 | if (swapctl_res < 0) { | 
| 242 | perror(_("swapctl failed: ")); | 264 | perror(_("swapctl failed: ")); | 
| 243 | die(STATE_UNKNOWN, _("Error in swapctl call\n")); | 265 | die(STATE_UNKNOWN, _("Error in swapctl call\n")); | 
| @@ -247,7 +269,7 @@ swap_result getSwapFromSwapctl_BSD(swap_config config) { | |||
| 247 | double dsktotal_mb = 0.0, dskfree_mb = 0.0, dskused_mb = 0.0; | 269 | double dsktotal_mb = 0.0, dskfree_mb = 0.0, dskused_mb = 0.0; | 
| 248 | unsigned long long total_swap_mb = 0, free_swap_mb = 0, used_swap_mb = 0; | 270 | unsigned long long total_swap_mb = 0, free_swap_mb = 0, used_swap_mb = 0; | 
| 249 | 271 | ||
| 250 | for (i = 0; i < nswaps; i++) { | 272 | for (int i = 0; i < nswaps; i++) { | 
| 251 | dsktotal_mb = (float)ent[i].se_nblks / config.conversion_factor; | 273 | dsktotal_mb = (float)ent[i].se_nblks / config.conversion_factor; | 
| 252 | dskused_mb = (float)ent[i].se_inuse / config.conversion_factor; | 274 | dskused_mb = (float)ent[i].se_inuse / config.conversion_factor; | 
| 253 | dskfree_mb = (dsktotal_mb - dskused_mb); | 275 | dskfree_mb = (dsktotal_mb - dskused_mb); | 
| @@ -279,7 +301,6 @@ swap_result getSwapFromSwapctl_BSD(swap_config config) { | |||
| 279 | 301 | ||
| 280 | return result; | 302 | return result; | 
| 281 | } | 303 | } | 
| 282 | #endif // CHECK_SWAP_SWAPCTL_BSD | ||
| 283 | 304 | ||
| 284 | #ifdef CHECK_SWAP_SWAPCTL_SVR4 | 305 | #ifdef CHECK_SWAP_SWAPCTL_SVR4 | 
| 285 | swap_result getSwapFromSwap_SRV4(swap_config config) { | 306 | swap_result getSwapFromSwap_SRV4(swap_config config) { | 
