diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-13 11:50:54 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-13 11:50:54 +0000 |
commit | 9e009c4b1128352c6039d25b39213fd480e9b055 (patch) | |
tree | e1495ef4ada6f8e092e20bc474195719f1b2b4aa /plugins/check_vsz.c | |
parent | 9728dcad931d1c442a6d8e3e6765e2d9870600d1 (diff) | |
download | monitoring-plugins-9e009c4b1128352c6039d25b39213fd480e9b055.tar.gz |
remove call_getopt and asprintf
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@190 f882894a-f735-0410-b71e-b25c423dba1c
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 2ec8775b..7eeab22c 100644 --- a/plugins/check_vsz.c +++ b/plugins/check_vsz.c @@ -61,7 +61,7 @@ main (int argc, char **argv) int proc_size = -1; char input_buffer[MAX_INPUT_BUFFER]; char proc_name[MAX_INPUT_BUFFER]; - char *message = NULL; + char *message = ""; if (!process_arguments (argc, argv)) { printf ("%s: failure parsing arguments\n", my_basename (argv[0])); @@ -80,8 +80,6 @@ main (int argc, char **argv) if (child_stderr == NULL) printf ("Could not open stderr for %s\n", VSZ_COMMAND); - message = malloc ((size_t) 1); - message[0] = 0; while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { line++; @@ -93,12 +91,7 @@ main (int argc, char **argv) if (sscanf (input_buffer, VSZ_FORMAT, &proc_size, proc_name) == 2) { if (proc == NULL) { if (proc_size > warn) { - len = strlen (message) + strlen (proc_name) + 23; - message = realloc (message, len); - if (message == NULL) - terminate (STATE_UNKNOWN, - "check_vsz: could not malloc message (1)"); - sprintf (message, "%s %s(%d)", message, proc_name, proc_size); + asprintf (&message, "%s %s(%d)", message, proc_name, proc_size); result = max_state (result, STATE_WARNING); } if (proc_size > crit) { @@ -106,12 +99,7 @@ main (int argc, char **argv) } } else if (strstr (proc_name, proc)) { - len = strlen (message) + 21; - message = realloc (message, len); - if (message == NULL) - terminate (STATE_UNKNOWN, - "check_vsz: could not malloc message (2)"); - sprintf (message, "%s %d", message, proc_size); + asprintf (&message, "%s %d", message, proc_size); if (proc_size > warn) { result = max_state (result, STATE_WARNING); } @@ -206,11 +194,7 @@ process_arguments (int argc, char **argv) warn = atoi (optarg); break; case 'C': /* command name */ - proc = malloc (strlen (optarg) + 1); - if (proc == NULL) - terminate (STATE_UNKNOWN, - "check_vsz: failed malloc of proc in process_arguments"); - strcpy (proc, optarg); + proc = optarg; break; } } @@ -236,13 +220,8 @@ process_arguments (int argc, char **argv) crit = atoi (argv[c++]); } - if (proc == NULL) { - proc = malloc (strlen (argv[c]) + 1); - if (proc == NULL) - terminate (STATE_UNKNOWN, - "check_vsz: failed malloc of proc in process_arguments"); - strcpy (proc, argv[c]); - } + if (proc == NULL) + proc = argv[c]; return c; } |