[PATCH] Simplify smb_msleep

Volker Lendecke vl at samba.org
Mon Mar 20 09:22:31 UTC 2017


Hi!

Review appreciated!

Thanks, Volker
-------------- next part --------------
>From e2718eb20674de2772afae8dd41877f6fbf91575 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 8 Jan 2017 19:52:47 +0000
Subject: [PATCH 1/3] lib: Avoid an includes.h

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

diff --git a/lib/util/select.c b/lib/util/select.c
index 99cd772..dc79a27 100644
--- a/lib/util/select.c
+++ b/lib/util/select.c
@@ -18,10 +18,11 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include "includes.h"
+#include "replace.h"
 #include "system/filesys.h"
 #include "system/select.h"
 #include "lib/util/select.h"
+#include "lib/util/time.h"
 
 int sys_poll_intr(struct pollfd *fds, int num_fds, int timeout)
 {
-- 
1.9.1


>From e079fbb0b3e73f9198f95fedffbb4270bca3de7d Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 19 Mar 2017 20:10:29 +0100
Subject: [PATCH 2/3] lib: Make sys_poll_intr available to ctdb

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

diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index ddece0e..bd3cc62 100644
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -71,7 +71,7 @@ bld.SAMBA_SUBSYSTEM('samba-util-core',
                     source='''data_blob.c util_file.c time.c
                               signal.c util.c idtree.c fault.c
                               substitute.c util_process.c util_strlist.c
-                              strv_util.c bitmap.c''',
+                              strv_util.c bitmap.c select.c''',
                     deps='''time-basic samba-debug socket-blocking talloc
                             tevent execinfo pthread strv''',
                     local_include=False)
@@ -113,7 +113,7 @@ else:
 
     bld.SAMBA_LIBRARY('samba-util',
                   source='''talloc_stack.c smb_threads.c
-                    rbtree.c rfc1738.c become_daemon.c system.c select.c getpass.c
+                    rbtree.c rfc1738.c become_daemon.c system.c getpass.c
                     genrand_util.c fsusage.c
                     params.c util_id.c util_net.c
                     util_strlist_v3.c util_paths.c
-- 
1.9.1


>From f357bfe85cecf702d9ebe5890a0cf1dd95a40ac6 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 8 Jan 2017 17:54:06 +0000
Subject: [PATCH 3/3] lib: Simplify smb_nanosleep

We have the recalculation logic also in sys_poll_intr, don't duplicate it.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/util/util.c | 44 ++------------------------------------------
 1 file changed, 2 insertions(+), 42 deletions(-)

diff --git a/lib/util/util.c b/lib/util/util.c
index 49f1584..ef148e9 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -33,6 +33,7 @@
 #include "system/wait.h"
 #include "debug.h"
 #include "samba_util.h"
+#include "lib/util/select.h"
 
 #undef malloc
 #undef strcasecmp
@@ -292,48 +293,7 @@ _PUBLIC_ bool directory_create_or_exist_strict(const char *dname,
 
 _PUBLIC_ void smb_msleep(unsigned int t)
 {
-#if defined(HAVE_NANOSLEEP)
-	struct timespec ts;
-	int ret;
-
-	ts.tv_sec = t/1000;
-	ts.tv_nsec = 1000000*(t%1000);
-
-	do {
-		errno = 0;
-		ret = nanosleep(&ts, &ts);
-	} while (ret < 0 && errno == EINTR && (ts.tv_sec > 0 || ts.tv_nsec > 0));
-#else
-	unsigned int tdiff=0;
-	struct timeval tval,t1,t2;
-	fd_set fds;
-
-	GetTimeOfDay(&t1);
-	t2 = t1;
-
-	while (tdiff < t) {
-		tval.tv_sec = (t-tdiff)/1000;
-		tval.tv_usec = 1000*((t-tdiff)%1000);
-
-		/* Never wait for more than 1 sec. */
-		if (tval.tv_sec > 1) {
-			tval.tv_sec = 1;
-			tval.tv_usec = 0;
-		}
-
-		FD_ZERO(&fds);
-		errno = 0;
-		select(0,&fds,NULL,NULL,&tval);
-
-		GetTimeOfDay(&t2);
-		if (t2.tv_sec < t1.tv_sec) {
-			/* Someone adjusted time... */
-			t1 = t2;
-		}
-
-		tdiff = usec_time_diff(&t2,&t1)/1000;
-	}
-#endif
+	sys_poll_intr(NULL, 0, t);
 }
 
 /**
-- 
1.9.1



More information about the samba-technical mailing list