diff --git a/plugins/popen.c b/plugins/popen.c
index d056904dcd88dcc36225291024c227521888f5e4..04eb3881b328fa0e0938a5b93295f661231119db 100644 (file)
--- a/plugins/popen.c
+++ b/plugins/popen.c
* path passed to the exec'd program are esstially empty. (popen create a shell
* and passes the environment to it).
*
* path passed to the exec'd program are esstially empty. (popen create a shell
* and passes the environment to it).
*
+ * $Id$
+ *
******************************************************************************/
******************************************************************************/
-#include <config.h>
-#include <common.h>
+#include "common.h"
/* extern so plugin has pid to kill exec'd process on timeouts */
extern int timeout_interval;
/* extern so plugin has pid to kill exec'd process on timeouts */
extern int timeout_interval;
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))
int open_max (void); /* {Prog openmax} */
#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 *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} */
/*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} */
FILE *
spopen (const char *cmdstring)
{
FILE *
spopen (const char *cmdstring)
{
- char *environ[] = { NULL };
+ char *env[2];
char *cmd = NULL;
char **argv = NULL;
char *str;
char *cmd = NULL;
char **argv = NULL;
char *str;
setrlimit (RLIMIT_CORE, &limit);
#endif
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);
/* if no command was passed, return with no error */
if (cmdstring == NULL)
return (NULL);
/* there cannot be more args than characters */
argc = strlen (cmdstring) + 1; /* add 1 for NULL termination */
argv = malloc (sizeof(char*)*argc);
/* there cannot be more args than characters */
argc = strlen (cmdstring) + 1; /* add 1 for NULL termination */
argv = malloc (sizeof(char*)*argc);
+
if (argv == NULL) {
if (argv == NULL) {
- printf ("Could not malloc argv array in popen()\n");
+ printf (_("Could not malloc argv array in popen()\n"));
return NULL;
}
return NULL;
}
str += strspn (str, " \t\r\n"); /* trim any leading whitespace */
if (i >= argc - 2) {
str += strspn (str, " \t\r\n"); /* trim any leading whitespace */
if (i >= argc - 2) {
- printf ("You've got a big problem buddy! You need more args!!!\n");
+ printf (_("CRITICAL - You need more args!!!\n"));
return (NULL);
}
return (NULL);
}
if (childpid == NULL) { /* first time through */
maxfd = open_max (); /* allocate zeroed out array for child pids */
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 */
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);
}
return (NULL);
}
if (childpid[i] > 0)
close (i);
if (childpid[i] > 0)
close (i);
- execve (argv[0], argv, environ);
+ execve (argv[0], argv, env);
_exit (0);
}
_exit (0);
}
int
spclose (FILE * fp)
{
int
spclose (FILE * fp)
{
- int fd, stat;
+ int fd, status;
pid_t pid;
if (childpid == NULL)
pid_t pid;
if (childpid == NULL)
- return (-1); /* popen() has never been called */
+ return (1); /* popen() has never been called */
fd = fileno (fp);
if ((pid = childpid[fd]) == 0)
fd = fileno (fp);
if ((pid = childpid[fd]) == 0)
- return (-1); /* fp wasn't opened by popen() */
+ return (1); /* fp wasn't opened by popen() */
childpid[fd] = 0;
if (fclose (fp) == EOF)
childpid[fd] = 0;
if (fclose (fp) == EOF)
- return (-1);
+ return (1);
- while (waitpid (pid, &stat, 0) < 0)
+ while (waitpid (pid, &status, 0) < 0)
if (errno != EINTR)
if (errno != EINTR)
- return (-1); /* error other than EINTR from waitpid() */
+ return (1); /* error other than EINTR from waitpid() */
- if (WIFEXITED (stat))
- return (WEXITSTATUS (stat)); /* return child's termination status */
+ if (WIFEXITED (status))
+ return (WEXITSTATUS (status)); /* return child's termination status */
- return (STATE_UNKNOWN);
+ return (1);
}
#ifdef OPEN_MAX
}
#ifdef OPEN_MAX
#define OPEN_MAX_GUESS 256 /* if OPEN_MAX is indeterminate */
/* no guarantee this is adequate */
#define OPEN_MAX_GUESS 256 /* if OPEN_MAX is indeterminate */
/* no guarantee this is adequate */
+
void
popen_timeout_alarm_handler (int signo)
{
if (signo == SIGALRM) {
kill (childpid[fileno (child_process)], SIGKILL);
void
popen_timeout_alarm_handler (int signo)
{
if (signo == SIGALRM) {
kill (childpid[fileno (child_process)], SIGKILL);
- printf ("CRITICAL - Plugin timed out after %d seconds\n",
+ printf (_("CRITICAL - Plugin timed out after %d seconds\n"),
timeout_interval);
exit (STATE_CRITICAL);
}
}
timeout_interval);
exit (STATE_CRITICAL);
}
}
+
int
open_max (void)
{
int
open_max (void)
{
if (errno == 0)
openmax = OPEN_MAX_GUESS; /* it's indeterminate */
else
if (errno == 0)
openmax = OPEN_MAX_GUESS; /* it's indeterminate */
else
- err_sys ("sysconf error for _SC_OPEN_MAX");
+ err_sys (_("sysconf error for _SC_OPEN_MAX"));
}
}
return (openmax);
}
}
}
return (openmax);
}
-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.
/* Fatal error related to a system call.
- * Print a message and terminate. */
-
-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". */
+ * Print a message and die. */
#define MAXLINE 2048
static void
#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];
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)
errno_save = errno; /* value caller might want printed */
vsprintf (buf, fmt, ap);
if (errnoflag)
fflush (stdout); /* in case stdout and stderr are the same */
fputs (buf, stderr);
fflush (NULL); /* flushes all stdio output streams */
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 *
}
char *