Code

fix a variety of compiler warnings about qualifier discards and other pedantic stuff
[nagiosplug.git] / plugins / popen.c
index cde3c7647465ca26e7effd9cae8617a27bf86780..fb855d7bbb134641c6195005162524ac4983778f 100644 (file)
@@ -67,7 +67,7 @@ static int maxfd;                                                             /* from our open_max(), {Prog openmax} */
 FILE *
 spopen (const char *cmdstring)
 {
-       char *environ[] = { NULL };
+       char *env[] = { "LC_ALL=C", (char*)0 };
        char *cmd = NULL;
        char **argv = NULL;
        char *str;
@@ -182,7 +182,7 @@ spopen (const char *cmdstring)
                        if (childpid[i] > 0)
                                close (i);
 
-               execve (argv[0], argv, environ);
+               execve (argv[0], argv, env);
                _exit (0);
        }
 
@@ -199,28 +199,28 @@ spopen (const char *cmdstring)
 int
 spclose (FILE * fp)
 {
-       int fd, stat;
+       int fd, status;
        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)
-               return (-1);                                                            /* fp wasn't opened by popen() */
+               return (1);                                                             /* fp wasn't opened by popen() */
 
        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)
-                       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
@@ -264,7 +264,7 @@ 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 terminate. */
+ * Print a message and die. */
 
 void
 err_sys (const char *fmt, ...)
@@ -302,8 +302,9 @@ char *
 rtrim (char *str, const char *tok)
 {
        int i = 0;
+       int j = sizeof (str);
 
-       while (str != NULL) {
+       while (str != NULL && i < j) {
                if (*(str + i) == *tok) {
                        sprintf (str + i, "%s", "\0");
                        return str;