summaryrefslogtreecommitdiff
path: root/accel-pppd
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2016-03-18 13:40:07 +0300
committerDmitry Kozlov <xeb@mail.ru>2016-03-18 13:40:07 +0300
commitecee62f204a93c7f512dce46657fbd101d155d78 (patch)
treed2fbe940bd94e7a93310651dceaf7c27e4866b75 /accel-pppd
parent862f1cbfe781098be2263443fc108a46f521a163 (diff)
downloadaccel-ppp-ecee62f204a93c7f512dce46657fbd101d155d78.tar.gz
accel-ppp-ecee62f204a93c7f512dce46657fbd101d155d78.zip
make termination caused by SIGTERM soft
Diffstat (limited to 'accel-pppd')
-rw-r--r--accel-pppd/cli/std_cmd.c6
-rw-r--r--accel-pppd/ctrl/ipoe/ipoe.c4
-rw-r--r--accel-pppd/include/ap_session.h2
-rw-r--r--accel-pppd/main.c6
-rw-r--r--accel-pppd/session.c20
5 files changed, 30 insertions, 8 deletions
diff --git a/accel-pppd/cli/std_cmd.c b/accel-pppd/cli/std_cmd.c
index 38e6a8b6..2f5af8aa 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 c986c63b..63df0660 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 7a8db12b..c6f15dd8 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 9eb08e10..b908fbc6 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 1ed10235..1fbac101 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)