diff --git a/tests/ibus_live_test.c b/tests/ibus_live_test.c index b94f03e..016c438 100644 --- a/tests/ibus_live_test.c +++ b/tests/ibus_live_test.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -228,7 +229,8 @@ static int startdaemon(Daemon *d, char *program, char *mapdir) { char missing[384]; - int notifyfd, watch, errpipe[2]; + int fd, notifyfd, watch, errpipe[2]; + long maxfd; pid_t pid; memset(d, 0, sizeof *d); @@ -281,6 +283,13 @@ startdaemon(Daemon *d, char *program, char *mapdir) dup2(errpipe[1], STDERR_FILENO) < 0) _exit(126); close(errpipe[1]); + if(close_range(3, UINT_MAX, 0) < 0){ + maxfd = sysconf(_SC_OPEN_MAX); + if(maxfd < 0) + maxfd = 1024; + for(fd = 3; fd < maxfd; fd++) + close(fd); + } if(setenv("XDG_RUNTIME_DIR", d->runtime, 1) < 0 || setenv("XDG_CONFIG_HOME", d->config, 1) < 0 || setenv("HOME", d->home, 1) < 0 || unsetenv("DISPLAY") < 0 || diff --git a/tests/ipc_live_test.c b/tests/ipc_live_test.c index fbff67f..662819a 100644 --- a/tests/ipc_live_test.c +++ b/tests/ipc_live_test.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -174,7 +175,8 @@ static int startdaemon(Daemon *d, char *program, char *mapdir) { char missing[384]; - int notifyfd, watch, errpipe[2]; + int fd, notifyfd, watch, errpipe[2]; + long maxfd; pid_t pid; memset(d, 0, sizeof *d); @@ -228,6 +230,13 @@ startdaemon(Daemon *d, char *program, char *mapdir) dup2(errpipe[1], STDERR_FILENO) < 0) _exit(126); close(errpipe[1]); + if(close_range(3, UINT_MAX, 0) < 0){ + maxfd = sysconf(_SC_OPEN_MAX); + if(maxfd < 0) + maxfd = 1024; + for(fd = 3; fd < maxfd; fd++) + close(fd); + } if(setenv("XDG_RUNTIME_DIR", d->runtime, 1) < 0 || setenv("XDG_CONFIG_HOME", d->config, 1) < 0 || setenv("HOME", d->home, 1) < 0 || unsetenv("DISPLAY") < 0 ||