New upstream version 2.3

This commit is contained in:
Jan Wagner 2020-12-10 21:00:09 +01:00
parent c845af032a
commit 5c6ba24b61
129 changed files with 14313 additions and 2999 deletions

View file

@ -39,9 +39,9 @@
*****************************************************************************/
#include "common.h"
#include "utils.h"
/* extern so plugin has pid to kill exec'd process on timeouts */
extern int timeout_interval;
extern pid_t *childpid;
extern int *child_stderr_array;
extern FILE *child_process;
@ -76,18 +76,9 @@ RETSIGTYPE popen_timeout_alarm_handler (int);
#define SIG_ERR ((Sigfunc *)-1)
#endif
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))
int open_max (void); /* {Prog openmax} */
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} */
#ifdef REDHAT_SPOPEN_ERROR
static volatile int childtermd = 0;
#endif
@ -186,14 +177,15 @@ spopen (const char *cmdstring)
}
argv[i] = NULL;
if(maxfd == 0)
maxfd = open_max();
if (childpid == NULL) { /* first time through */
maxfd = open_max (); /* allocate zeroed out array for child pids */
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 ((size_t)maxfd, sizeof (int))) == NULL)
return (NULL);
}
@ -273,15 +265,6 @@ spclose (FILE * fp)
return (1);
}
#ifdef OPEN_MAX
static int openmax = OPEN_MAX;
#else
static int openmax = 0;
#endif
#define OPEN_MAX_GUESS 256 /* if OPEN_MAX is indeterminate */
/* no guarantee this is adequate */
#ifdef REDHAT_SPOPEN_ERROR
RETSIGTYPE
popen_sigchld_handler (int signo)
@ -309,63 +292,3 @@ popen_timeout_alarm_handler (int signo)
exit (STATE_CRITICAL);
}
}
int
open_max (void)
{
if (openmax == 0) { /* first time through */
errno = 0;
if ((openmax = sysconf (_SC_OPEN_MAX)) < 0) {
if (errno == 0)
openmax = OPEN_MAX_GUESS; /* it's indeterminate */
else
err_sys (_("sysconf error for _SC_OPEN_MAX"));
}
}
return (openmax);
}
/* Fatal error related to a system call.
* Print a message and die. */
#define MAXLINE 2048
static void
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)
sprintf (buf + strlen (buf), ": %s", strerror (errno_save));
strcat (buf, "\n");
fflush (stdout); /* in case stdout and stderr are the same */
fputs (buf, stderr);
fflush (NULL); /* flushes all stdio output streams */
va_end (ap);
exit (1);
}
char *
rtrim (char *str, const char *tok)
{
int i = 0;
int j = sizeof (str);
while (str != NULL && i < j) {
if (*(str + i) == *tok) {
sprintf (str + i, "%s", "\0");
return str;
}
i++;
}
return str;
}