diff options
Diffstat (limited to 'plugins/check_vsz.c')
-rw-r--r-- | plugins/check_vsz.c | 33 |
1 files changed, 6 insertions, 27 deletions
diff --git a/plugins/check_vsz.c b/plugins/check_vsz.c index 2ec8775..7eeab22 100644 --- a/plugins/check_vsz.c +++ b/plugins/check_vsz.c | |||
@@ -61,7 +61,7 @@ main (int argc, char **argv) | |||
61 | int proc_size = -1; | 61 | int proc_size = -1; |
62 | char input_buffer[MAX_INPUT_BUFFER]; | 62 | char input_buffer[MAX_INPUT_BUFFER]; |
63 | char proc_name[MAX_INPUT_BUFFER]; | 63 | char proc_name[MAX_INPUT_BUFFER]; |
64 | char *message = NULL; | 64 | char *message = ""; |
65 | 65 | ||
66 | if (!process_arguments (argc, argv)) { | 66 | if (!process_arguments (argc, argv)) { |
67 | printf ("%s: failure parsing arguments\n", my_basename (argv[0])); | 67 | printf ("%s: failure parsing arguments\n", my_basename (argv[0])); |
@@ -80,8 +80,6 @@ main (int argc, char **argv) | |||
80 | if (child_stderr == NULL) | 80 | if (child_stderr == NULL) |
81 | printf ("Could not open stderr for %s\n", VSZ_COMMAND); | 81 | printf ("Could not open stderr for %s\n", VSZ_COMMAND); |
82 | 82 | ||
83 | message = malloc ((size_t) 1); | ||
84 | message[0] = 0; | ||
85 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | 83 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { |
86 | 84 | ||
87 | line++; | 85 | line++; |
@@ -93,12 +91,7 @@ main (int argc, char **argv) | |||
93 | if (sscanf (input_buffer, VSZ_FORMAT, &proc_size, proc_name) == 2) { | 91 | if (sscanf (input_buffer, VSZ_FORMAT, &proc_size, proc_name) == 2) { |
94 | if (proc == NULL) { | 92 | if (proc == NULL) { |
95 | if (proc_size > warn) { | 93 | if (proc_size > warn) { |
96 | len = strlen (message) + strlen (proc_name) + 23; | 94 | asprintf (&message, "%s %s(%d)", message, proc_name, proc_size); |
97 | message = realloc (message, len); | ||
98 | if (message == NULL) | ||
99 | terminate (STATE_UNKNOWN, | ||
100 | "check_vsz: could not malloc message (1)"); | ||
101 | sprintf (message, "%s %s(%d)", message, proc_name, proc_size); | ||
102 | result = max_state (result, STATE_WARNING); | 95 | result = max_state (result, STATE_WARNING); |
103 | } | 96 | } |
104 | if (proc_size > crit) { | 97 | if (proc_size > crit) { |
@@ -106,12 +99,7 @@ main (int argc, char **argv) | |||
106 | } | 99 | } |
107 | } | 100 | } |
108 | else if (strstr (proc_name, proc)) { | 101 | else if (strstr (proc_name, proc)) { |
109 | len = strlen (message) + 21; | 102 | asprintf (&message, "%s %d", message, proc_size); |
110 | message = realloc (message, len); | ||
111 | if (message == NULL) | ||
112 | terminate (STATE_UNKNOWN, | ||
113 | "check_vsz: could not malloc message (2)"); | ||
114 | sprintf (message, "%s %d", message, proc_size); | ||
115 | if (proc_size > warn) { | 103 | if (proc_size > warn) { |
116 | result = max_state (result, STATE_WARNING); | 104 | result = max_state (result, STATE_WARNING); |
117 | } | 105 | } |
@@ -206,11 +194,7 @@ process_arguments (int argc, char **argv) | |||
206 | warn = atoi (optarg); | 194 | warn = atoi (optarg); |
207 | break; | 195 | break; |
208 | case 'C': /* command name */ | 196 | case 'C': /* command name */ |
209 | proc = malloc (strlen (optarg) + 1); | 197 | proc = optarg; |
210 | if (proc == NULL) | ||
211 | terminate (STATE_UNKNOWN, | ||
212 | "check_vsz: failed malloc of proc in process_arguments"); | ||
213 | strcpy (proc, optarg); | ||
214 | break; | 198 | break; |
215 | } | 199 | } |
216 | } | 200 | } |
@@ -236,13 +220,8 @@ process_arguments (int argc, char **argv) | |||
236 | crit = atoi (argv[c++]); | 220 | crit = atoi (argv[c++]); |
237 | } | 221 | } |
238 | 222 | ||
239 | if (proc == NULL) { | 223 | if (proc == NULL) |
240 | proc = malloc (strlen (argv[c]) + 1); | 224 | proc = argv[c]; |
241 | if (proc == NULL) | ||
242 | terminate (STATE_UNKNOWN, | ||
243 | "check_vsz: failed malloc of proc in process_arguments"); | ||
244 | strcpy (proc, argv[c]); | ||
245 | } | ||
246 | 225 | ||
247 | return c; | 226 | return c; |
248 | } | 227 | } |