]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
r24019: merge from http://people.samba.org/bzr/metze/samba/3_2-ctdb-metze/:
authorStefan Metzmacher <metze@samba.org>
Tue, 24 Jul 2007 09:20:23 +0000 (09:20 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:28:56 +0000 (12:28 -0500)
use a timed event to make sure the timelimit is correctly
handled in smbcontrol when waiting for messages

metze
(This used to be commit 68c786dafacb187dfea83c45b7fd84127dc02e43)

source3/utils/smbcontrol.c

index 532b2fb8bf04952e735cb5e1ee358551afff3c2a..e4db2cd4f616a0f45d046f7da69a27be3bcf6bea 100644 (file)
@@ -65,23 +65,38 @@ static BOOL send_message(struct messaging_context *msg_ctx,
        return ret;
 }
 
+static void timeout_handler(struct event_context *event_ctx,
+                           struct timed_event *te,
+                           const struct timeval *now,
+                           void *private_data)
+{
+       BOOL *timed_out = (BOOL *)private_data;
+       TALLOC_FREE(te);
+       *timed_out = True;
+}
+
 /* Wait for one or more reply messages */
 
 static void wait_replies(struct messaging_context *msg_ctx,
                         BOOL multiple_replies)
 {
-       time_t start_time = time(NULL);
-
-       /* Wait around a bit.  This is pretty disgusting - we have to
-           busy-wait here as there is no nicer way to do it. */
+       struct timed_event *te;
+       BOOL timed_out = False;
+
+       if (!(te = event_add_timed(messaging_event_context(msg_ctx), NULL,
+                                  timeval_current_ofs(timeout, 0),
+                                  "smbcontrol_timeout",
+                                  timeout_handler, (void *)&timed_out))) {
+               DEBUG(0, ("event_add_timed failed\n"));
+               return;
+       }
 
-       do {
+       while (!timed_out) {
                message_dispatch(msg_ctx);
-               event_loop_once(messaging_event_context(msg_ctx));
                if (num_replies > 0 && !multiple_replies)
                        break;
-               sleep(1);
-       } while (timeout - (time(NULL) - start_time) > 0);
+               event_loop_once(messaging_event_context(msg_ctx));
+       }
 }
 
 /* Message handler callback that displays the PID and a string on stdout */