summaryrefslogtreecommitdiff
path: root/accel-pppd/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'accel-pppd/main.c')
-rw-r--r--accel-pppd/main.c113
1 files changed, 41 insertions, 72 deletions
diff --git a/accel-pppd/main.c b/accel-pppd/main.c
index 2e48c45..e153caf 100644
--- a/accel-pppd/main.c
+++ b/accel-pppd/main.c
@@ -14,43 +14,52 @@
#include "log.h"
#include "events.h"
-static int goto_daemon;
static char *pid_file;
static char *conf_file;
-#define ARG_MAX 128
-static int parse_cmdline(char ***argv)
-{
+static void change_limits(void)
+{
FILE *f;
- int i;
- size_t len;
+ struct rlimit lim;
+ unsigned int file_max = 1024*1024;
+ unsigned int nr_open = 1024*1024;
- f = fopen("/proc/self/cmdline", "r");
- if (!f) {
- perror("open cmdline");
- _exit(EXIT_FAILURE);
+ f = fopen("/proc/sys/fs/nr_open", "r");
+ if (f) {
+ fscanf(f, "%d", &nr_open);
+ fclose(f);
}
- *argv = _malloc(ARG_MAX * sizeof(void *));
- memset(*argv, 0, ARG_MAX * sizeof(void *));
-
- for(i = 0; i < ARG_MAX; i++) {
- len = 0;
- if (getdelim(&(*argv)[i], &len, 0, f) < 0)
- break;
+ f = fopen("/proc/sys/fs/file-max", "r");
+ if (f) {
+ fscanf(f, "%d", &file_max);
+ fclose(f);
}
- fclose(f);
+ if (file_max > nr_open)
+ file_max = nr_open;
- return i;
+ lim.rlim_cur = file_max;
+ lim.rlim_max = file_max;
+ if (setrlimit(RLIMIT_NOFILE, &lim))
+ log_emerg("main: setrlimit: %s\n", strerror(errno));
}
-static void __init __main(void)
+
+static void config_reload_notify(int r)
+{
+ if (!r)
+ triton_event_fire(EV_CONFIG_RELOAD, NULL);
+}
+static void config_reload(int num)
{
- int i,argc;
- char **argv;
+ triton_conf_reload(config_reload_notify);
+}
+
+int main(int argc, char **argv)
+{
+ sigset_t set;
+ int i, sig, goto_daemon = 0;
- argc=parse_cmdline(&argv);
-
if (argc < 2)
goto usage;
@@ -74,51 +83,6 @@ static void __init __main(void)
if (triton_init(conf_file))
_exit(EXIT_FAILURE);
- return;
-
-usage:
- printf("usage: accel-pppd [-d] [-p <file>] -c <file>\n\
- where:\n\
- -d - daemon mode\n\
- -p - write pid to <file>\n\
- -c - config file\n");
- _exit(EXIT_FAILURE);
-}
-
-static void change_limits(void)
-{
- FILE *f;
- struct rlimit lim;
- unsigned int file_max;
-
- f = fopen("/proc/sys/fs/file-max", "r");
- if (f) {
- fscanf(f, "%d", &file_max);
- fclose(f);
-
- lim.rlim_cur = file_max;
- lim.rlim_max = file_max;
- if (setrlimit(RLIMIT_NOFILE, &lim))
- log_emerg("main: setrlimit: %s\n", strerror(errno));
- } else
- log_emerg("main: failed to open '/proc/sys/fs/file-max': %s\n", strerror(errno));
-}
-
-static void config_reload_notify(int r)
-{
- if (!r)
- triton_event_fire(EV_CONFIG_RELOAD, NULL);
-}
-static void config_reload(int num)
-{
- triton_conf_reload(config_reload_notify);
-}
-
-int main(int argc, char **argv)
-{
- sigset_t set;
- int sig;
-
if (goto_daemon) {
/*pid_t pid = fork();
if (pid > 0)
@@ -148,9 +112,6 @@ int main(int argc, char **argv)
}
}
- //signal(SIGTERM, sigterm);
- //signal(SIGPIPE, sigterm);
-
change_limits();
if (triton_load_modules("modules"))
@@ -197,5 +158,13 @@ int main(int argc, char **argv)
triton_terminate();
return EXIT_SUCCESS;
+
+usage:
+ printf("usage: accel-pppd [-d] [-p <file>] -c <file>\n\
+ where:\n\
+ -d - daemon mode\n\
+ -p - write pid to <file>\n\
+ -c - config file\n");
+ _exit(EXIT_FAILURE);
}