diff options
Diffstat (limited to 'plugins/popen.c')
-rw-r--r-- | plugins/popen.c | 52 |
1 files changed, 3 insertions, 49 deletions
diff --git a/plugins/popen.c b/plugins/popen.c index 116d168d..557fb44e 100644 --- a/plugins/popen.c +++ b/plugins/popen.c | |||
@@ -78,14 +78,9 @@ RETSIGTYPE popen_timeout_alarm_handler (int); | |||
78 | 78 | ||
79 | #define min(a,b) ((a) < (b) ? (a) : (b)) | 79 | #define min(a,b) ((a) < (b) ? (a) : (b)) |
80 | #define max(a,b) ((a) > (b) ? (a) : (b)) | 80 | #define max(a,b) ((a) > (b) ? (a) : (b)) |
81 | static void err_sys (const char *, ...) __attribute__((noreturn,format(printf, 1, 2))); | ||
82 | char *rtrim (char *, const char *); | ||
83 | 81 | ||
84 | char *pname = NULL; /* caller can set this from argv[0] */ | 82 | char *pname = NULL; /* caller can set this from argv[0] */ |
85 | 83 | ||
86 | /*int *childerr = NULL;*//* ptr to array allocated at run-time */ | ||
87 | /*extern pid_t *childpid = NULL; *//* ptr to array allocated at run-time */ | ||
88 | |||
89 | #ifdef REDHAT_SPOPEN_ERROR | 84 | #ifdef REDHAT_SPOPEN_ERROR |
90 | static volatile int childtermd = 0; | 85 | static volatile int childtermd = 0; |
91 | #endif | 86 | #endif |
@@ -184,6 +179,9 @@ spopen (const char *cmdstring) | |||
184 | } | 179 | } |
185 | argv[i] = NULL; | 180 | argv[i] = NULL; |
186 | 181 | ||
182 | if(maxfd == 0) | ||
183 | maxfd = open_max(); | ||
184 | |||
187 | if (childpid == NULL) { /* first time through */ | 185 | if (childpid == NULL) { /* first time through */ |
188 | if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL) | 186 | if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL) |
189 | return (NULL); | 187 | return (NULL); |
@@ -296,47 +294,3 @@ popen_timeout_alarm_handler (int signo) | |||
296 | exit (STATE_CRITICAL); | 294 | exit (STATE_CRITICAL); |
297 | } | 295 | } |
298 | } | 296 | } |
299 | |||
300 | |||
301 | /* Fatal error related to a system call. | ||
302 | * Print a message and die. */ | ||
303 | |||
304 | #define MAXLINE 2048 | ||
305 | static void | ||
306 | err_sys (const char *fmt, ...) | ||
307 | { | ||
308 | int errnoflag = 1; | ||
309 | int errno_save; | ||
310 | char buf[MAXLINE]; | ||
311 | |||
312 | va_list ap; | ||
313 | |||
314 | va_start (ap, fmt); | ||
315 | /* err_doit (1, fmt, ap); */ | ||
316 | errno_save = errno; /* value caller might want printed */ | ||
317 | vsprintf (buf, fmt, ap); | ||
318 | if (errnoflag) | ||
319 | sprintf (buf + strlen (buf), ": %s", strerror (errno_save)); | ||
320 | strcat (buf, "\n"); | ||
321 | fflush (stdout); /* in case stdout and stderr are the same */ | ||
322 | fputs (buf, stderr); | ||
323 | fflush (NULL); /* flushes all stdio output streams */ | ||
324 | va_end (ap); | ||
325 | exit (1); | ||
326 | } | ||
327 | |||
328 | char * | ||
329 | rtrim (char *str, const char *tok) | ||
330 | { | ||
331 | int i = 0; | ||
332 | int j = sizeof (str); | ||
333 | |||
334 | while (str != NULL && i < j) { | ||
335 | if (*(str + i) == *tok) { | ||
336 | sprintf (str + i, "%s", "\0"); | ||
337 | return str; | ||
338 | } | ||
339 | i++; | ||
340 | } | ||
341 | return str; | ||
342 | } | ||