diff options
Diffstat (limited to 'plugins/popen.c')
| -rw-r--r-- | plugins/popen.c | 41 |
1 files changed, 18 insertions, 23 deletions
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); | |||
| 57 | #define min(a,b) ((a) < (b) ? (a) : (b)) | 57 | #define min(a,b) ((a) < (b) ? (a) : (b)) |
| 58 | #define max(a,b) ((a) > (b) ? (a) : (b)) | 58 | #define max(a,b) ((a) > (b) ? (a) : (b)) |
| 59 | int open_max (void); /* {Prog openmax} */ | 59 | int open_max (void); /* {Prog openmax} */ |
| 60 | void err_sys (const char *, ...); | 60 | static void err_sys (const char *, ...) __attribute__((noreturn,format(printf, 1, 2))); |
| 61 | char *rtrim (char *, const char *); | 61 | char *rtrim (char *, const char *); |
| 62 | 62 | ||
| 63 | char *pname = NULL; /* caller can set this from argv[0] */ | ||
| 64 | |||
| 63 | /*int *childerr = NULL;*//* ptr to array allocated at run-time */ | 65 | /*int *childerr = NULL;*//* ptr to array allocated at run-time */ |
| 64 | /*extern pid_t *childpid = NULL; *//* ptr to array allocated at run-time */ | 66 | /*extern pid_t *childpid = NULL; *//* ptr to array allocated at run-time */ |
| 65 | static int maxfd; /* from our open_max(), {Prog openmax} */ | 67 | static int maxfd; /* from our open_max(), {Prog openmax} */ |
| @@ -67,7 +69,7 @@ static int maxfd; /* from our open_max(), {Prog openmax} */ | |||
| 67 | FILE * | 69 | FILE * |
| 68 | spopen (const char *cmdstring) | 70 | spopen (const char *cmdstring) |
| 69 | { | 71 | { |
| 70 | char *env[] = { "LC_ALL=C", (char*)0 }; | 72 | char *env[2]; |
| 71 | char *cmd = NULL; | 73 | char *cmd = NULL; |
| 72 | char **argv = NULL; | 74 | char **argv = NULL; |
| 73 | char *str; | 75 | char *str; |
| @@ -84,6 +86,9 @@ spopen (const char *cmdstring) | |||
| 84 | setrlimit (RLIMIT_CORE, &limit); | 86 | setrlimit (RLIMIT_CORE, &limit); |
| 85 | #endif | 87 | #endif |
| 86 | 88 | ||
| 89 | env[0] = strdup("LC_ALL=C"); | ||
| 90 | env[1] = '\0'; | ||
| 91 | |||
| 87 | /* if no command was passed, return with no error */ | 92 | /* if no command was passed, return with no error */ |
| 88 | if (cmdstring == NULL) | 93 | if (cmdstring == NULL) |
| 89 | return (NULL); | 94 | return (NULL); |
| @@ -148,13 +153,13 @@ spopen (const char *cmdstring) | |||
| 148 | 153 | ||
| 149 | if (childpid == NULL) { /* first time through */ | 154 | if (childpid == NULL) { /* first time through */ |
| 150 | maxfd = open_max (); /* allocate zeroed out array for child pids */ | 155 | maxfd = open_max (); /* allocate zeroed out array for child pids */ |
| 151 | if ((childpid = calloc (maxfd, sizeof (pid_t))) == NULL) | 156 | if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL) |
| 152 | return (NULL); | 157 | return (NULL); |
| 153 | } | 158 | } |
| 154 | 159 | ||
| 155 | if (child_stderr_array == NULL) { /* first time through */ | 160 | if (child_stderr_array == NULL) { /* first time through */ |
| 156 | maxfd = open_max (); /* allocate zeroed out array for child pids */ | 161 | maxfd = open_max (); /* allocate zeroed out array for child pids */ |
| 157 | if ((child_stderr_array = calloc (maxfd, sizeof (int))) == NULL) | 162 | if ((child_stderr_array = calloc ((size_t)maxfd, sizeof (int))) == NULL) |
| 158 | return (NULL); | 163 | return (NULL); |
| 159 | } | 164 | } |
| 160 | 165 | ||
| @@ -259,34 +264,22 @@ open_max (void) | |||
| 259 | } | 264 | } |
| 260 | 265 | ||
| 261 | 266 | ||
| 262 | static void err_doit (int, const char *, va_list); | ||
| 263 | |||
| 264 | char *pname = NULL; /* caller can set this from argv[0] */ | ||
| 265 | 267 | ||
| 266 | /* Fatal error related to a system call. | 268 | /* Fatal error related to a system call. |
| 267 | * Print a message and die. */ | 269 | * Print a message and die. */ |
| 268 | 270 | ||
| 269 | void | ||
| 270 | err_sys (const char *fmt, ...) | ||
| 271 | { | ||
| 272 | va_list ap; | ||
| 273 | |||
| 274 | va_start (ap, fmt); | ||
| 275 | err_doit (1, fmt, ap); | ||
| 276 | va_end (ap); | ||
| 277 | exit (1); | ||
| 278 | } | ||
| 279 | |||
| 280 | /* Print a message and return to caller. | ||
| 281 | * Caller specifies "errnoflag". */ | ||
| 282 | |||
| 283 | #define MAXLINE 2048 | 271 | #define MAXLINE 2048 |
| 284 | static void | 272 | static void |
| 285 | err_doit (int errnoflag, const char *fmt, va_list ap) | 273 | err_sys (const char *fmt, ...) |
| 286 | { | 274 | { |
| 275 | int errnoflag = 1; | ||
| 287 | int errno_save; | 276 | int errno_save; |
| 288 | char buf[MAXLINE]; | 277 | char buf[MAXLINE]; |
| 289 | 278 | ||
| 279 | va_list ap; | ||
| 280 | |||
| 281 | va_start (ap, fmt); | ||
| 282 | /* err_doit (1, fmt, ap); */ | ||
| 290 | errno_save = errno; /* value caller might want printed */ | 283 | errno_save = errno; /* value caller might want printed */ |
| 291 | vsprintf (buf, fmt, ap); | 284 | vsprintf (buf, fmt, ap); |
| 292 | if (errnoflag) | 285 | if (errnoflag) |
| @@ -295,7 +288,8 @@ err_doit (int errnoflag, const char *fmt, va_list ap) | |||
| 295 | fflush (stdout); /* in case stdout and stderr are the same */ | 288 | fflush (stdout); /* in case stdout and stderr are the same */ |
| 296 | fputs (buf, stderr); | 289 | fputs (buf, stderr); |
| 297 | fflush (NULL); /* flushes all stdio output streams */ | 290 | fflush (NULL); /* flushes all stdio output streams */ |
| 298 | return; | 291 | va_end (ap); |
| 292 | exit (1); | ||
| 299 | } | 293 | } |
| 300 | 294 | ||
| 301 | char * | 295 | char * |
| @@ -313,3 +307,4 @@ rtrim (char *str, const char *tok) | |||
| 313 | } | 307 | } |
| 314 | return str; | 308 | return str; |
| 315 | } | 309 | } |
| 310 | |||
