[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Fri Aug 1 16:37:04 MDT 2014


The branch, master has been updated
       via  811e0e6 lib: Make DEBUG a subsystem of its own
       via  a7c243b lib: Make close_low_fd() independently linkable
       via  4ac12fb debug: Use close_low_fd in reopen_logs_internal
       via  b310ea6 lib: Use close_low_fd in close_low_fds
       via  2dd8b6b lib: Add close_low_fd
      from  9b24abe fix unstrcpy

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 811e0e6f9962adbf0d12448044f17542b92ad15e
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Jul 30 14:12:54 2014 +0000

    lib: Make DEBUG a subsystem of its own
    
    In the future this might become a library, but even with the SUBSYSTEM
    it should be clear what debug.c depends upon.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Sat Aug  2 00:36:50 CEST 2014 on sn-devel-104

commit a7c243b62c6eaaca317fefa41e12a44b664c12ac
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Jul 31 09:40:04 2014 +0000

    lib: Make close_low_fd() independently linkable
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 4ac12fb2f7b0c949448d38feb0e6dbdb1b928993
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 20:43:05 2014 +0200

    debug: Use close_low_fd in reopen_logs_internal
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b310ea63536dd81fee6c5c94dac4666aa7080f1f
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 20:42:18 2014 +0200

    lib: Use close_low_fd in close_low_fds
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2dd8b6b25c76bd426ea0ed9fa9cce6cc09297503
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 29 20:35:10 2014 +0200

    lib: Add close_low_fd
    
    This factors out the essential code from close_low_fds for one file
    descriptor: Redirect a fd to /dev/null
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/util/become_daemon.c                           |   51 ++++++----------
 lib/util/close_low_fd.c                            |   65 ++++++++++++++++++++
 .../srv_epmapper.h => lib/util/close_low_fd.h      |   22 +++----
 lib/util/debug.c                                   |    3 +-
 lib/util/samba_util.h                              |    2 -
 lib/util/wscript_build                             |   14 ++++-
 6 files changed, 106 insertions(+), 51 deletions(-)
 create mode 100644 lib/util/close_low_fd.c
 copy source3/rpc_server/epmapper/srv_epmapper.h => lib/util/close_low_fd.h (64%)


Changeset truncated at 500 lines:

diff --git a/lib/util/become_daemon.c b/lib/util/become_daemon.c
index 0671a1e..17e0baf 100644
--- a/lib/util/become_daemon.c
+++ b/lib/util/become_daemon.c
@@ -27,6 +27,7 @@
 #if HAVE_SYSTEMD
 #include <systemd/sd-daemon.h>
 #endif
+#include "lib/util/close_low_fd.h"
 
 /*******************************************************************
  Close the low 3 fd's and open dev/null in their place.
@@ -34,42 +35,28 @@
 
 _PUBLIC_ void close_low_fds(bool stdin_too, bool stdout_too, bool stderr_too)
 {
-#ifndef VALGRIND
-	int fd;
-	int i;
 
-	if (stdin_too)
-		close(0);
-	if (stdout_too)
-		close(1);
-
-	if (stderr_too)
-		close(2);
-
-	/* try and use up these file descriptors, so silly
-		library routines writing to stdout etc won't cause havoc */
-	for (i=0;i<3;i++) {
-		if (i == 0 && !stdin_too)
-			continue;
-		if (i == 1 && !stdout_too)
-			continue;
-		if (i == 2 && !stderr_too)
-			continue;
-
-		fd = open("/dev/null",O_RDWR,0);
-		if (fd < 0)
-			fd = open("/dev/null",O_WRONLY,0);
-		if (fd < 0) {
-			DEBUG(0,("Can't open /dev/null\n"));
-			return;
+	if (stdin_too) {
+		int ret = close_low_fd(0);
+		if (ret != 0) {
+			DEBUG(0, ("%s: close_low_fd(0) failed: %s\n",
+				  __func__, strerror(ret)));
 		}
-		if (fd != i) {
-			DEBUG(0,("Didn't get file descriptor %d\n",i));
-			close(fd);
-			return;
+	}
+	if (stdout_too) {
+		int ret = close_low_fd(1);
+		if (ret != 0) {
+			DEBUG(0, ("%s: close_low_fd(1) failed: %s\n",
+				  __func__, strerror(ret)));
+		}
+	}
+	if (stderr_too) {
+		int ret = close_low_fd(2);
+		if (ret != 0) {
+			DEBUG(0, ("%s: close_low_fd(2) failed: %s\n",
+				  __func__, strerror(ret)));
 		}
 	}
-#endif
 }
 
 /****************************************************************************
diff --git a/lib/util/close_low_fd.c b/lib/util/close_low_fd.c
new file mode 100644
index 0000000..b11d25f
--- /dev/null
+++ b/lib/util/close_low_fd.c
@@ -0,0 +1,65 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Samba utility functions
+ * Copyright (C) Volker Lendecke 2014
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "replace.h"
+#include "system/filesys.h"
+#include "close_low_fd.h"
+
+_PUBLIC_ int close_low_fd(int fd)
+{
+#ifndef VALGRIND
+	int ret, dev_null;
+
+	dev_null = open("/dev/null", O_RDWR, 0);
+
+	if ((dev_null == -1) && (errno = ENFILE)) {
+		/*
+		 * Try to free up an fd
+		 */
+		ret = close(fd);
+		if (ret != 0) {
+			return errno;
+		}
+	}
+
+	dev_null = open("/dev/null", O_RDWR, 0);
+	if (dev_null == -1) {
+		dev_null = open("/dev/null", O_WRONLY, 0);
+	}
+	if (dev_null == -1) {
+		return errno;
+	}
+
+	if (dev_null == fd) {
+		/*
+		 * This can happen in the ENFILE case above
+		 */
+		return 0;
+	}
+
+	ret = dup2(dev_null, fd);
+	if (ret == -1) {
+		int err = errno;
+		close(dev_null);
+		return err;
+	}
+	close(dev_null);
+#endif
+	return 0;
+}
diff --git a/source3/rpc_server/epmapper/srv_epmapper.h b/lib/util/close_low_fd.h
similarity index 64%
copy from source3/rpc_server/epmapper/srv_epmapper.h
copy to lib/util/close_low_fd.h
index 1abc583..954d1d2 100644
--- a/source3/rpc_server/epmapper/srv_epmapper.h
+++ b/lib/util/close_low_fd.h
@@ -1,9 +1,7 @@
 /*
  * Unix SMB/CIFS implementation.
- *
- * Endpoint server for the epmapper pipe
- *
- * Copyright (C) 2010-2011 Andreas Schneider <asn at samba.org>
+ * Samba utility functions
+ * Copyright (C) Volker Lendecke 2014
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,16 +17,12 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef _SRV_EPMAPPER_H_
-#define _SRV_EPMAPPER_H_
+#ifndef _CLOSE_LOW_FD_H
+#define _CLOSE_LOW_FD_H
 
-/**
- * @brief Cleanup memory and other stuff.
+/*
+ * Redirect "fd" to /dev/null
  */
-void srv_epmapper_cleanup(void);
-
-bool srv_epmapper_delete_endpoints(struct pipes_struct *p);
-
-#endif /*_SRV_EPMAPPER_H_ */
+int close_low_fd(int fd);
 
-/* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */
+#endif
diff --git a/lib/util/debug.c b/lib/util/debug.c
index 33cbed2..2779dd3 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -23,6 +23,7 @@
 #include "system/filesys.h"
 #include "system/syslog.h"
 #include "lib/util/time_basic.h"
+#include "lib/util/close_low_fd.h"
 
 /* define what facility to use for syslog */
 #ifndef SYSLOG_FACILITY
@@ -617,7 +618,7 @@ bool reopen_logs_internal(void)
 			   at the logfile.  There really isn't much
 			   that can be done on such a fundamental
 			   failure... */
-			close_low_fds(false, false, true);
+			close_low_fd(2);
 		}
 	}
 
diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h
index 2ffe028..233b5fd 100644
--- a/lib/util/samba_util.h
+++ b/lib/util/samba_util.h
@@ -836,8 +836,6 @@ _PUBLIC_ void *idr_find(struct idr_context *idp, int id);
 */
 _PUBLIC_ int idr_remove(struct idr_context *idp, int id);
 
-/* The following definitions come from lib/util/become_daemon.c  */
-
 /**
  Close the low 3 fd's and open dev/null in their place
 **/
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index 8be2c2e..7c4abf9 100755
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -5,16 +5,26 @@ bld.SAMBA_SUBSYSTEM('time-basic',
                     deps='replace',
                     local_include=False)
 
+bld.SAMBA_SUBSYSTEM('close-low-fd',
+                    source='close_low_fd.c',
+                    deps='replace',
+                    local_include=False)
+
+bld.SAMBA_SUBSYSTEM('samba-debug',
+                    source='debug.c',
+                    deps='replace time-basic close-low-fd talloc',
+                    local_include=False)
+
 bld.SAMBA_LIBRARY('samba-util',
                   source='''talloc_stack.c smb_threads.c xfile.c data_blob.c
                     util_file.c time.c rbtree.c rfc1738.c select.c getpass.c
                     genrand.c fsusage.c blocking.c become_daemon.c
                     signal.c system.c params.c util.c util_id.c util_net.c
-                    util_strlist.c util_paths.c idtree.c debug.c fault.c base64.c
+                    util_strlist.c util_paths.c idtree.c fault.c base64.c
                     util_str.c util_str_common.c substitute.c ms_fnmatch.c
                     server_id.c dprintf.c parmlist.c bitmap.c pidfile.c
                     tevent_debug.c util_process.c memcache.c''',
-                  deps='DYNCONFIG time-basic',
+                  deps='DYNCONFIG time-basic close-low-fd samba-debug',
                   public_deps='talloc tevent execinfo pthread LIBCRYPTO charset util_setid systemd-daemon',
                   public_headers='debug.h attr.h byteorder.h data_blob.h memory.h safe_string.h time.h talloc_stack.h xfile.h dlinklist.h samba_util.h string_wrappers.h',
                   header_path= [ ('dlinklist.h samba_util.h', '.'), ('*', 'util') ],


-- 
Samba Shared Repository


More information about the samba-cvs mailing list