diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2014-12-04 12:07:17 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2014-12-08 18:13:45 +0100 |
commit | 3c4a49e215379ea207c38c08e990a89b31be3f36 (patch) | |
tree | a04f1aa0ce4a90c70bbff3a9088626cef5415d37 /proto-shell.c | |
parent | 069b6b830492109f3e880063f7f52ce2329cb9b6 (diff) |
netifd: Make possible state transitions more clear when handling teardown event
Improve code readibility regarding state transitions when handling teardown event
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'proto-shell.c')
-rw-r--r-- | proto-shell.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/proto-shell.c b/proto-shell.c index 86933b0..977cdbc 100644 --- a/proto-shell.c +++ b/proto-shell.c @@ -184,28 +184,35 @@ proto_shell_handler(struct interface_proto_state *proto, state->renew_pending = false; action = "renew"; } else { - if (state->sm == S_TEARDOWN) - return 0; - - state->renew_pending = false; - if (state->script_task.uloop.pending) { - if (state->sm != S_SETUP_ABORT) { + switch (state->sm) { + case S_SETUP: + if (state->script_task.uloop.pending) { uloop_timeout_set(&state->teardown_timeout, 1000); kill(state->script_task.uloop.pid, SIGTERM); if (state->proto_task.uloop.pending) kill(state->proto_task.uloop.pid, SIGTERM); + state->renew_pending = false; state->sm = S_SETUP_ABORT; + return 0; + } + /* fall through if no script task is running */ + case S_IDLE: + action = "teardown"; + state->renew_pending = false; + state->sm = S_TEARDOWN; + if (state->last_error >= 0) { + snprintf(error_buf, sizeof(error_buf), "ERROR=%d", state->last_error); + envp[j++] = error_buf; } + uloop_timeout_set(&state->teardown_timeout, 5000); + break; + + case S_TEARDOWN: return 0; - } - action = "teardown"; - state->sm = S_TEARDOWN; - if (state->last_error >= 0) { - snprintf(error_buf, sizeof(error_buf), "ERROR=%d", state->last_error); - envp[j++] = error_buf; + default: + return -1; } - uloop_timeout_set(&state->teardown_timeout, 5000); } D(INTERFACE, "run %s for interface '%s'\n", action, proto->iface->name); |