aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Karl DeBisschop <kdebisschop@users.sourceforge.net> 2003-08-09 00:41:06 +0000
committerGravatar Karl DeBisschop <kdebisschop@users.sourceforge.net> 2003-08-09 00:41:06 +0000
commit41158497e887d2d9cd925574f349fd3e65402644 (patch)
tree947605c94adb74ae12cc83440fb22ab6f90c8b08
parent8aee8dd8b4e64a9b023334e0c36761bf75f99306 (diff)
downloadmonitoring-plugins-41158497e887d2d9cd925574f349fd3e65402644.tar.gz
more pedantic compiler warnings
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@668 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--plugins/check_disk.c23
-rw-r--r--plugins/check_dummy.c128
-rw-r--r--plugins/popen.c41
-rw-r--r--plugins/utils.c2
-rw-r--r--plugins/utils.h2
5 files changed, 94 insertions, 102 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index bd060218..7974d141 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -109,7 +109,7 @@ enum
#endif
int process_arguments (int, char **);
-void print_path (char *mypath);
+void print_path (const char *mypath);
int validate_arguments (uintmax_t, uintmax_t, double, double, char *);
int check_disk (double usp, uintmax_t free_disk);
int walk_name_list (struct name_list *list, const char *name);
@@ -216,7 +216,7 @@ main (int argc, char **argv)
temp_list = temp_list->name_next;
}
- die (result, "DISK %s%s\n", state_text (result), output, details);
+ die (result, "DISK %s%s%s\n", state_text (result), output, details);
return STATE_UNKNOWN;
}
@@ -453,11 +453,15 @@ process_arguments (int argc, char **argv)
}
-void print_path (char *mypath)
+void
+print_path (const char *mypath)
{
- if (mypath)
- printf (" for %s", mypath);
- printf ("\n");
+ if (mypath == NULL)
+ printf ("\n");
+ else
+ printf (" for %s\n", mypath);
+
+ return;
}
int
@@ -473,14 +477,14 @@ validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, char *mypath
printf (_("\
INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive"),
cp, wp);
- print_path (path);
+ print_path (mypath);
return ERROR;
}
else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) {
printf (_("\
INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"),
(unsigned long)c, (unsigned long)w);
- print_path (path);
+ print_path (mypath);
return ERROR;
}
@@ -542,6 +546,7 @@ print_help (void)
{
print_revision (progname, revision);
+ printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
printf (_(COPYRIGHT), copyright, email);
printf (_("\
@@ -596,7 +601,7 @@ and generates an alert if free space is less than one of the threshold values.")
check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /\n\
Checks /tmp and /var at 10%,5% and / at 100MB, 50MB\n"));
- support ();
+ printf (_(UT_SUPPORT));
}
diff --git a/plugins/check_dummy.c b/plugins/check_dummy.c
index d90b1409..3db5238f 100644
--- a/plugins/check_dummy.c
+++ b/plugins/check_dummy.c
@@ -1,39 +1,21 @@
-/*************************************************************
- *
- * CHECK_DUMMY.C
- *
- * Program: Dummy plugin for Nagios
- * License: GPL
- * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
- *
- * Last Modified: $Date$
- *
- * Command line: CHECK_DUMMY <state>
- *
- * Description:
- *
- * This plugin will simply return the state corresponding to the
- * numerical value of the <state> argument.
- *
- * License Information:
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- **************************************************************/
-
-#include "config.h"
+/******************************************************************************
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+******************************************************************************/
+
#include "common.h"
#include "utils.h"
@@ -42,39 +24,18 @@ const char *revision = "$Revision$";
const char *copyright = "1999-2003";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
-void
-print_usage (void)
-{
- printf (_("Usage: %s <integer state>\n"), progname);
-}
+void print_help (void);
+void print_usage (void);
-void
-print_help (void)
-{
- print_revision (progname, revision);
- printf (_(COPYRIGHT), copyright, email);
-
- print_usage ();
-
- printf (_(UT_HELP_VRSN));
-
- printf (_("\n\
-This plugin will simply return the state corresponding to the numeric value\n\
-of the <state> argument.\n"));
-
- support ();
-}
int
main (int argc, char **argv)
{
int result;
- if (argc != 2) {
- printf (_("Incorrect number of arguments supplied\n"));
- exit (STATE_UNKNOWN);
- }
+ if (argc != 2)
+ usage (_("Incorrect number of arguments supplied\n"));
else if (strcmp (argv[1], "-V") == 0 || strcmp (argv[1], "--version") == 0) {
print_revision (progname, revision);
exit (STATE_OK);
@@ -83,11 +44,10 @@ main (int argc, char **argv)
print_help ();
exit (STATE_OK);
}
- else if (!is_integer (argv[1])) {
- print_usage ();
- exit (STATE_UNKNOWN);
- }
- result = atoi (argv[1]);
+ else if (!is_integer (argv[1]))
+ usage (_("Arguments to check_dummy must be an integer\n"));
+ else
+ result = atoi (argv[1]);
switch (result) {
case STATE_OK:
@@ -99,10 +59,42 @@ main (int argc, char **argv)
case STATE_CRITICAL:
printf ("Status is CRITICAL\n");
break;
- default:
+ case STATE_UNKNOWN:
printf ("Status is UNKNOWN\n");
- result = STATE_UNKNOWN;
+ break;
+ default:
+ printf ("Status %d is not a supported error state\n", result);
+ break;
}
return result;
}
+
+
+
+void
+print_help (void)
+{
+ print_revision (progname, revision);
+
+ printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
+ printf (_(COPYRIGHT), copyright, email);
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_("\n\
+This plugin will simply return the state corresponding to the numeric value\n\
+of the <state> argument.\n"));
+
+ printf (_(UT_SUPPORT));
+}
+
+
+
+void
+print_usage (void)
+{
+ printf (_("Usage: %s <integer state>\n"), progname);
+}
diff --git a/plugins/popen.c b/plugins/popen.c
index fb855d7b..98ba085b 100644
--- a/plugins/popen.c
+++ b/plugins/popen.c
@@ -57,9 +57,11 @@ RETSIGTYPE popen_timeout_alarm_handler (int);
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))
int open_max (void); /* {Prog openmax} */
-void err_sys (const char *, ...);
+static void err_sys (const char *, ...) __attribute__((noreturn,format(printf, 1, 2)));
char *rtrim (char *, const char *);
+char *pname = NULL; /* caller can set this from argv[0] */
+
/*int *childerr = NULL;*//* ptr to array allocated at run-time */
/*extern pid_t *childpid = NULL; *//* ptr to array allocated at run-time */
static int maxfd; /* from our open_max(), {Prog openmax} */
@@ -67,7 +69,7 @@ static int maxfd; /* from our open_max(), {Prog openmax} */
FILE *
spopen (const char *cmdstring)
{
- char *env[] = { "LC_ALL=C", (char*)0 };
+ char *env[2];
char *cmd = NULL;
char **argv = NULL;
char *str;
@@ -84,6 +86,9 @@ spopen (const char *cmdstring)
setrlimit (RLIMIT_CORE, &limit);
#endif
+ env[0] = strdup("LC_ALL=C");
+ env[1] = '\0';
+
/* if no command was passed, return with no error */
if (cmdstring == NULL)
return (NULL);
@@ -148,13 +153,13 @@ spopen (const char *cmdstring)
if (childpid == NULL) { /* first time through */
maxfd = open_max (); /* allocate zeroed out array for child pids */
- if ((childpid = calloc (maxfd, sizeof (pid_t))) == NULL)
+ if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL)
return (NULL);
}
if (child_stderr_array == NULL) { /* first time through */
maxfd = open_max (); /* allocate zeroed out array for child pids */
- if ((child_stderr_array = calloc (maxfd, sizeof (int))) == NULL)
+ if ((child_stderr_array = calloc ((size_t)maxfd, sizeof (int))) == NULL)
return (NULL);
}
@@ -259,34 +264,22 @@ open_max (void)
}
-static void err_doit (int, const char *, va_list);
-
-char *pname = NULL; /* caller can set this from argv[0] */
/* Fatal error related to a system call.
* Print a message and die. */
-void
-err_sys (const char *fmt, ...)
-{
- va_list ap;
-
- va_start (ap, fmt);
- err_doit (1, fmt, ap);
- va_end (ap);
- exit (1);
-}
-
-/* Print a message and return to caller.
- * Caller specifies "errnoflag". */
-
#define MAXLINE 2048
static void
-err_doit (int errnoflag, const char *fmt, va_list ap)
+err_sys (const char *fmt, ...)
{
+ int errnoflag = 1;
int errno_save;
char buf[MAXLINE];
+ va_list ap;
+
+ va_start (ap, fmt);
+ /* err_doit (1, fmt, ap); */
errno_save = errno; /* value caller might want printed */
vsprintf (buf, fmt, ap);
if (errnoflag)
@@ -295,7 +288,8 @@ err_doit (int errnoflag, const char *fmt, va_list ap)
fflush (stdout); /* in case stdout and stderr are the same */
fputs (buf, stderr);
fflush (NULL); /* flushes all stdio output streams */
- return;
+ va_end (ap);
+ exit (1);
}
char *
@@ -313,3 +307,4 @@ rtrim (char *str, const char *tok)
}
return str;
}
+
diff --git a/plugins/utils.c b/plugins/utils.c
index aed03c4e..c2261dc3 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -54,7 +54,7 @@ max_state (int a, int b)
void usage (char *msg)
{
- printf (msg);
+ printf ("%s", msg);
print_usage ();
exit (STATE_UNKNOWN);
}
diff --git a/plugins/utils.h b/plugins/utils.h
index a852e86a..c378e459 100644
--- a/plugins/utils.h
+++ b/plugins/utils.h
@@ -16,7 +16,7 @@ suite of plugins. */
void support (void);
char *clean_revstring (const char *revstring);
void print_revision (const char *, const char *);
-void die (int result, const char *fmt, ...) __attribute__((noreturn));
+void die (int result, const char *fmt, ...) __attribute__((noreturn,format(printf, 2, 3)));
/* Handle timeouts */