diff options
Diffstat (limited to 'accel-pppd/main.c')
-rw-r--r-- | accel-pppd/main.c | 104 |
1 files changed, 32 insertions, 72 deletions
diff --git a/accel-pppd/main.c b/accel-pppd/main.c index c408736..e153caf 100644 --- a/accel-pppd/main.c +++ b/accel-pppd/main.c @@ -14,77 +14,9 @@ #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) -{ - FILE *f; - int i; - size_t len; - - f = fopen("/proc/self/cmdline", "r"); - if (!f) { - perror("open cmdline"); - _exit(EXIT_FAILURE); - } - - *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; - } - - fclose(f); - - return i; -} -static void __init __main(void) -{ - int i,argc; - char **argv; - - argc=parse_cmdline(&argv); - - if (argc < 2) - goto usage; - - for(i = 1; i < argc; i++) { - if (!strcmp(argv[i], "-d")) - goto_daemon = 1; - else if (!strcmp(argv[i], "-p")) { - if (i == argc - 1) - goto usage; - pid_file = argv[++i]; - } else if (!strcmp(argv[i], "-c")) { - if (i == argc - 1) - goto usage; - conf_file = argv[++i]; - } - } - - if (!conf_file) - goto usage; - - 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; @@ -126,7 +58,30 @@ static void config_reload(int num) int main(int argc, char **argv) { sigset_t set; - int sig; + int i, sig, goto_daemon = 0; + + if (argc < 2) + goto usage; + + for(i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-d")) + goto_daemon = 1; + else if (!strcmp(argv[i], "-p")) { + if (i == argc - 1) + goto usage; + pid_file = argv[++i]; + } else if (!strcmp(argv[i], "-c")) { + if (i == argc - 1) + goto usage; + conf_file = argv[++i]; + } + } + + if (!conf_file) + goto usage; + + if (triton_init(conf_file)) + _exit(EXIT_FAILURE); if (goto_daemon) { /*pid_t pid = fork(); @@ -157,9 +112,6 @@ int main(int argc, char **argv) } } - //signal(SIGTERM, sigterm); - //signal(SIGPIPE, sigterm); - change_limits(); if (triton_load_modules("modules")) @@ -206,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); } |