summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2013-10-16 22:11:28 +0400
committerDmitry Kozlov <xeb@mail.ru>2013-10-16 22:11:28 +0400
commitd30c909bf845e359ec657f294af13d36cce46d06 (patch)
treee8f8d331b5be554714a1e292b1563a30f1159378
parent2598be10d661e2b38831b3489122003111fa7752 (diff)
downloadaccel-ppp-xebd-d30c909bf845e359ec657f294af13d36cce46d06.tar.gz
accel-ppp-xebd-d30c909bf845e359ec657f294af13d36cce46d06.zip
rewrite restart procedure
Signed-off-by: Dmitry Kozlov <xeb@mail.ru>
-rw-r--r--accel-pppd/main.c70
1 files changed, 20 insertions, 50 deletions
diff --git a/accel-pppd/main.c b/accel-pppd/main.c
index 3b94353..7be6767 100644
--- a/accel-pppd/main.c
+++ b/accel-pppd/main.c
@@ -12,6 +12,7 @@
#include <pthread.h>
#include <sys/stat.h>
#include <sys/mman.h>
+#include <sys/wait.h>
#include <sys/resource.h>
#ifdef CRYPTO_OPENSSL
@@ -33,6 +34,8 @@ static char *pid_file;
static char *conf_file;
static char *conf_dump;
static sigset_t orig_set;
+static char **argv;
+static int argc;
#ifdef CRYPTO_OPENSSL
#include <openssl/ssl.h>
@@ -75,7 +78,6 @@ static void change_limits(void)
{
FILE *f;
struct rlimit lim;
- unsigned int file_max = 1024*1024;
unsigned int nr_open = 1024*1024;
f = fopen("/proc/sys/fs/nr_open", "r");
@@ -84,17 +86,8 @@ static void change_limits(void)
fclose(f);
}
- f = fopen("/proc/sys/fs/file-max", "r");
- if (f) {
- fscanf(f, "%d", &file_max);
- fclose(f);
- }
-
- if (file_max > nr_open)
- file_max = nr_open;
-
- lim.rlim_cur = file_max;
- lim.rlim_max = file_max;
+ lim.rlim_cur = nr_open;
+ lim.rlim_max = nr_open;
if (setrlimit(RLIMIT_NOFILE, &lim))
log_emerg("main: setrlimit: %s\n", strerror(errno));
}
@@ -110,7 +103,7 @@ static void config_reload(int num)
triton_conf_reload(config_reload_notify);
}
-/*static void close_all_fd(void)
+static void close_all_fd(void)
{
DIR *dirp;
struct dirent ent, *res;
@@ -135,56 +128,24 @@ static void config_reload(int num)
}
closedir(dirp);
-}*/
+}
void core_restart(int soft)
{
- char fname[128];
- int fd, n, f = 0;
- char cmdline[ARG_MAX];
char exe[PATH_MAX];
- char *argv[16];
- char *ptr = cmdline, *endptr;
-
- if (soft && fork()) {
- //close_all_fd();
- return;
- }
pthread_sigmask(SIG_SETMASK, &orig_set, NULL);
- sprintf(fname, "/proc/%i/cmdline", getpid());
-
- fd = open(fname, O_RDONLY);
- n = read(fd, cmdline, ARG_MAX);
-
- endptr = ptr + n;
-
- n = 0;
- while (ptr < endptr && n < 14) {
- if (strcmp(ptr, "--internal"))
- argv[n++] = ptr;
- else if (soft) {
- f = 1;
- argv[n++] = ptr;
- }
-
- while (ptr < endptr && *ptr++);
- }
-
#ifdef USE_BACKUP
if (soft)
backup_restore_fd();
+ else
#endif
+ close_all_fd();
sprintf(exe, "/proc/%u/exe", getpid());
readlink(exe, exe, PATH_MAX);
- if (!f && soft)
- argv[n++] = "--internal";
-
- argv[n++] = NULL;
-
while (1) {
execv(exe, argv);
sleep(3);
@@ -197,6 +158,8 @@ static void sigsegv(int num)
char fname[128];
char exec_file[PATH_MAX];
struct rlimit lim;
+ pid_t pid;
+ int status;
pthread_sigmask(SIG_SETMASK, &orig_set, NULL);
@@ -224,7 +187,11 @@ static void sigsegv(int num)
}
out:
- core_restart(1);
+ pid = fork();
+ if (pid) {
+ waitpid(pid, &status, 0);
+ core_restart(1);
+ }
if (conf_dump) {
lim.rlim_cur = RLIM_INFINITY;
@@ -236,7 +203,7 @@ out:
abort();
}
-int main(int argc, char **argv)
+int main(int _argc, char **_argv)
{
sigset_t set;
int i, sig, goto_daemon = 0, len;
@@ -245,6 +212,9 @@ int main(int argc, char **argv)
int pagesize = sysconf(_SC_PAGE_SIZE);
int internal = 0;
+ argc = _argc;
+ argv = _argv;
+
if (argc < 2)
goto usage;