aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/utils.c b/src/utils.c
index 41fc7d4..0959cee 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -125,10 +125,12 @@ int close_fds_except(int fds, ...)
max_fd = sysconf(_SC_OPEN_MAX) - 1;
if (max_fd <= 0)
return 1;
+ if (fds < 0)
+ return 1;
va_start(ap, fds);
{
- int *all_fds = malloc(max_fd * sizeof(*all_fds));
+ int *all_fds = (int *) malloc((max_fd+1) * sizeof(*all_fds));
assert(all_fds);
memset(all_fds, -1, max_fd * sizeof(*all_fds));
@@ -136,6 +138,7 @@ int close_fds_except(int fds, ...)
while ( (fd = va_arg(ap, int)) >= 0 ) {
all_fds[except_count++] = fd;
}
+ all_fds[except_count++] = fds;
for (fd = max_fd; fd >= 0; --fd) {
found = 0;
@@ -164,7 +167,8 @@ int redirect_devnull_to(int fds, ...)
null_fd = open("/dev/null", O_RDWR);
if (null_fd < 0)
return -1;
- assert(null_fd >= 0);
+ if (fds < -1)
+ return -1;
va_start(ap, fds);
{