Skip to content

Commit

Permalink
sysutils/rsyslog8: patch for forking issue due to close_range() call
Browse files Browse the repository at this point in the history
Add patch from upstream:

rsyslog/rsyslog@599b5c7

After fork if the child process uses close_range to close open file
descriptors it has no way to exempt the parentPipeFD causing a failure
to signal successful startup to the parent process. This causes
failures on all systems that aren't Linux that implement close_range.

1. Loop through file descriptors between beginClose and
   MAX(parentPipeFD,dbgGetDbglogFd()) making sure not to close those two
   file descriptors.

2. Potentially use close_range to close all file descriptors above
   MAX(parentPipeFD,dbgGetDbglogFd())

PR:	        274509
Reported by:	Helmut Ritter
Obtained from:	rsyslog/rsyslog#5254
  • Loading branch information
nhuff authored and infracaninophile committed Oct 24, 2023
1 parent 14dfdd5 commit 959521f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
4 changes: 1 addition & 3 deletions sysutils/rsyslog8/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
PORTNAME= rsyslog
PORTVERSION= 8.2310.0
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= sysutils
MASTER_SITES= http://www.rsyslog.com/files/download/rsyslog/

MAINTAINER= matthew@FreeBSD.org
COMMENT= Syslogd supporting SQL, TCP, and TLS
WWW= https://www.rsyslog.com/

BROKEN= "Socket operation on non-socket" See PR 274509

LICENSE= GPLv3 LGPL3 APACHE20
LICENSE_COMB= multi

Expand Down
36 changes: 36 additions & 0 deletions sysutils/rsyslog8/files/patch-tools_rsyslogd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--- tools/rsyslogd.c.orig 2023-10-09 07:12:48 UTC
+++ tools/rsyslogd.c
@@ -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();

0 comments on commit 959521f

Please sign in to comment.