s3:smbd: use tevent_loop_wait() in the child process event loop
authorMichael Adam <obnox@samba.org>
Tue, 26 Feb 2013 15:18:09 +0000 (16:18 +0100)
committerMichael Adam <obnox@samba.org>
Fri, 19 Sep 2014 07:15:12 +0000 (09:15 +0200)
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
source3/smbd/globals.h
source3/smbd/process.c

index ce2d3b19968066786bb277cb2d979e9482e2fd1d..55a8263f7e7a8b62fb75d45bebf0320e62378e39 100644 (file)
@@ -506,8 +506,6 @@ struct smbXsrv_connection {
                struct smbd_smb2_request *requests;
        } smb2;
 
-       uint64_t smbd_idle_profstamp;
-
        /*
         * this session_table is used for SMB1 and SMB2,
         */
index 280f86246a201366c40f66f8dbc22e90d672935a..3cd3335e5e5a260d75ba065096d051039782e609 100644 (file)
@@ -3495,12 +3495,16 @@ NTSTATUS smbXsrv_connection_init_tables(struct smbXsrv_connection *conn,
        return NT_STATUS_OK;
 }
 
+struct smbd_tevent_trace_state {
+       TALLOC_CTX *frame;
+       uint64_t smbd_idle_profstamp;
+};
+
 static void smbd_tevent_trace_callback(enum tevent_trace_point point,
                                       void *private_data)
 {
-       struct smbXsrv_connection *conn =
-               talloc_get_type_abort(private_data,
-               struct smbXsrv_connection);
+       struct smbd_tevent_trace_state *state =
+               (struct smbd_tevent_trace_state *)private_data;
 
        switch (point) {
        case TEVENT_TRACE_BEFORE_WAIT:
@@ -3508,18 +3512,22 @@ static void smbd_tevent_trace_callback(enum tevent_trace_point point,
                 * This just removes compiler warning
                 * without profile support
                 */
-               conn->smbd_idle_profstamp = 0;
-               START_PROFILE_STAMP(smbd_idle, conn->smbd_idle_profstamp);
+               state->smbd_idle_profstamp = 0;
+               START_PROFILE_STAMP(smbd_idle, state->smbd_idle_profstamp);
                break;
        case TEVENT_TRACE_AFTER_WAIT:
-               END_PROFILE_STAMP(smbd_idle, conn->smbd_idle_profstamp);
+               END_PROFILE_STAMP(smbd_idle, state->smbd_idle_profstamp);
                break;
-#ifdef TEVENT_HAS_LOOP_ONCE_TRACE_POINTS
        case TEVENT_TRACE_BEFORE_LOOP_ONCE:
+               TALLOC_FREE(state->frame);
+               state->frame = talloc_stackframe_pool(8192);
+               break;
        case TEVENT_TRACE_AFTER_LOOP_ONCE:
+               TALLOC_FREE(state->frame);
                break;
-#endif
        }
+
+       errno = 0;
 }
 
 /**
@@ -3554,7 +3562,9 @@ void smbd_process(struct tevent_context *ev_ctx,
                  int sock_fd,
                  bool interactive)
 {
-       TALLOC_CTX *frame = talloc_stackframe();
+       struct smbd_tevent_trace_state trace_state = {
+               .frame = talloc_stackframe(),
+       };
        struct smbXsrv_client *client;
        struct smbXsrv_connection *xconn;
        struct smbd_server_connection *sconn;
@@ -3894,25 +3904,19 @@ void smbd_process(struct tevent_context *ev_ctx,
        xconn->remote_hostname = sconn->remote_hostname;
        xconn->protocol = PROTOCOL_NONE;
 
-       TALLOC_FREE(frame);
+       TALLOC_FREE(trace_state.frame);
 
-       tevent_set_trace_callback(ev_ctx, smbd_tevent_trace_callback, xconn);
+       tevent_set_trace_callback(ev_ctx, smbd_tevent_trace_callback,
+                                 &trace_state);
 
-       while (True) {
-               frame = talloc_stackframe_pool(8192);
-
-               errno = 0;
-               if (tevent_loop_once(ev_ctx) == -1) {
-                       if (errno != EINTR) {
-                               DEBUG(3, ("tevent_loop_once failed: %s,"
-                                         " exiting\n", strerror(errno) ));
-                               break;
-                       }
-               }
-
-               TALLOC_FREE(frame);
+       ret = tevent_loop_wait(ev_ctx);
+       if (ret != 0) {
+               DEBUG(1, ("tevent_loop_wait failed: %d, %s,"
+                         " exiting\n", ret, strerror(errno)));
        }
 
+       TALLOC_FREE(trace_state.frame);
+
        exit_server_cleanly(NULL);
 }