Skip to content

Commit

Permalink
Merge pull request #5254 from nhuff/freebsd
Browse files Browse the repository at this point in the history
Fix forking issue do to close_range call
  • Loading branch information
rgerhards committed Oct 24, 2023
2 parents 4398263 + 73d2d71 commit 599b5c7
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tools/rsyslogd.c
Expand Up @@ -460,19 +460,24 @@ prepareBackground(const int parentPipeFD)
/* try MacOS, FreeBSD */
if(close_unneeded_open_files("/proc/fd", beginClose, parentPipeFD) != 0) {
/* did not work out, so let's close everything... */
const int endClose = getdtablesize();
# if defined(HAVE_CLOSE_RANGE)
if(close_range(beginClose, endClose, 0) != 0) {
int endClose = (parentPipeFD > dbgGetDbglogFd()) ? parentPipeFD : dbgGetDbglogFd();
for(int i = beginClose ; i <= endClose ; ++i) {
if((i != dbgGetDbglogFd()) && (i != parentPipeFD)) {
aix_close_it(i); /* AIXPORT */
}
}
beginClose = endClose + 1;
endClose = getdtablesize();
#if defined(HAVE_CLOSE_RANGE)
if(close_range(beginClose, endClose, 0) !=0) {
dbgprintf("errno %d after close_range(), fallback to loop\n", errno);
# endif
#endif
for(int i = beginClose ; i <= endClose ; ++i) {
if((i != dbgGetDbglogFd()) && (i != parentPipeFD)) {
aix_close_it(i); /* AIXPORT */
}
aix_close_it(i); /* AIXPORT */
}
# if defined(HAVE_CLOSE_RANGE)
#if defined(HAVE_CLOSE_RANGE)
}
# endif
#endif
}
}
seedRandomNumberForChild();
Expand Down

0 comments on commit 599b5c7

Please sign in to comment.