ctdb-recovery: Negate the status when checking the recovery lock
authorMartin Schwenke <martin@meltin.net>
Thu, 28 Jan 2016 04:07:30 +0000 (15:07 +1100)
committerAmitay Isaacs <amitay@samba.org>
Tue, 23 Feb 2016 06:23:18 +0000 (07:23 +0100)
Have 0 indicate that the lock was taken.  This allows non-zero values
to be used to indicate why the lock could not be taken.  EACCES means
lock contention.

For now use just EACCES to cover all failures, since
ctdb_recovery_lock() returns a bool and details of other errors will
be lost.  ctdb_recovery_lock() will undergo some big changes, so don't
try to fix this now.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_recover.c

index 658735bf9777756a771961adacdba8106b844b75..988f205d1efbcfddec777a8867d1062ffe9e33ce 100644 (file)
@@ -477,12 +477,12 @@ static void set_recmode_handler(struct tevent_context *ev,
 
        ret = sys_read(state->fd[0], &c, 1);
        if (ret == 1) {
-               /* Child wrote status. 0 indicates that it was unable
+               /* Child wrote status. EACCES indicates that it was unable
                 * to take the lock, which is the expected outcome.
-                * Non-zero indicates that it was able to take the
+                * 0 indicates that it was able to take the
                 * lock, which is an error because the recovery daemon
                 * should be holding the lock. */
-               if (c == 0) {
+               if (c == EACCES) {
                        status = 0;
                        err = NULL;
 
@@ -634,7 +634,7 @@ int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
        }
 
        if (state->child == 0) {
-               char cc = 0;
+               char cc = EACCES;
                close(state->fd[0]);
 
                prctl_set_comment("ctdb_recmode");
@@ -646,7 +646,7 @@ int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
                              ("ERROR: Daemon able to take recovery lock on \"%s\" during recovery\n",
                               ctdb->recovery_lock_file));
                        ctdb_recovery_unlock(ctdb);
-                       cc = 1;
+                       cc = 0;
                }
 
                sys_write(state->fd[1], &cc, 1);