lockwait: Check result of lockwait child
authorVolker Lendecke <vl@samba.org>
Tue, 12 Mar 2013 12:35:17 +0000 (13:35 +0100)
committerAmitay Isaacs <amitay@gmail.com>
Mon, 25 Mar 2013 06:52:41 +0000 (17:52 +1100)
server/ctdb_lockwait.c

index 6e4ecfd58a552620b20ecebddbd44adf15e2facf..cdc1af0cc27a7641506b1ffeb83ea1ce106bb0ff 100644 (file)
@@ -89,6 +89,9 @@ static void lockwait_handler(struct event_context *ev, struct fd_event *fde,
        TDB_DATA key = h->key;
        struct tdb_context *tdb = h->ctdb_db->ltdb->tdb;
        TALLOC_CTX *tmp_ctx = talloc_new(ev);
+       char result;
+       ssize_t nread;
+       char *msg;
 
        key.dptr = talloc_memdup(tmp_ctx, key.dptr, key.dsize);
        h->ctdb_db->pending_requests--;
@@ -106,6 +109,19 @@ static void lockwait_handler(struct event_context *ev, struct fd_event *fde,
                }
        }
 
+       nread = read(h->fd[0], &result, sizeof(result));
+       if (nread == -1) {
+               asprintf(&msg, "lockwait child read failed: %s\n", strerror(errno));
+               ctdb_fatal(h->ctdb, msg);
+       }
+       if (nread == 0) {
+               ctdb_fatal(h->ctdb, "lockwait child exited early\n");
+       }
+       if (result != 0) {
+               asprintf(&msg, "lockwait child wrote %d\n", (int)result);
+               ctdb_fatal(h->ctdb, msg);
+       }
+
        tdb_chainlock_mark(tdb, key);
        callback(p);
        if (h->ctdb_db->lockwait_overflow) {