diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2009-12-08 12:47:24 +1030 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2009-12-08 12:47:24 +1030 |
commit | 3ff8bf81382b9f14578c479e884eee35941feeb5 (patch) | |
tree | f58263a200623bd754c01aa1f08acb6fdf635503 /ctdb/server/eventscript.c | |
parent | cc678d572fa8fd7add6d41e87d5be70f31a52573 (diff) | |
download | samba-3ff8bf81382b9f14578c479e884eee35941feeb5.tar.gz samba-3ff8bf81382b9f14578c479e884eee35941feeb5.tar.xz samba-3ff8bf81382b9f14578c479e884eee35941feeb5.zip |
eventscript: get_current_script() helper
This neatens the code slightly. We also use the name 'current' in
ctdb_event_script_handler() for uniformity.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(This used to be ctdb commit e9661b383e0c50b9e3d114b7434dfe601aff5744)
Diffstat (limited to 'ctdb/server/eventscript.c')
-rw-r--r-- | ctdb/server/eventscript.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 7f0593a537..6038a9e6e6 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -101,6 +101,11 @@ struct ctdb_scripts { struct ctdb_script scripts[1]; }; +static struct ctdb_script *get_current_script(struct ctdb_event_script_state *state) +{ + return &state->scripts->scripts[state->current]; +} + /* called from ctdb_logging when we have received output on STDERR from * one of the eventscripts */ @@ -108,7 +113,7 @@ static void log_event_script_output(const char *str, uint16_t len, void *p) { struct ctdb_event_script_state *state = talloc_get_type(p, struct ctdb_event_script_state); - struct ctdb_script *current = &state->scripts->scripts[state->current]; + struct ctdb_script *current = get_current_script(state); current->output = talloc_asprintf_append(current->output, "%*.*s", len, len, str); } @@ -443,7 +448,7 @@ static int fork_child_for_script(struct ctdb_context *ctdb, struct ctdb_event_script_state *state) { int r; - struct ctdb_script *current = &state->scripts->scripts[state->current]; + struct ctdb_script *current = get_current_script(state); current->start = timeval_current(); @@ -494,24 +499,24 @@ 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_script *script = &state->scripts->scripts[state->current]; + struct ctdb_script *current = get_current_script(state); struct ctdb_context *ctdb = state->ctdb; int r; - r = read(state->fd[0], &script->status, sizeof(script->status)); + r = read(state->fd[0], ¤t->status, sizeof(current->status)); if (r < 0) { - script->status = -errno; - } else if (r != sizeof(script->status)) { - script->status = -EIO; + current->status = -errno; + } else if (r != sizeof(current->status)) { + current->status = -EIO; } - script->finished = timeval_current(); + current->finished = timeval_current(); /* update overall status based on this script. */ - state->cb_status = script->status; + state->cb_status = current->status; /* don't stop just because it vanished or was disabled. */ - if (script->status == -ENOENT || script->status == -ENOEXEC) { + if (current->status == -ENOENT || current->status == -ENOEXEC) { state->cb_status = 0; } |