summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-07-24 09:20:23 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:28:56 -0500
commitefddd9c7533447d6df304701b02c08c562c9ad27 (patch)
tree6b8639082239eb33dea75cd212bd7ec6094ff801 /source3/utils
parentc8a07d8431f29b28e11041c8c3df60869c85bd57 (diff)
downloadsamba-efddd9c7533447d6df304701b02c08c562c9ad27.tar.gz
samba-efddd9c7533447d6df304701b02c08c562c9ad27.tar.bz2
samba-efddd9c7533447d6df304701b02c08c562c9ad27.zip
r24019: merge from http://people.samba.org/bzr/metze/samba/3_2-ctdb-metze/:
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)
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/smbcontrol.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c
index 532b2fb8bf..e4db2cd4f6 100644
--- a/source3/utils/smbcontrol.c
+++ b/source3/utils/smbcontrol.c
@@ -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 */