From: Andrew Bartlett Date: Mon, 16 Feb 2015 02:59:11 +0000 (+1300) Subject: debug: Set close-on-exec for the main log file FD X-Git-Tag: samba-4.2.0~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38d6d2047ce8be04c73e510cda54b80ff644018d;p=thirdparty%2Fsamba.git debug: Set close-on-exec for the main log file FD This does not change the properties of dup2() of the fd as STDERR, however this is closed before we start smbd or winbindd as child processes. This is needed otherwise the logfile remains open in the child process, and logfile rotation can mean this old log remains on disk indefinatly. BUG: https://bugzilla.samba.org/show_bug.cgi?id=11100 Pair-programmed-with: Garming Sam Signed-off-by: Garming Sam Signed-off-by: Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Mon Feb 16 11:42:47 CET 2015 on sn-devel-104 (cherry picked from commit 1d95b0afc3547a91f8558873ce58652c271ed9eb) --- diff --git a/lib/util/debug.c b/lib/util/debug.c index 00595957aa6..0c5e9729a0d 100644 --- a/lib/util/debug.c +++ b/lib/util/debug.c @@ -604,6 +604,7 @@ bool reopen_logs_internal(void) log_overflow = false; ret = false; } else { + smb_set_close_on_exec(new_fd); old_fd = state.fd; state.fd = new_fd; debug_close_fd(old_fd); @@ -737,6 +738,7 @@ void check_log_size( void ) */ int fd = open( "/dev/console", O_WRONLY, 0); if (fd != -1) { + smb_set_close_on_exec(fd); state.fd = fd; DEBUG(0,("check_log_size: open of debug file %s failed - using console.\n", state.debugf )); @@ -793,6 +795,7 @@ static int Debug1(const char *msg) if(fd == -1) { goto done; } + smb_set_close_on_exec(fd); state.fd = fd; } } diff --git a/lib/util/wscript_build b/lib/util/wscript_build index cd23231f3cc..5db7e35a729 100755 --- a/lib/util/wscript_build +++ b/lib/util/wscript_build @@ -22,7 +22,7 @@ bld.SAMBA_SUBSYSTEM('close-low-fd', bld.SAMBA_LIBRARY('samba-debug', source='debug.c', - deps='replace time-basic close-low-fd talloc', + deps='replace time-basic close-low-fd talloc socket-blocking', local_include=False, private_library=True)