summaryrefslogtreecommitdiff
path: root/accel-pppd/main.c
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2016-03-18 19:37:19 +0300
committerDmitry Kozlov <xeb@mail.ru>2016-03-18 19:37:19 +0300
commit65c90307db554663964f1aa2624630433a98d040 (patch)
tree5afe7c8ee96f188bc3c63e476b7e17ef839232c0 /accel-pppd/main.c
parente7d6fe6a72d0e03b1c63d070ff6e2f187a40f02a (diff)
downloadaccel-ppp-65c90307db554663964f1aa2624630433a98d040.tar.gz
accel-ppp-65c90307db554663964f1aa2624630433a98d040.zip
improved restart and termination procedure
Diffstat (limited to 'accel-pppd/main.c')
-rw-r--r--accel-pppd/main.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/accel-pppd/main.c b/accel-pppd/main.c
index 66737248..02ada1d1 100644
--- a/accel-pppd/main.c
+++ b/accel-pppd/main.c
@@ -37,6 +37,10 @@ static char *conf_dump;
static sigset_t orig_set;
static char **argv;
static int argc;
+static int restart = -1;
+static int term;
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
#ifdef CRYPTO_OPENSSL
#include <openssl/ssl.h>
@@ -131,7 +135,7 @@ static void close_all_fd(void)
closedir(dirp);
}
-void core_restart(int soft)
+static void __core_restart(int soft)
{
char exe[PATH_MAX];
@@ -153,6 +157,16 @@ void core_restart(int soft)
}
}
+void core_restart(int soft)
+{
+#ifdef USE_BACKUP
+ if (soft)
+ __core_restart(1);
+#endif
+ restart = soft;
+ kill(getpid(), SIGTERM);
+}
+
static void sigsegv(int num)
{
char cmd[PATH_MAX];
@@ -191,7 +205,7 @@ out:
pid = fork();
if (pid) {
waitpid(pid, &status, 0);
- core_restart(1);
+ __core_restart(1);
}
if (conf_dump) {
@@ -204,6 +218,14 @@ out:
abort();
}
+static void shutdown_cb()
+{
+ pthread_mutex_lock(&lock);
+ term = 1;
+ pthread_cond_signal(&cond);
+ pthread_mutex_unlock(&lock);
+}
+
int main(int _argc, char **_argv)
{
sigset_t set;
@@ -336,11 +358,18 @@ 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);
+ ap_shutdown_soft(shutdown_cb, 1);
+
+ pthread_mutex_lock(&lock);
+ while (!term)
+ pthread_cond_wait(&cond, &lock);
+ pthread_mutex_unlock(&lock);
triton_terminate();
+ if (restart != -1)
+ __core_restart(restart);
+
if (pid_file)
unlink(pid_file);