diff options
-rw-r--r-- | accel-pppd/cli/std_cmd.c | 6 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.c | 4 | ||||
-rw-r--r-- | accel-pppd/include/ap_session.h | 2 | ||||
-rw-r--r-- | accel-pppd/main.c | 6 | ||||
-rw-r--r-- | accel-pppd/session.c | 20 |
5 files changed, 30 insertions, 8 deletions
diff --git a/accel-pppd/cli/std_cmd.c b/accel-pppd/cli/std_cmd.c index 38e6a8b..2f5af8a 100644 --- a/accel-pppd/cli/std_cmd.c +++ b/accel-pppd/cli/std_cmd.c @@ -292,7 +292,7 @@ static int shutdown_exec(const char *cmd, char * const *f, int f_cnt, void *cli) if (f_cnt == 2) { if (!strcmp(f[1], "soft")) { - ap_shutdown_soft(NULL); + ap_shutdown_soft(NULL, 0); return CLI_CMD_OK; } else if (!strcmp(f[1], "hard")) hard = 1; @@ -303,7 +303,7 @@ static int shutdown_exec(const char *cmd, char * const *f, int f_cnt, void *cli) return CLI_CMD_SYNTAX; } - ap_shutdown_soft(NULL); + ap_shutdown_soft(NULL, 0); terminate_all_sessions(hard); @@ -370,7 +370,7 @@ static int restart_exec(const char *cmd, char * const *f, int f_cnt, void *cli) else return CLI_CMD_SYNTAX; - ap_shutdown_soft(restart); + ap_shutdown_soft(restart, 0); terminate_all_sessions(0); return CLI_CMD_OK; diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index c986c63..63df066 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -1097,7 +1097,7 @@ static int ipoe_session_terminate(struct ap_session *s, int hard) { struct ipoe_session *ses = container_of(s, typeof(*ses), ses); - if (hard || !conf_soft_terminate || ses->UP) + if (hard || !conf_soft_terminate || ses->UP || ap_shutdown) ipoe_session_terminated(ses); else ses->terminate = 1; @@ -2068,8 +2068,8 @@ static void ipoe_serv_close(struct triton_context_t *ctx) struct ipoe_serv *serv = container_of(ctx, typeof(*serv), ctx); pthread_mutex_lock(&serv->lock); + serv->need_close = 1; if (!list_empty(&serv->sessions)) { - serv->need_close = 1; pthread_mutex_unlock(&serv->lock); return; } diff --git a/accel-pppd/include/ap_session.h b/accel-pppd/include/ap_session.h index 7a8db12..c6f15dd 100644 --- a/accel-pppd/include/ap_session.h +++ b/accel-pppd/include/ap_session.h @@ -147,6 +147,6 @@ int ap_session_rename(struct ap_session *ses, const char *ifname, int len); int ap_session_read_stats(struct ap_session *ses, struct rtnl_link_stats *stats); -void ap_shutdown_soft(void (*cb)(void)); +int ap_shutdown_soft(void (*cb)(void), int term); #endif diff --git a/accel-pppd/main.c b/accel-pppd/main.c index 9eb08e1..b908fbc 100644 --- a/accel-pppd/main.c +++ b/accel-pppd/main.c @@ -21,10 +21,11 @@ #include "triton/triton.h" -#include "memdebug.h" #include "log.h" #include "events.h" +#include "ap_session.h" #include "backup.h" +#include "memdebug.h" #ifndef ARG_MAX #define ARG_MAX 128*1024 @@ -335,6 +336,9 @@ int main(int _argc, char **_argv) sigwait(&set, &sig); log_info1("terminate, sig = %i\n", sig); + if (ap_shutdown_soft(NULL, 1) == 0) + sigwait(&set, &sig); + triton_terminate(); return EXIT_SUCCESS; diff --git a/accel-pppd/session.c b/accel-pppd/session.c index 1ed1023..1fbac10 100644 --- a/accel-pppd/session.c +++ b/accel-pppd/session.c @@ -292,17 +292,35 @@ void __export ap_session_terminate(struct ap_session *ses, int cause, int hard) } } -void ap_shutdown_soft(void (*cb)(void)) +static void __terminate_soft_reboot(struct ap_session *ses) { + ap_session_terminate(ses, TERM_NAS_REBOOT, 0); +} + +int ap_shutdown_soft(void (*cb)(void), int term) +{ + struct ap_session *ses; + ap_shutdown = 1; shutdown_cb = cb; + pthread_rwlock_rdlock(&ses_lock); + if (!ap_session_stat.starting && !ap_session_stat.active && !ap_session_stat.finishing) { + pthread_rwlock_unlock(&ses_lock); if (shutdown_cb) shutdown_cb(); else kill(getpid(), SIGTERM); + return 1; + } else if (term) { + list_for_each_entry(ses, &ses_list, entry) + triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_soft_reboot, ses); } + + pthread_rwlock_unlock(&ses_lock); + + return 0; } static void generate_sessionid(struct ap_session *ses) |