s3-prefork: Fix worker flags handling.
authorSimo Sorce <idra@samba.org>
Tue, 16 Aug 2011 15:37:41 +0000 (11:37 -0400)
committerSimo Sorce <idra@samba.org>
Sun, 21 Aug 2011 13:05:05 +0000 (09:05 -0400)
We can't have a clear idea of wether the worker is IDLE or BUSY.
The only things we can tell is if it is Alive, whether it is currently
Accepting connections or wether it is Exiting soon.

Remove PF_WORKER_IDLE, PF_WORKER_BUSY and replace their use with
PF_WORKER_ALIVE. Also properly assign PF_WORKER_ACCEPTING so that
users of the API can rely on the flag.

Signed-off-by: Andreas Schneider <asn@samba.org>
Signed-off-by: Simo Sorce <idra@samba.org>
source3/lib/server_prefork.c
source3/lib/server_prefork.h
source3/printing/spoolssd.c
source3/rpc_server/lsasd.c

index ee725e883b1a039ad0292782d079e1cbab422b3a..7d675485a045c791c7159bc5b81091a7a5b94e9c 100644 (file)
@@ -109,7 +109,7 @@ bool prefork_create_pool(TALLOC_CTX *mem_ctx,
 
                case 0: /* THE CHILD */
 
-                       pfp->pool[i].status = PF_WORKER_IDLE;
+                       pfp->pool[i].status = PF_WORKER_ALIVE;
                        ret = pfp->main_fn(ev_ctx, msg_ctx,
                                           &pfp->pool[i], i + 1,
                                           pfp->listen_fd_size,
@@ -196,7 +196,7 @@ int prefork_add_children(struct tevent_context *ev_ctx,
 
                case 0: /* THE CHILD */
 
-                       pfp->pool[i].status = PF_WORKER_IDLE;
+                       pfp->pool[i].status = PF_WORKER_ALIVE;
                        ret = pfp->main_fn(ev_ctx, msg_ctx,
                                           &pfp->pool[i], i + 1,
                                           pfp->listen_fd_size,
@@ -252,7 +252,8 @@ int prefork_retire_children(struct prefork_pool *pfp,
 
        for (i = 0; i < pfp->pool_size; i++) {
                oldest[i].num = i;
-               if (pfp->pool[i].status == PF_WORKER_IDLE) {
+               if (pfp->pool[i].status == PF_WORKER_ALIVE ||
+                   pfp->pool[i].status == PF_WORKER_ACCEPTING) {
                        oldest[i].started = pfp->pool[i].started;
                } else {
                        oldest[i].started = now;
@@ -264,7 +265,8 @@ int prefork_retire_children(struct prefork_pool *pfp,
                prefork_sort_oldest);
 
        for (i = 0, j = 0; i < pfp->pool_size && j < num_children; i++) {
-               if (pfp->pool[i].status == PF_WORKER_IDLE &&
+               if ((pfp->pool[i].status == PF_WORKER_ALIVE ||
+                    pfp->pool[i].status == PF_WORKER_ACCEPTING) &&
                    pfp->pool[i].started <= age_limit) {
                        /* tell the child it's time to give up */
                        DEBUG(5, ("Retiring pid %d!\n", pfp->pool[i].pid));
@@ -519,6 +521,8 @@ struct tevent_req *prefork_listen_send(TALLOC_CTX *mem_ctx,
                }
        }
 
+       pf->status = PF_WORKER_ACCEPTING;
+
        return req;
 }
 
@@ -539,6 +543,14 @@ static void prefork_listen_accept_handler(struct tevent_context *ev,
        req = ctx->req;
        state = tevent_req_data(ctx->req, struct pf_listen_state);
 
+       if (state->pf->cmds == PF_SRV_MSG_EXIT) {
+               /* We have been asked to exit, so drop here and the next
+                * child will pick it up */
+               state->pf->status = PF_WORKER_EXITING;
+               state->error = EINTR;
+               goto done;
+       }
+
        ZERO_STRUCT(addr);
        addrlen = sizeof(addr);
        sd = accept(ctx->listen_fd, (struct sockaddr *)&addr, &addrlen);
@@ -609,9 +621,11 @@ int prefork_listen_recv(struct tevent_req *req,
                *fd = state->accept_fd;
                *srv_addr = talloc_move(mem_ctx, &state->srv_addr);
                *cli_addr = talloc_move(mem_ctx, &state->cli_addr);
-               state->pf->status = PF_WORKER_BUSY;
                state->pf->num_clients++;
        }
+       if (state->pf->status == PF_WORKER_ACCEPTING) {
+               state->pf->status = PF_WORKER_ALIVE;
+       }
 
        tevent_req_received(req);
        return ret;
index 2685f5070000c69597adc678f62c62b7ae07137a..334b5813a00e7d1496251390f8ba8e4f2bc46567 100644 (file)
@@ -26,9 +26,8 @@ struct prefork_pool;
 
 enum pf_worker_status {
        PF_WORKER_NONE = 0,
-       PF_WORKER_IDLE,
+       PF_WORKER_ALIVE,
        PF_WORKER_ACCEPTING,
-       PF_WORKER_BUSY,
        PF_WORKER_EXITING
 };
 
index e1052ad1f5768cbe45da3eceae543a1de8b82044..76d05fca58db49d7e5e3d229267a192e9129caed 100644 (file)
@@ -437,7 +437,7 @@ static void spoolss_next_client(void *pvt)
        data = talloc_get_type_abort(pvt, struct spoolss_children_data);
 
        if (data->pf->num_clients == 0) {
-               data->pf->status = PF_WORKER_IDLE;
+               data->pf->status = PF_WORKER_ALIVE;
        }
 
        if (data->pf->cmds == PF_SRV_MSG_EXIT) {
index 743d91569c6561452a3b9847b35443cf0bd4736d..043165fe1364b5b92c4dd4e2b4131e540164271e 100644 (file)
@@ -374,7 +374,7 @@ static void lsasd_next_client(void *pvt)
        data = talloc_get_type_abort(pvt, struct lsasd_children_data);
 
        if (data->pf->num_clients == 0) {
-               data->pf->status = PF_WORKER_IDLE;
+               data->pf->status = PF_WORKER_ALIVE;
        }
 
        if (data->pf->cmds == PF_SRV_MSG_EXIT) {