simpler shutdown process. The reply is not actually needed, and
authorAndrew Tridgell <tridge@samba.org>
Wed, 18 Apr 2007 05:35:41 +0000 (15:35 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 18 Apr 2007 05:35:41 +0000 (15:35 +1000)
occasionally leads to problems if an immediate send on the socket
causes a context switch and the client exiting before the daemon. We
now exit the client when the daemon goes away.

(This used to be ctdb commit b7bed0088e700f25105ceea63640b38804f51e4d)

ctdb/common/ctdb_client.c
ctdb/common/ctdb_daemon.c
ctdb/include/ctdb_private.h

index fb2018510d19479e1f6feed49c9fce1f029bcbf0..1eef235e00c24f11b9808e33a1483e7dba158358 100644 (file)
@@ -92,19 +92,6 @@ void ctdb_reply_fetch_lock(struct ctdb_context *ctdb, struct ctdb_req_header *hd
        state->state = CTDB_FETCH_LOCK_DONE;
 }
 
-/*
-  called in the client when we receive a CTDB_REPLY_SHUTDOWN from the daemon
-
-  This packet comes in response to a CTDB_REQ_SHUTDOWN request packet. It
-  contains any reply data from the call
-*/
-void ctdb_reply_shutdown(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
-{
-       talloc_free(ctdb);
-
-       exit(10);
-}
-
 /*
   this is called in the client, when data comes in from the daemon
  */
@@ -121,9 +108,13 @@ static void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args)
        tmp_ctx = talloc_new(ctdb);
        talloc_steal(tmp_ctx, hdr);
 
+       if (cnt == 0) {
+               DEBUG(2,("Daemon has exited - shutting down client\n"));
+               exit(0);
+       }
+
        if (cnt < sizeof(*hdr)) {
-               ctdb_set_error(ctdb, "Bad packet length %d in client\n", cnt);
-               exit(1); /* XXX - temporary for debugging */
+               DEBUG(0,("Bad packet length %d in client\n", cnt));
                goto done;
        }
        if (cnt != hdr->length) {
@@ -159,10 +150,6 @@ static void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args)
                ctdb_reply_fetch_lock(ctdb, hdr);
                break;
 
-       case CTDB_REPLY_SHUTDOWN:
-               ctdb_reply_shutdown(ctdb, hdr);
-               break;
-
        default:
                DEBUG(0,("bogus operation code:%d\n",hdr->operation));
        }
index cb05c4176b447442506706a6226f653c56473b44..14019ea3f10cd412d8939764c064d99191e3c5ec 100644 (file)
@@ -197,7 +197,6 @@ static void daemon_fetch_lock_complete(struct ctdb_call_state *state)
 static void daemon_request_shutdown(struct ctdb_client *client, 
                                      struct ctdb_req_shutdown *f)
 {
-       struct ctdb_reply_shutdown rs;
        struct ctdb_context *ctdb = talloc_get_type(client->ctdb, struct ctdb_context);
        int len;
        uint32_t node;
@@ -240,16 +239,6 @@ static void daemon_request_shutdown(struct ctdb_client *client,
                event_loop_once(ctdb->ev);
        }
 
-       /* send a shutdown reply back to the client */
-       len = sizeof(struct ctdb_reply_shutdown);
-       ZERO_STRUCT(rs);
-       rs.hdr.length       = len;
-       rs.hdr.ctdb_magic   = CTDB_MAGIC;
-       rs.hdr.ctdb_version = CTDB_VERSION;
-       rs.hdr.operation    = CTDB_REPLY_SHUTDOWN;
-       ctdb_queue_send(client->queue, (uint8_t *)&(rs.hdr), rs.hdr.length);
-       /* XXX we should wait here until the packet has been sent to the client */
-
        /* all daemons have requested to finish - we now exit */
        DEBUG(1,("All daemons finished - exiting\n"));
        _exit(0);
index 3180366ff088861538d0a5b3b353707c03cfa86d..7b069e1331e4adcd8652b23a04d16309ff514291 100644 (file)
@@ -222,8 +222,7 @@ enum ctdb_operation {
        CTDB_REPLY_CONNECT_WAIT = 1002,
        CTDB_REQ_FETCH_LOCK     = 1003,
        CTDB_REPLY_FETCH_LOCK   = 1004,
-       CTDB_REQ_SHUTDOWN       = 1005,
-       CTDB_REPLY_SHUTDOWN     = 1006,
+       CTDB_REQ_SHUTDOWN       = 1005
 };
 
 #define CTDB_MAGIC 0x43544442 /* CTDB */