open_max is a library function now, it should be mp_open_max

This commit is contained in:
RincewindsHat 2023-09-23 10:33:06 +02:00
parent bef0d0dd4a
commit 4295decfbf
5 changed files with 11 additions and 11 deletions

View file

@ -1,7 +1,7 @@
#include "./maxfd.h"
#include <errno.h>
long open_max (void) {
long mp_open_max (void) {
long maxfd = 0L;
/* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX.
* If that fails and the macro isn't defined, we fall back to an educated

View file

@ -4,6 +4,6 @@
#define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */
#define MAXFD_LIMIT 8192 /* upper limit of open files */
long open_max (void);
long mp_open_max (void);
#endif // _MAXFD_

View file

@ -89,7 +89,7 @@ extern void die (int, const char *, ...)
void
cmd_init (void)
{
long maxfd = open_max();
long maxfd = mp_open_max();
/* if maxfd is unnaturally high, we force it to a lower value
* ( e.g. on SunOS, when ulimit is set to unlimited: 2147483647 this would cause
@ -145,7 +145,7 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr)
/* close all descriptors in _cmd_pids[]
* This is executed in a separate address space (pure child),
* so we don't have to worry about async safety */
long maxfd = open_max();
long maxfd = mp_open_max();
for (i = 0; i < maxfd; i++)
if (_cmd_pids[i] > 0)
close (i);
@ -172,7 +172,7 @@ _cmd_close (int fd)
pid_t pid;
/* make sure the provided fd was opened */
long maxfd = open_max();
long maxfd = mp_open_max();
if (fd < 0 || fd > maxfd || !_cmd_pids || (pid = _cmd_pids[fd]) == 0)
return -1;
@ -385,7 +385,7 @@ timeout_alarm_handler (int signo)
printf (_("%s - Plugin timed out after %d seconds\n"),
state_text(timeout_state), timeout_interval);
long maxfd = open_max();
long maxfd = mp_open_max();
if(_cmd_pids) for(i = 0; i < maxfd; i++) {
if(_cmd_pids[i] != 0) kill(_cmd_pids[i], SIGKILL);
}

View file

@ -178,7 +178,7 @@ spopen (const char *cmdstring)
}
argv[i] = NULL;
long maxfd = open_max();
long maxfd = mp_open_max();
if (childpid == NULL) { /* first time through */
if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL)

View file

@ -88,7 +88,7 @@ extern void die (int, const char *, ...)
* through this api and thus achieve async-safeness throughout the api */
void np_runcmd_init(void)
{
long maxfd = open_max();
long maxfd = mp_open_max();
if(!np_pids) np_pids = calloc(maxfd, sizeof(pid_t));
}
@ -191,7 +191,7 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr)
/* close all descriptors in np_pids[]
* This is executed in a separate address space (pure child),
* so we don't have to worry about async safety */
long maxfd = open_max();
long maxfd = mp_open_max();
for (i = 0; i < maxfd; i++)
if(np_pids[i] > 0)
close (i);
@ -219,7 +219,7 @@ np_runcmd_close(int fd)
pid_t pid;
/* make sure this fd was opened by popen() */
long maxfd = open_max();
long maxfd = mp_open_max();
if(fd < 0 || fd > maxfd || !np_pids || (pid = np_pids[fd]) == 0)
return -1;
@ -243,7 +243,7 @@ runcmd_timeout_alarm_handler (int signo)
if (signo == SIGALRM)
puts(_("CRITICAL - Plugin timed out while executing system call"));
long maxfd = open_max();
long maxfd = mp_open_max();
if(np_pids) for(i = 0; i < maxfd; i++) {
if(np_pids[i] != 0) kill(np_pids[i], SIGKILL);
}