Révision c01ddbb0
extract function getenvint to common.c
| tools/munin-plugins-busybox/common.c | ||
|---|---|---|
| 1 | 1 |
#include <stdio.h> |
| 2 |
#include <stdlib.h> |
|
| 2 | 3 |
|
| 3 | 4 |
int writeyes(void) {
|
| 4 | 5 |
puts("yes");
|
| ... | ... | |
| 12 | 13 |
puts("no");
|
| 13 | 14 |
return 1; |
| 14 | 15 |
} |
| 16 |
|
|
| 17 |
int getenvint(const char *name, int defvalue) {
|
|
| 18 |
const char *value; |
|
| 19 |
value = getenv(name); |
|
| 20 |
if(value == NULL) |
|
| 21 |
return defvalue; |
|
| 22 |
return atoi(value); |
|
| 23 |
} |
|
| tools/munin-plugins-busybox/common.h | ||
|---|---|---|
| 5 | 5 |
|
| 6 | 6 |
int writeyes(void); |
| 7 | 7 |
int writeno(const char *); |
| 8 |
int getenvint(const char *, int); |
|
| 8 | 9 |
|
| 9 | 10 |
#endif |
| tools/munin-plugins-busybox/load.c | ||
|---|---|---|
| 7 | 7 |
|
| 8 | 8 |
int load(int argc, char **argv) {
|
| 9 | 9 |
FILE *f; |
| 10 |
int warn, crit; |
|
| 11 | 10 |
float val; |
| 12 |
char *s; |
|
| 13 | 11 |
if(argc > 1) {
|
| 14 | 12 |
if(!strcmp(argv[1], "config")) {
|
| 15 |
s = getenv("load_warn");
|
|
| 16 |
if(s) |
|
| 17 |
warn = atoi(s); |
|
| 18 |
else |
|
| 19 |
warn = 10; |
|
| 20 |
s = getenv("load_crit");
|
|
| 21 |
if(s) |
|
| 22 |
crit = atoi(s); |
|
| 23 |
else |
|
| 24 |
crit = 120; |
|
| 25 | 13 |
puts("graph_title Load average\n"
|
| 26 | 14 |
"graph_args --base 1000 -l 0\n" |
| 27 | 15 |
"graph_vlabel load\n" |
| 28 | 16 |
"graph_scale no\n" |
| 29 | 17 |
"graph_category system\n" |
| 30 | 18 |
"load.label load"); |
| 31 |
printf("load.warning %d\nload.critical %d\n", warn, crit);
|
|
| 19 |
printf("load.warning %d\nload.critical %d\n",
|
|
| 20 |
getenvint("load_warn", 10),
|
|
| 21 |
getenvint("load_crit", 120));
|
|
| 32 | 22 |
return 0; |
| 33 | 23 |
} |
| 34 | 24 |
if(!strcmp(argv[1], "autoconf")) |
Formats disponibles : Unified diff