debug: Set close-on-exec for the main log file FD
authorAndrew Bartlett <abartlet@samba.org>
Mon, 16 Feb 2015 02:59:11 +0000 (15:59 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 16 Feb 2015 10:42:47 +0000 (11:42 +0100)
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 <garming@catalyst.net.nz>
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Mon Feb 16 11:42:47 CET 2015 on sn-devel-104

lib/util/debug.c
lib/util/wscript_build

index a794c5b28deab9c57536479edad71afe308d693e..80a1c254d624cb6a00bd2e29ddffb106246ae817 100644 (file)
@@ -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);
@@ -735,6 +736,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 ));
@@ -791,6 +793,7 @@ static int Debug1(const char *msg)
                        if(fd == -1) {
                                goto done;
                        }
+                       smb_set_close_on_exec(fd);
                        state.fd = fd;
                }
        }
index a1dec2a093e127306e9cfa3fdd2fa310918ce3fc..3121e1ff5b2d70ddc0019ae9d6f4d7e20e0bc8cf 100755 (executable)
@@ -27,7 +27,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)