eventscript: replace other -1 returns with -errno
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 7 Dec 2009 12:45:56 +0000 (23:15 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 7 Dec 2009 12:45:56 +0000 (23:15 +1030)
This completes our "problem with script" reporting; we never set cb_status
to -1 on error.  Real errnos are used where the failure is a system call
(eg. read, setpgid), otherwise -EIO is used if we couldn't communicate with
the parent.

The latter case is a bit useless, since the parent probably won't see
the error anyway, but it's neater.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
server/eventscript.c

index bd42ed6d524976d9479e55692f546cf40e339b17..940b49ec7b44662a76daf67a94e0f79a45e24cf5 100644 (file)
@@ -460,9 +460,8 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
                }
 
                if (ctdb_ctrl_event_script_init(ctdb) != 0) {
-                       DEBUG(DEBUG_ERR,(__location__ " Failed to init event script monitoring\n"));
-                       talloc_free(tmp_ctx);
-                       return -1;
+                       ret = -EIO;
+                       goto out;
                }
        }
 
@@ -478,16 +477,16 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
                if (i == ARRAY_SIZE(allowed_calls)) {
                        DEBUG(DEBUG_ERR,("Refusing to run event scripts call '%s' while in recovery\n",
                                 call_names[call]));
-                       talloc_free(tmp_ctx);
-                       return -1;
+                       ret = -EBUSY;
+                       goto out;
                }
        }
 
        if (setpgid(0,0) != 0) {
+               ret = -errno;
                DEBUG(DEBUG_ERR,("Failed to create process group for event scripts - %s\n",
                         strerror(errno)));
-               talloc_free(tmp_ctx);
-               return -1;              
+               goto out;
        }
 
        signal(SIGTERM, sigterm);
@@ -530,16 +529,14 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
 
                if (!from_user && call == CTDB_EVENT_MONITOR) {
                        if (ctdb_ctrl_event_script_start(ctdb, current->name) != 0) {
-                               DEBUG(DEBUG_ERR,(__location__ " Failed to start event script monitoring\n"));
-                               talloc_free(tmp_ctx);
-                               return -1;
+                               ret = -EIO;
+                               goto out;
                        }
 
                        if (current->error) {
                                if (ctdb_ctrl_event_script_stop(ctdb, -current->error) != 0) {
-                                       DEBUG(DEBUG_ERR,(__location__ " Failed to report disabled eventscript\n"));
-                                       talloc_free(tmp_ctx);
-                                       return -1;
+                                       ret = -EIO;
+                                       goto out;
                                }
                        }
                }
@@ -571,9 +568,8 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
  
                if (!from_user && call == CTDB_EVENT_MONITOR) {
                        if (ctdb_ctrl_event_script_stop(ctdb, ret) != 0) {
-                               DEBUG(DEBUG_ERR,(__location__ " Failed to stop event script monitoring\n"));
-                               talloc_free(tmp_ctx);
-                               return -1;
+                               ret = -EIO;
+                               goto out;
                        }
                }
 
@@ -594,12 +590,11 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
        
        if (!from_user && call == CTDB_EVENT_MONITOR) {
                if (ctdb_ctrl_event_script_finished(ctdb) != 0) {
-                       DEBUG(DEBUG_ERR,(__location__ " Failed to finish event script monitoring\n"));
-                       talloc_free(tmp_ctx);
-                       return -1;
+                       ret = -EIO;
                }
        }
 
+out:
        talloc_free(tmp_ctx);
        return ret;
 }
@@ -611,10 +606,13 @@ static void ctdb_event_script_handler(struct event_context *ev, struct fd_event
        struct ctdb_event_script_state *state = 
                talloc_get_type(p, struct ctdb_event_script_state);
        struct ctdb_context *ctdb = state->ctdb;
+       int r;
 
-       if (read(state->fd[0], &state->cb_status, sizeof(state->cb_status)) !=
-           sizeof(state->cb_status)) {
-               state->cb_status = -2;
+       r = read(state->fd[0], &state->cb_status, sizeof(state->cb_status));
+       if (r < 0) {
+               state->cb_status = -errno;
+       } else if (r != sizeof(state->cb_status)) {
+               state->cb_status = -EIO;
        }
 
        DEBUG(DEBUG_INFO,(__location__ " Eventscript %s %s finished with state %d\n",