X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=proto-shell.c;h=977cdbceedc8d69639dd79082838610a325cf0bc;hp=86933b026efd22680d51041016e83127b778fd64;hb=3c4a49e215379ea207c38c08e990a89b31be3f36;hpb=069b6b830492109f3e880063f7f52ce2329cb9b6 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);