Handle a client that exited correctly: We need to ignore SIGPIPE and when the
authorVolker Lendecke <vl@samba.org>
Wed, 11 Apr 2007 11:17:36 +0000 (13:17 +0200)
committerVolker Lendecke <vl@samba.org>
Wed, 11 Apr 2007 11:17:36 +0000 (13:17 +0200)
read returns 0 bytes this means the client has exited. Close the connection
then.

(This used to be ctdb commit bd10f4e62146493848258df8a3dc3b9222337a12)

ctdb/common/ctdb_daemon.c
ctdb/direct/ctdbd.c

index 6e9fbedb2fad33356241cd60c659aaea6cab6d01..72ab7ed0b10a154ed84af340a04ba8937ef55c0c 100644 (file)
@@ -283,6 +283,11 @@ static void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args)
        struct ctdb_client *client = talloc_get_type(args, struct ctdb_client);
        struct ctdb_req_header *hdr;
 
+       if (cnt == 0) {
+               talloc_free(client);
+               return;
+       }
+
        if (cnt < sizeof(*hdr)) {
                ctdb_set_error(client->ctdb, "Bad packet length %d\n", cnt);
                return;
index 8a99c0ab01248026f08699df2b4425967d2f99aa..727ca1d4a601a5109c4f3515ea9b495c0095d609 100644 (file)
 #include "lib/events/events.h"
 #include "system/filesys.h"
 #include "popt.h"
+#include <signal.h>
+
+static void block_signal(int signum)
+{
+       struct sigaction act;
+
+       memset(&act, 0, sizeof(act));
+
+       act.sa_handler = SIG_IGN;
+       sigemptyset(&act.sa_mask);
+       sigaddset(&act.sa_mask, signum);
+       sigaction(signum, &act, NULL);
+}
 
 
 /*
@@ -75,6 +88,8 @@ int main(int argc, const char *argv[])
                exit(1);
        }
 
+       block_signal(SIGPIPE);
+
        ev = event_context_init(NULL);
 
        /* initialise ctdb */