[PATCH] Just another round of random cleanups

Volker Lendecke Volker.Lendecke at SerNet.DE
Wed Sep 17 14:48:20 MDT 2014


Hi!

Review&push would be appreciated.

Thanks,

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 8c0b881768856bcaa2a837375a26fdd2500116ec Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 16 Sep 2014 22:39:01 +0200
Subject: [PATCH 01/11] lib: Make set_blocking() available independently

async_connect_send() needs this, and I don't want to pull in samba-util
just for this

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/async_req/wscript_build |    2 +-
 lib/util/wscript_build      |    8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/async_req/wscript_build b/lib/async_req/wscript_build
index 0de58e4..7802935 100644
--- a/lib/async_req/wscript_build
+++ b/lib/async_req/wscript_build
@@ -4,6 +4,6 @@
 bld.SAMBA_SUBSYSTEM('LIBASYNC_REQ',
 	source='async_sock.c',
 	public_deps='talloc tevent',
-	deps='tevent-util'
+	deps='tevent-util socket-blocking'
 	)
 
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index c9487f2..0267ddc 100755
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -25,16 +25,20 @@ bld.SAMBA_SUBSYSTEM('samba-debug',
                     deps='replace time-basic close-low-fd talloc',
                     local_include=False)
 
+bld.SAMBA_SUBSYSTEM('socket-blocking',
+                    source='blocking.c',
+                    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
+                    genrand.c fsusage.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 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 close-low-fd samba-debug tini tiniparser',
+                  deps='DYNCONFIG time-basic close-low-fd samba-debug tini tiniparser socket-blocking',
                   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') ],
-- 
1.7.9.5


From ba92f5cc148b14e3ce21a9c78d4fb5c60e03550e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 16 Sep 2014 23:11:27 +0200
Subject: [PATCH 02/11] lib: Reduce deps for "smb_transport"

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 libcli/smb/wscript |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcli/smb/wscript b/libcli/smb/wscript
index 17efc97..e6556ce 100755
--- a/libcli/smb/wscript
+++ b/libcli/smb/wscript
@@ -6,8 +6,8 @@ def build(bld):
         source='''
             read_smb.c
         ''',
-        deps='errors LIBASYNC_REQ',
-        public_deps='talloc tevent samba-util',
+        deps='LIBASYNC_REQ',
+        public_deps='talloc tevent',
         private_library=True,
         public_headers='''
             read_smb.h
-- 
1.7.9.5


From 17303f087c4fd018cb97497679086b5ab48db98f Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 17 Sep 2014 00:25:38 +0200
Subject: [PATCH 03/11] Remove a few #ifdef EWOULDBLOCk

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/recvfile.c          |    8 --------
 source3/lib/sendfile.c          |   20 --------------------
 source3/lib/system.c            |   20 ++++----------------
 source3/lib/unix_msg/unix_msg.c |    6 ------
 source3/smbd/vfs.c              |    7 ++-----
 5 files changed, 6 insertions(+), 55 deletions(-)

diff --git a/source3/lib/recvfile.c b/source3/lib/recvfile.c
index bffe07f..273c51f 100644
--- a/source3/lib/recvfile.c
+++ b/source3/lib/recvfile.c
@@ -84,11 +84,7 @@ static ssize_t default_sys_recvfile(int fromfd,
 			read_ret = read(fromfd, buffer, toread);
 		} while (read_ret == -1 && errno == EINTR);
 
-#if defined(EWOULDBLOCK)
 		if (read_ret == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
-#else
-		if (read_ret == -1 && (errno == EAGAIN)) {
-#endif
 			/*
 			 * fromfd socket is in non-blocking mode.
 			 * If we already read some and wrote
@@ -209,11 +205,7 @@ ssize_t sys_recvfile(int fromfd,
 				return default_sys_recvfile(fromfd, tofd,
 							    offset, count);
 			}
-#if defined(EWOULDBLOCK)
 			if (errno == EAGAIN || errno == EWOULDBLOCK) {
-#else
-			if (errno == EAGAIN) {
-#endif
 				/*
 				 * fromfd socket is in non-blocking mode.
 				 * If we already read some and wrote
diff --git a/source3/lib/sendfile.c b/source3/lib/sendfile.c
index d5fd5a6..3d457bd 100644
--- a/source3/lib/sendfile.c
+++ b/source3/lib/sendfile.c
@@ -59,11 +59,7 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, off_t offset
 		ssize_t nwritten;
 		do {
 			nwritten = sendfile(tofd, fromfd, &offset, total);
-#if defined(EWOULDBLOCK)
 		} while (nwritten == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
-#else
-		} while (nwritten == -1 && (errno == EINTR || errno == EAGAIN));
-#endif
 		if (nwritten == -1) {
 			if (errno == ENOSYS || errno == EINVAL) {
 				/* Ok - we're in a world of pain here. We just sent
@@ -139,11 +135,7 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, off_t offset
 		xferred = 0;
 
 			nwritten = sendfilev(tofd, vec, sfvcnt, &xferred);
-#if defined(EWOULDBLOCK)
 		if  (nwritten == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) {
-#else
-		if (nwritten == -1 && (errno == EINTR || errno == EAGAIN)) {
-#endif
 			if (xferred == 0)
 				continue; /* Nothing written yet. */
 			else
@@ -213,11 +205,7 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, off_t offset
 
 		do {
 			nwritten = sendfile(tofd, fromfd, offset, total, &hdtrl[0], 0);
-#if defined(EWOULDBLOCK)
 		} while (nwritten == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
-#else
-		} while (nwritten == -1 && (errno == EINTR || errno == EAGAIN));
-#endif
 		if (nwritten == -1)
 			return -1;
 		if (nwritten == 0)
@@ -282,11 +270,7 @@ ssize_t sys_sendfile(int tofd, int fromfd,
 #else
 		ret = sendfile(fromfd, tofd, offset, count, &sf_header, &nwritten, 0);
 #endif
-#if defined(EWOULDBLOCK)
 		if (ret == -1 && errno != EINTR && errno != EAGAIN && errno != EWOULDBLOCK) {
-#else
-		if (ret == -1 && errno != EINTR && errno != EAGAIN) {
-#endif
 			/* Send failed, we are toast. */
 			return -1;
 		}
@@ -364,11 +348,7 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, off_t offset
 		*/
 		do {
 			ret = send_file(&tofd, &hdtrl, 0);
-#if defined(EWOULDBLOCK)
 		} while ((ret == 1) || (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)));
-#else
-		} while ((ret == 1) || (ret == -1 && (errno == EINTR || errno == EAGAIN)));
-#endif
 		if ( ret == -1 )
 			return -1;
 	}
diff --git a/source3/lib/system.c b/source3/lib/system.c
index 698de12..6478e6f 100644
--- a/source3/lib/system.c
+++ b/source3/lib/system.c
@@ -62,11 +62,8 @@ ssize_t sys_read(int fd, void *buf, size_t count)
 
 	do {
 		ret = read(fd, buf, count);
-#if defined(EWOULDBLOCK)
 	} while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
-#else
-	} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
-#endif
+
 	return ret;
 }
 
@@ -80,11 +77,8 @@ ssize_t sys_write(int fd, const void *buf, size_t count)
 
 	do {
 		ret = write(fd, buf, count);
-#if defined(EWOULDBLOCK)
 	} while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
-#else
-	} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
-#endif
+
 	return ret;
 }
 
@@ -109,11 +103,8 @@ ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt)
 
 	do {
 		ret = writev(fd, iov, iovcnt);
-#if defined(EWOULDBLOCK)
 	} while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
-#else
-	} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
-#endif
+
 	return ret;
 }
 
@@ -159,11 +150,8 @@ ssize_t sys_send(int s, const void *msg, size_t len, int flags)
 
 	do {
 		ret = send(s, msg, len, flags);
-#if defined(EWOULDBLOCK)
 	} while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
-#else
-	} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
-#endif
+
 	return ret;
 }
 
diff --git a/source3/lib/unix_msg/unix_msg.c b/source3/lib/unix_msg/unix_msg.c
index 00438ce..982ae46 100644
--- a/source3/lib/unix_msg/unix_msg.c
+++ b/source3/lib/unix_msg/unix_msg.c
@@ -246,9 +246,7 @@ static void unix_dgram_recv_handler(struct poll_watch *w, int fd, short events,
 	received = recvmsg(fd, &msg, 0);
 	if (received == -1) {
 		if ((errno == EAGAIN) ||
-#ifdef EWOULDBLOCK
 		    (errno == EWOULDBLOCK) ||
-#endif
 		    (errno == EINTR) || (errno == ENOMEM)) {
 			/* Not really an error - just try again. */
 			return;
@@ -496,11 +494,7 @@ static int unix_dgram_send(struct unix_dgram_ctx *ctx,
 	if (ret >= 0) {
 		return 0;
 	}
-#ifdef EWOULDBLOCK
 	if ((errno != EWOULDBLOCK) && (errno != EAGAIN) && (errno != EINTR)) {
-#else
-	if ((errno != EAGAIN) && (errno != EINTR)) {
-#endif
 		return errno;
 	}
 
diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index 744db7a..8e33f2d 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -467,12 +467,9 @@ ssize_t vfs_pwrite_data(struct smb_request *req,
 						fsp,
 						offset + total,
 						N - total);
-#if defined(EWOULDBLOCK)
 			if (ret == 0 || (ret == -1 &&
-				(errno == EAGAIN || errno == EWOULDBLOCK))) {
-#else /* EWOULDBLOCK */
-			if (ret == 0 || (ret == -1 && errno == EAGAIN)) {
-#endif /* EWOULDBLOCK */
+					 (errno == EAGAIN ||
+					  errno == EWOULDBLOCK))) {
 				int old_flags;
 				/* Ensure the socket is blocking. */
 				old_flags = fcntl(sockfd, F_GETFL, 0);
-- 
1.7.9.5


From 8bc471c576aaba13adba20f99bbb1eb042a2469b Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 17 Sep 2014 15:09:52 +0200
Subject: [PATCH 04/11] lib: Fix samba-util dep in "errors" module

This piece of code pulls in talloc_stackframe and smb_panic into what
should be a very simple mapping library. I'm trying to reduce our
dependencies right now a bit, and I think the use cases that this fixes
(unknown NTSTATUS together with double nt_errstr() calls in the same
DEBUG) are rare enough that this is not justified.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 libcli/util/nterr.c       |   24 ++++++++----------------
 libcli/util/wscript_build |    2 +-
 2 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/libcli/util/nterr.c b/libcli/util/nterr.c
index 9f90f7a..dbf399b 100644
--- a/libcli/util/nterr.c
+++ b/libcli/util/nterr.c
@@ -3905,8 +3905,8 @@ NTSTATUS nt_status_squash(NTSTATUS nt_status)
 
 const char *nt_errstr(NTSTATUS nt_code)
 {
+	static char msg[20];
 	int idx = 0;
-	char *result;
 
 	while (nt_errs[idx].nt_errstr != NULL) {
 		if (NT_STATUS_V(nt_errs[idx].nt_errcode) ==
@@ -3916,22 +3916,14 @@ const char *nt_errstr(NTSTATUS nt_code)
 		idx++;
 	}
 
-	if (!talloc_stackframe_exists()) {
-		/* prevent memory leaks from talloc_tos() by using a
-		 * static area. This means the caller will overwrite
-		 * the string with subsequent calls, which can cause
-		 * display of the wrong error. If that happens the
-		 * caller should have a talloc stackframe
-		 */
-		static char msg[20];
-		snprintf(msg, sizeof(msg), "NT code 0x%08x", NT_STATUS_V(nt_code));
-		return msg;
-	}
+	/*
+	 * This should not really happen, we should have all error codes
+	 * available. We have a problem that this might get wrongly
+	 * overwritten by later calls in the same DEBUG statement.
+	 */
 
-	result = talloc_asprintf(talloc_tos(), "NT code 0x%08x",
-				 NT_STATUS_V(nt_code));
-	SMB_ASSERT(result != NULL);
-	return result;
+	snprintf(msg, sizeof(msg), "NT code 0x%08x", NT_STATUS_V(nt_code));
+	return msg;
 }
 
 /************************************************************************
diff --git a/libcli/util/wscript_build b/libcli/util/wscript_build
index 3bfa4b1..ccb882d 100644
--- a/libcli/util/wscript_build
+++ b/libcli/util/wscript_build
@@ -5,7 +5,7 @@ bld.SAMBA_LIBRARY('errors',
                   public_headers='error.h ntstatus.h doserr.h werror.h hresult.h',
                   header_path='core',
                   source='doserr.c errormap.c nterr.c errmap_unix.c hresult.c',
-                  public_deps='talloc samba-util',
+                  public_deps='talloc samba-debug',
                   private_library=True
                   )
 
-- 
1.7.9.5


From 0d92b07e11b521e71a83a7c0b693f644b250e022 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 14 Sep 2014 11:15:34 +0200
Subject: [PATCH 05/11] lib: Move tdb lock timeout fns to source3

This is not the nicest code and needs to be replaced. Remove it from
common.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/util/util_tdb.c        |   78 --------------------------------------------
 lib/util/util_tdb.h        |   18 ----------
 source3/include/util_tdb.h |   19 +++++++++++
 source3/lib/util_tdb.c     |   78 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 97 insertions(+), 96 deletions(-)

diff --git a/lib/util/util_tdb.c b/lib/util/util_tdb.c
index 93df958..811c2a4 100644
--- a/lib/util/util_tdb.c
+++ b/lib/util/util_tdb.c
@@ -317,84 +317,6 @@ int32_t tdb_change_int32_atomic(struct tdb_context *tdb, const char *keystr, int
 	return ret;
 }
 
-static sig_atomic_t gotalarm;
-
-/***************************************************************
- Signal function to tell us we timed out.
-****************************************************************/
-
-static void gotalarm_sig(int signum)
-{
-	gotalarm = 1;
-}
-
-/****************************************************************************
- Lock a chain with timeout (in seconds).
-****************************************************************************/
-
-static int tdb_chainlock_with_timeout_internal( TDB_CONTEXT *tdb, TDB_DATA key, unsigned int timeout, int rw_type)
-{
-	/* Allow tdb_chainlock to be interrupted by an alarm. */
-	int ret;
-	gotalarm = 0;
-
-	if (timeout) {
-		CatchSignal(SIGALRM, gotalarm_sig);
-		tdb_setalarm_sigptr(tdb, &gotalarm);
-		alarm(timeout);
-	}
-
-	if (rw_type == F_RDLCK)
-		ret = tdb_chainlock_read(tdb, key);
-	else
-		ret = tdb_chainlock(tdb, key);
-
-	if (timeout) {
-		alarm(0);
-		tdb_setalarm_sigptr(tdb, NULL);
-		CatchSignal(SIGALRM, SIG_IGN);
-		if (gotalarm && (ret != 0)) {
-			DEBUG(0,("tdb_chainlock_with_timeout_internal: alarm (%u) timed out for key %s in tdb %s\n",
-				timeout, key.dptr, tdb_name(tdb)));
-			/* TODO: If we time out waiting for a lock, it might
-			 * be nice to use F_GETLK to get the pid of the
-			 * process currently holding the lock and print that
-			 * as part of the debugging message. -- mbp */
-			return -1;
-		}
-	}
-
-	return ret == 0 ? 0 : -1;
-}
-
-/****************************************************************************
- Write lock a chain. Return non-zero if timeout or lock failed.
-****************************************************************************/
-
-int tdb_chainlock_with_timeout( TDB_CONTEXT *tdb, TDB_DATA key, unsigned int timeout)
-{
-	return tdb_chainlock_with_timeout_internal(tdb, key, timeout, F_WRLCK);
-}
-
-int tdb_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval,
-				   int timeout)
-{
-	TDB_DATA key = string_term_tdb_data(keyval);
-
-	return tdb_chainlock_with_timeout(tdb, key, timeout);
-}
-
-/****************************************************************************
- Read lock a chain by string. Return non-zero if timeout or lock failed.
-****************************************************************************/
-
-int tdb_read_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval, unsigned int timeout)
-{
-	TDB_DATA key = string_term_tdb_data(keyval);
-
-	return tdb_chainlock_with_timeout_internal(tdb, key, timeout, F_RDLCK);
-}
-
 /****************************************************************************
  Atomic unsigned integer change. Returns old value. To create, set initial value in *oldval. 
 ****************************************************************************/
diff --git a/lib/util/util_tdb.h b/lib/util/util_tdb.h
index 630bdf66..12c472c 100644
--- a/lib/util/util_tdb.h
+++ b/lib/util/util_tdb.h
@@ -53,24 +53,6 @@ int tdb_read_lock_bystring(struct tdb_context *tdb, const char *keyval);
 void tdb_read_unlock_bystring(struct tdb_context *tdb, const char *keyval);
 
 /****************************************************************************
- Lock a chain, with timeout.
-****************************************************************************/
-int tdb_chainlock_with_timeout( struct tdb_context *tdb, TDB_DATA key,
-				unsigned int timeout);
-
-/****************************************************************************
- Lock a chain by string, with timeout Return non-zero if lock failed.
-****************************************************************************/
-int tdb_lock_bystring_with_timeout(struct tdb_context *tdb, const char *keyval,
-				   int timeout);
-
-/****************************************************************************
- Readlock a chain by string, with timeout Return non-zero if lock failed.
-****************************************************************************/
-int tdb_read_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval,
-					unsigned int timeout);
-
-/****************************************************************************
  Fetch a int32_t value by a arbitrary blob key, return -1 if not found.
  Output is int32_t in native byte order.
 ****************************************************************************/
diff --git a/source3/include/util_tdb.h b/source3/include/util_tdb.h
index c9e9e40..5a58a6b 100644
--- a/source3/include/util_tdb.h
+++ b/source3/include/util_tdb.h
@@ -46,4 +46,23 @@ int tdb_data_cmp(TDB_DATA t1, TDB_DATA t2);
 
 char *tdb_data_string(TALLOC_CTX *mem_ctx, TDB_DATA d);
 
+/****************************************************************************
+ Lock a chain, with timeout.
+****************************************************************************/
+int tdb_chainlock_with_timeout( struct tdb_context *tdb, TDB_DATA key,
+				unsigned int timeout);
+
+/****************************************************************************
+ Lock a chain by string, with timeout Return non-zero if lock failed.
+****************************************************************************/
+int tdb_lock_bystring_with_timeout(struct tdb_context *tdb, const char *keyval,
+				   int timeout);
+
+/****************************************************************************
+ Readlock a chain by string, with timeout Return non-zero if lock failed.
+****************************************************************************/
+int tdb_read_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval,
+					unsigned int timeout);
+
+
 #endif /* __TDBUTIL_H__ */
diff --git a/source3/lib/util_tdb.c b/source3/lib/util_tdb.c
index 440c28b..38c5fa0 100644
--- a/source3/lib/util_tdb.c
+++ b/source3/lib/util_tdb.c
@@ -451,3 +451,81 @@ done:
 	talloc_free(ost);
 	return ret;
 }
+
+static sig_atomic_t gotalarm;
+
+/***************************************************************
+ Signal function to tell us we timed out.
+****************************************************************/
+
+static void gotalarm_sig(int signum)
+{
+	gotalarm = 1;
+}
+
+/****************************************************************************
+ Lock a chain with timeout (in seconds).
+****************************************************************************/
+
+static int tdb_chainlock_with_timeout_internal( TDB_CONTEXT *tdb, TDB_DATA key, unsigned int timeout, int rw_type)
+{
+	/* Allow tdb_chainlock to be interrupted by an alarm. */
+	int ret;
+	gotalarm = 0;
+
+	if (timeout) {
+		CatchSignal(SIGALRM, gotalarm_sig);
+		tdb_setalarm_sigptr(tdb, &gotalarm);
+		alarm(timeout);
+	}
+
+	if (rw_type == F_RDLCK)
+		ret = tdb_chainlock_read(tdb, key);
+	else
+		ret = tdb_chainlock(tdb, key);
+
+	if (timeout) {
+		alarm(0);
+		tdb_setalarm_sigptr(tdb, NULL);
+		CatchSignal(SIGALRM, SIG_IGN);
+		if (gotalarm && (ret != 0)) {
+			DEBUG(0,("tdb_chainlock_with_timeout_internal: alarm (%u) timed out for key %s in tdb %s\n",
+				timeout, key.dptr, tdb_name(tdb)));
+			/* TODO: If we time out waiting for a lock, it might
+			 * be nice to use F_GETLK to get the pid of the
+			 * process currently holding the lock and print that
+			 * as part of the debugging message. -- mbp */
+			return -1;
+		}
+	}
+
+	return ret == 0 ? 0 : -1;
+}
+
+/****************************************************************************
+ Write lock a chain. Return non-zero if timeout or lock failed.
+****************************************************************************/
+
+int tdb_chainlock_with_timeout( TDB_CONTEXT *tdb, TDB_DATA key, unsigned int timeout)
+{
+	return tdb_chainlock_with_timeout_internal(tdb, key, timeout, F_WRLCK);
+}
+
+int tdb_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval,
+				   int timeout)
+{
+	TDB_DATA key = string_term_tdb_data(keyval);
+
+	return tdb_chainlock_with_timeout(tdb, key, timeout);
+}
+
+/****************************************************************************
+ Read lock a chain by string. Return non-zero if timeout or lock failed.
+****************************************************************************/
+
+int tdb_read_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval, unsigned int timeout)
+{
+	TDB_DATA key = string_term_tdb_data(keyval);
+
+	return tdb_chainlock_with_timeout_internal(tdb, key, timeout, F_RDLCK);
+}
-- 
1.7.9.5


From 71c54487b63d0f0eae44263f4bc38b3f88b63902 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 14 Sep 2014 09:35:24 +0200
Subject: [PATCH 06/11] tdb_wrap: Only pull in samba-debug

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/tdb_wrap/wscript_build        |    2 +-
 source4/ntvfs/posix/wscript_build |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/tdb_wrap/wscript_build b/lib/tdb_wrap/wscript_build
index 0e5532f..7e113c3 100644
--- a/lib/tdb_wrap/wscript_build
+++ b/lib/tdb_wrap/wscript_build
@@ -2,7 +2,7 @@
 
 bld.SAMBA_LIBRARY('tdb-wrap',
                   source='tdb_wrap.c',
-                  deps='tdb talloc samba-util samba-hostconfig',
+                  deps='tdb talloc samba-debug',
                   private_library=True,
                   local_include=False
                  )
diff --git a/source4/ntvfs/posix/wscript_build b/source4/ntvfs/posix/wscript_build
index f6e1ef6..a39989b 100644
--- a/source4/ntvfs/posix/wscript_build
+++ b/source4/ntvfs/posix/wscript_build
@@ -48,7 +48,7 @@ bld.SAMBA_PYTHON('python_xattr_native',
 
 bld.SAMBA_LIBRARY('posix_eadb',
                   source='posix_eadb.c',
-                  deps='tdb tdb-wrap',
+                  deps='tdb tdb-wrap samba-util',
                   autoproto='posix_eadb_proto.h',
                   private_library=True)
 
-- 
1.7.9.5


From 7cdc8b57da27dc69a674c9b8a7b1eeba02a3fc14 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 14 Sep 2014 11:22:36 +0200
Subject: [PATCH 07/11] lib: util_tdb does not need samba-util

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/util/wscript_build |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index 0267ddc..a769b03 100755
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -71,7 +71,7 @@ bld.SAMBA_SUBSYSTEM('UNIX_PRIVS',
 bld.SAMBA_LIBRARY('util_tdb',
 	source='util_tdb.c',
 	local_include=False,
-	public_deps='tdb talloc samba-util',
+	public_deps='tdb talloc',
 	private_library=True
 	)
 
-- 
1.7.9.5


From 5c63934049b4ab27cca0ae73ecac38bcbad57a96 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 14 Sep 2014 14:33:53 +0200
Subject: [PATCH 08/11] messaging4: Fix an error path memleak

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/lib/messaging/messaging.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index a67a58a..53c8a9a 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -1041,6 +1041,7 @@ struct irpc_name_records *irpc_all_servers(struct imessaging_context *msg_ctx,
 
 	ret = tdb_traverse_read(t->tdb, all_servers_func, name_records);
 	if (ret == -1) {
+		TALLOC_FREE(name_records);
 		return NULL;
 	}
 
-- 
1.7.9.5


From b02fe6a164e20a1252fc84f7f723ef35937ca498 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 13 Sep 2014 20:06:45 +0200
Subject: [PATCH 09/11] ctdb_conn: Fix a small memory leak when releasing an
 IP

We're exiting anyway, but when in the future we have multichannel this
might actually be a small leak.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/ctdbd_conn.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 3ba8385..a667482 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -415,6 +415,8 @@ static NTSTATUS ctdb_read_req(struct ctdbd_connection *conn, uint32_t reqid,
 			DEBUG(10, ("received CTDB_SRVID_RELEASE_IP\n"));
 			ret = conn->release_ip_handler((const char *)msg->data,
 						       conn->release_ip_priv);
+			TALLOC_FREE(hdr);
+
 			if (ret) {
 				/*
 				 * We need to release the ip,
@@ -426,7 +428,6 @@ static NTSTATUS ctdb_read_req(struct ctdbd_connection *conn, uint32_t reqid,
 				conn->release_ip_priv = NULL;
 				return NT_STATUS_ADDRESS_CLOSED;
 			}
-			TALLOC_FREE(hdr);
 			goto next_pkt;
 		}
 
-- 
1.7.9.5


From 3b19b962f5a9bc78819a27638ed3cf097c7e05de Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 13 Sep 2014 20:44:13 +0200
Subject: [PATCH 10/11] lib: Add EMSGSIZE to map_nt_error_from_unix

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/errmap_unix.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/source3/lib/errmap_unix.c b/source3/lib/errmap_unix.c
index c5e190c..56d3f00 100644
--- a/source3/lib/errmap_unix.c
+++ b/source3/lib/errmap_unix.c
@@ -49,6 +49,7 @@ static const struct {
 	{ ENOSPC,       NT_STATUS_DISK_FULL },
 	{ ENOMEM,       NT_STATUS_NO_MEMORY },
 	{ EISDIR,       NT_STATUS_FILE_IS_A_DIRECTORY},
+	{ EMSGSIZE,	NT_STATUS_PORT_MESSAGE_TOO_LONG },
 #ifdef EPIPE
 	{ EPIPE,        NT_STATUS_CONNECTION_DISCONNECTED},
 #endif
-- 
1.7.9.5


From a4de70d7c16f3adc2fc312b5834b8b781d117cce Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 14 Sep 2014 20:45:31 +0200
Subject: [PATCH 11/11] lib: Polish echo_server

Samba has a lot of struct assignments now, in a lot of cases it simplifies the
code. Use it in the sample code.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/tevent/echo_server.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/tevent/echo_server.c b/lib/tevent/echo_server.c
index a1da0d8..102f7b4 100644
--- a/lib/tevent/echo_server.c
+++ b/lib/tevent/echo_server.c
@@ -619,10 +619,10 @@ int main(int argc, const char **argv)
 		exit(1);
 	}
 
-	memset(&addr, 0, sizeof(addr));
-
-	addr.sin_family = AF_INET;
-	addr.sin_port = htons(port);
+	addr = (struct sockaddr_in) {
+		.sin_family = AF_INET,
+		.sin_port = htons(port)
+	};
 
 	ret = bind(listen_sock, (struct sockaddr *)&addr, sizeof(addr));
 	if (ret == -1) {
-- 
1.7.9.5



More information about the samba-technical mailing list