]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
r22934: Change smbcontrol to use messaging_register instead of message_register
authorVolker Lendecke <vlendec@samba.org>
Wed, 16 May 2007 13:02:53 +0000 (13:02 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:22:10 +0000 (12:22 -0500)
(This used to be commit e3d985c581ffc597aea932858d27c421643d2868)

source3/lib/events.c
source3/lib/messages.c
source3/utils/smbcontrol.c

index a00db77b6bea3cd1fbaece208e5f9b3a3cd871d0..77d18ec13d057ef6e71c92e511f1b1307ff35505 100644 (file)
@@ -185,20 +185,27 @@ void event_fd_set_not_readable(struct fd_event *fde)
        fde->flags &= ~EVENT_FD_READ;
 }
 
-void event_add_to_select_args(struct event_context *event_ctx,
+/*
+ * Return if there's something in the queue
+ */
+
+BOOL event_add_to_select_args(struct event_context *event_ctx,
                              const struct timeval *now,
                              fd_set *read_fds, fd_set *write_fds,
                              struct timeval *timeout, int *maxfd)
 {
        struct fd_event *fde;
        struct timeval diff;
+       BOOL ret = False;
 
        for (fde = event_ctx->fd_events; fde; fde = fde->next) {
                if (fde->flags & EVENT_FD_READ) {
                        FD_SET(fde->fd, read_fds);
+                       ret = True;
                }
                if (fde->flags & EVENT_FD_WRITE) {
                        FD_SET(fde->fd, write_fds);
+                       ret = True;
                }
 
                if ((fde->flags & (EVENT_FD_READ|EVENT_FD_WRITE))
@@ -208,11 +215,13 @@ void event_add_to_select_args(struct event_context *event_ctx,
        }
 
        if (event_ctx->timed_events == NULL) {
-               return;
+               return ret;
        }
 
        diff = timeval_until(now, &event_ctx->timed_events->when);
        *timeout = timeval_min(timeout, &diff);
+
+       return True;
 }
 
 BOOL run_events(struct event_context *event_ctx,
@@ -297,6 +306,40 @@ struct timeval *get_timed_events_timeout(struct event_context *event_ctx,
        return to_ret;
 }
 
+int event_loop_once(struct event_context *ev)
+{
+       struct timeval now, to;
+       fd_set r_fds, w_fds;
+       int maxfd = 0;
+       int ret;
+
+       FD_ZERO(&r_fds);
+       FD_ZERO(&w_fds);
+
+       to.tv_sec = 9999;       /* Max timeout */
+       to.tv_usec = 0;
+
+       GetTimeOfDay(&now);
+
+       if (!event_add_to_select_args(ev, &now, &r_fds, &w_fds, &to, &maxfd)) {
+               return -1;
+       }
+
+       if (timeval_is_zero(&to)) {
+               run_events(ev, 0, NULL, NULL);
+               return 0;
+       }
+
+       ret = sys_select(maxfd, &r_fds, &w_fds, NULL, &to);
+
+       if (ret == -1 && errno != EINTR) {
+               return -1;
+       }
+
+       run_events(ev, ret, &r_fds, &w_fds);
+       return 0;
+}
+
 struct event_context *event_context_init(TALLOC_CTX *mem_ctx)
 {
        return TALLOC_ZERO_P(NULL, struct event_context);
index 9c1eba7b1c6349adbc620ed4f350018138b6b0c9..4cbdda61ee91c385a0cf07242265a9953d9682d5 100644 (file)
@@ -723,6 +723,7 @@ struct messaging_callback {
 
 struct messaging_context {
        struct server_id id;
+       struct event_context *event_ctx;
        struct messaging_callback *callbacks;
 };
 
@@ -740,6 +741,11 @@ static int messaging_context_destructor(struct messaging_context *ctx)
        return 0;
 }
 
+struct event_context *messaging_event_context(struct messaging_context *msg_ctx)
+{
+       return msg_ctx->event_ctx;
+}
+
 struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, 
                                         struct server_id server_id, 
                                         struct event_context *ev)
@@ -751,6 +757,7 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
        }
 
        ctx->id = server_id;
+       ctx->event_ctx = ev;
        talloc_set_destructor(ctx, messaging_context_destructor);
 
        if (!message_init(ctx)) {
index f9e39329f178159f124ff7b4f55200d744b45dbd..5d06576825b2ab986ecabea321d2b49887e818b0 100644 (file)
@@ -70,7 +70,8 @@ static BOOL send_message(struct messaging_context *msg_ctx,
 
 /* Wait for one or more reply messages */
 
-static void wait_replies(BOOL multiple_replies)
+static void wait_replies(struct messaging_context *msg_ctx,
+                        BOOL multiple_replies)
 {
        time_t start_time = time(NULL);
 
@@ -79,6 +80,7 @@ static void wait_replies(BOOL multiple_replies)
 
        do {
                message_dispatch();
+               event_loop_once(messaging_event_context(msg_ctx));
                if (num_replies > 0 && !multiple_replies)
                        break;
                sleep(1);
@@ -87,20 +89,26 @@ static void wait_replies(BOOL multiple_replies)
 
 /* Message handler callback that displays the PID and a string on stdout */
 
-static void print_pid_string_cb(int msg_type, struct server_id pid, void *buf,
-                               size_t len, void *private_data)
+static void print_pid_string_cb(struct messaging_context *msg,
+                               void *private_data, 
+                               uint32_t msg_type, 
+                               struct server_id pid,
+                               DATA_BLOB *data)
 {
        printf("PID %u: %.*s", (unsigned int)procid_to_pid(&pid),
-              (int)len, (const char *)buf);
+              (int)data->length, (const char *)data->data);
        num_replies++;
 }
 
 /* Message handler callback that displays a string on stdout */
 
-static void print_string_cb(int msg_type, struct server_id pid,
-                           void *buf, size_t len, void *private_data)
+static void print_string_cb(struct messaging_context *msg,
+                           void *private_data, 
+                           uint32_t msg_type, 
+                           struct server_id pid,
+                           DATA_BLOB *data)
 {
-       printf("%.*s", (int)len, (const char *)buf);
+       printf("%.*s", (int)data->length, (const char *)data->data);
        num_replies++;
 }
 
@@ -350,8 +358,11 @@ static BOOL do_election(struct messaging_context *msg_ctx,
 
 /* Ping a samba daemon process */
 
-static void pong_cb(int msg_type, struct server_id pid, void *buf,
-                   size_t len, void *private_data)
+static void pong_cb(struct messaging_context *msg,
+                   void *private_data, 
+                   uint32_t msg_type, 
+                   struct server_id pid,
+                   DATA_BLOB *data)
 {
        char *src_string = procid_str(NULL, &pid);
        printf("PONG from pid %s\n", src_string);
@@ -373,16 +384,16 @@ static BOOL do_ping(struct messaging_context *msg_ctx,
        if (!send_message(msg_ctx, pid, MSG_PING, NULL, 0, False))
                return False;
 
-       message_register(MSG_PONG, pong_cb, NULL);
+       messaging_register(msg_ctx, NULL, MSG_PONG, pong_cb);
 
-       wait_replies(procid_to_pid(&pid) == 0);
+       wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
 
        /* No replies were received within the timeout period */
 
        if (num_replies == 0)
                printf("No replies received\n");
 
-       message_deregister(MSG_PONG);
+       messaging_deregister(msg_ctx, MSG_PONG, NULL);
 
        return num_replies;
 }
@@ -490,14 +501,14 @@ static BOOL do_profilelevel(struct messaging_context *msg_ctx,
        messaging_register(msg_ctx, NULL, MSG_REQ_PROFILELEVEL,
                           profilelevel_rqst);
 
-       wait_replies(procid_to_pid(&pid) == 0);
+       wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
 
        /* No replies were received within the timeout period */
 
        if (num_replies == 0)
                printf("No replies received\n");
 
-       message_deregister(MSG_PROFILE);
+       messaging_deregister(msg_ctx, MSG_PROFILE, NULL);
 
        return num_replies;
 }
@@ -518,16 +529,16 @@ static BOOL do_debuglevel(struct messaging_context *msg_ctx,
        if (!send_message(msg_ctx, pid, MSG_REQ_DEBUGLEVEL, NULL, 0, False))
                return False;
 
-       message_register(MSG_DEBUGLEVEL, print_pid_string_cb, NULL);
+       messaging_register(msg_ctx, NULL, MSG_DEBUGLEVEL, print_pid_string_cb);
 
-       wait_replies(procid_to_pid(&pid) == 0);
+       wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
 
        /* No replies were received within the timeout period */
 
        if (num_replies == 0)
                printf("No replies received\n");
 
-       message_deregister(MSG_DEBUGLEVEL);
+       messaging_deregister(msg_ctx, MSG_DEBUGLEVEL, NULL);
 
        return num_replies;
 }
@@ -730,21 +741,21 @@ static BOOL do_poolusage(struct messaging_context *msg_ctx,
                return False;
        }
 
-       message_register(MSG_POOL_USAGE, print_string_cb, NULL);
+       messaging_register(msg_ctx, NULL, MSG_POOL_USAGE, print_string_cb);
 
        /* Send a message and register our interest in a reply */
 
        if (!send_message(msg_ctx, pid, MSG_REQ_POOL_USAGE, NULL, 0, False))
                return False;
 
-       wait_replies(procid_to_pid(&pid) == 0);
+       wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
 
        /* No replies were received within the timeout period */
 
        if (num_replies == 0)
                printf("No replies received\n");
 
-       message_deregister(MSG_POOL_USAGE);
+       messaging_deregister(msg_ctx, MSG_POOL_USAGE, NULL);
 
        return num_replies;
 }
@@ -929,20 +940,21 @@ static BOOL do_winbind_onlinestatus(struct messaging_context *msg_ctx,
                return False;
        }
 
-       message_register(MSG_WINBIND_ONLINESTATUS, print_pid_string_cb, NULL);
+       messaging_register(msg_ctx, NULL, MSG_WINBIND_ONLINESTATUS,
+                          print_pid_string_cb);
 
        if (!send_message(msg_ctx, pid, MSG_WINBIND_ONLINESTATUS, &myid,
                          sizeof(myid), False))
                return False;
 
-       wait_replies(procid_to_pid(&pid) == 0);
+       wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
 
        /* No replies were received within the timeout period */
 
        if (num_replies == 0)
                printf("No replies received\n");
 
-       message_deregister(MSG_WINBIND_ONLINESTATUS);
+       messaging_deregister(msg_ctx, MSG_WINBIND_ONLINESTATUS, NULL);
 
        return num_replies;
 }