提交 ecee62f2 编写于 作者: D Dmitry Kozlov

make termination caused by SIGTERM soft

上级 862f1cbf
...@@ -292,7 +292,7 @@ static int shutdown_exec(const char *cmd, char * const *f, int f_cnt, void *cli) ...@@ -292,7 +292,7 @@ static int shutdown_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
if (f_cnt == 2) { if (f_cnt == 2) {
if (!strcmp(f[1], "soft")) { if (!strcmp(f[1], "soft")) {
ap_shutdown_soft(NULL); ap_shutdown_soft(NULL, 0);
return CLI_CMD_OK; return CLI_CMD_OK;
} else if (!strcmp(f[1], "hard")) } else if (!strcmp(f[1], "hard"))
hard = 1; hard = 1;
...@@ -303,7 +303,7 @@ static int shutdown_exec(const char *cmd, char * const *f, int f_cnt, void *cli) ...@@ -303,7 +303,7 @@ static int shutdown_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
return CLI_CMD_SYNTAX; return CLI_CMD_SYNTAX;
} }
ap_shutdown_soft(NULL); ap_shutdown_soft(NULL, 0);
terminate_all_sessions(hard); terminate_all_sessions(hard);
...@@ -370,7 +370,7 @@ static int restart_exec(const char *cmd, char * const *f, int f_cnt, void *cli) ...@@ -370,7 +370,7 @@ static int restart_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
else else
return CLI_CMD_SYNTAX; return CLI_CMD_SYNTAX;
ap_shutdown_soft(restart); ap_shutdown_soft(restart, 0);
terminate_all_sessions(0); terminate_all_sessions(0);
return CLI_CMD_OK; return CLI_CMD_OK;
......
...@@ -1097,7 +1097,7 @@ static int ipoe_session_terminate(struct ap_session *s, int hard) ...@@ -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); 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); ipoe_session_terminated(ses);
else else
ses->terminate = 1; ses->terminate = 1;
...@@ -2068,8 +2068,8 @@ static void ipoe_serv_close(struct triton_context_t *ctx) ...@@ -2068,8 +2068,8 @@ static void ipoe_serv_close(struct triton_context_t *ctx)
struct ipoe_serv *serv = container_of(ctx, typeof(*serv), ctx); struct ipoe_serv *serv = container_of(ctx, typeof(*serv), ctx);
pthread_mutex_lock(&serv->lock); pthread_mutex_lock(&serv->lock);
serv->need_close = 1;
if (!list_empty(&serv->sessions)) { if (!list_empty(&serv->sessions)) {
serv->need_close = 1;
pthread_mutex_unlock(&serv->lock); pthread_mutex_unlock(&serv->lock);
return; return;
} }
......
...@@ -147,6 +147,6 @@ int ap_session_rename(struct ap_session *ses, const char *ifname, int len); ...@@ -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); 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 #endif
...@@ -21,10 +21,11 @@ ...@@ -21,10 +21,11 @@
#include "triton/triton.h" #include "triton/triton.h"
#include "memdebug.h"
#include "log.h" #include "log.h"
#include "events.h" #include "events.h"
#include "ap_session.h"
#include "backup.h" #include "backup.h"
#include "memdebug.h"
#ifndef ARG_MAX #ifndef ARG_MAX
#define ARG_MAX 128*1024 #define ARG_MAX 128*1024
...@@ -335,6 +336,9 @@ int main(int _argc, char **_argv) ...@@ -335,6 +336,9 @@ int main(int _argc, char **_argv)
sigwait(&set, &sig); sigwait(&set, &sig);
log_info1("terminate, sig = %i\n", sig); log_info1("terminate, sig = %i\n", sig);
if (ap_shutdown_soft(NULL, 1) == 0)
sigwait(&set, &sig);
triton_terminate(); triton_terminate();
return EXIT_SUCCESS; return EXIT_SUCCESS;
......
...@@ -292,17 +292,35 @@ void __export ap_session_terminate(struct ap_session *ses, int cause, int hard) ...@@ -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; ap_shutdown = 1;
shutdown_cb = cb; shutdown_cb = cb;
pthread_rwlock_rdlock(&ses_lock);
if (!ap_session_stat.starting && !ap_session_stat.active && !ap_session_stat.finishing) { if (!ap_session_stat.starting && !ap_session_stat.active && !ap_session_stat.finishing) {
pthread_rwlock_unlock(&ses_lock);
if (shutdown_cb) if (shutdown_cb)
shutdown_cb(); shutdown_cb();
else else
kill(getpid(), SIGTERM); 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) static void generate_sessionid(struct ap_session *ses)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册