summaryrefslogtreecommitdiff
path: root/accel-pptpd/main.c
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-09-01 19:29:43 +0400
committerKozlov Dmitry <dima@server>2010-09-01 19:29:43 +0400
commit2b63c6e6e368d6ea39584a70ddb81a88e0924c47 (patch)
tree790cc5d46e691b4b920170b7dfde40d3c6ec4be6 /accel-pptpd/main.c
parent5bac5a2edb7bc7639c853fd0f7109dcddb7c4cee (diff)
downloadaccel-ppp-2b63c6e6e368d6ea39584a70ddb81a88e0924c47.tar.gz
accel-ppp-2b63c6e6e368d6ea39584a70ddb81a88e0924c47.zip
rewriting triton library ...
Diffstat (limited to 'accel-pptpd/main.c')
-rw-r--r--accel-pptpd/main.c82
1 files changed, 78 insertions, 4 deletions
diff --git a/accel-pptpd/main.c b/accel-pptpd/main.c
index ff74305..90f206d 100644
--- a/accel-pptpd/main.c
+++ b/accel-pptpd/main.c
@@ -1,17 +1,82 @@
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/stat.h>
+
#include "triton/triton.h"
-#include "log.h"
void sigterm(int num)
{
- triton_terminate();
}
int main(int argc,char **argv)
{
+ int i;
+ int daemon=0;
+ char *pid_file=NULL;
+ char *conf_file=NULL;
sigset_t set;
- log_init(stdout,4,0);
+ if (argc<2)
+ goto usage;
+
+ for(i=1; i<argc; i++)
+ {
+ if (!strcmp(argv[i],"-d"))
+ 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))
+ return EXIT_FAILURE;
- triton_init();
+ if (daemon)
+ {
+ pid_t pid=fork();
+ if (pid>0)
+ _exit(EXIT_SUCCESS);
+ if (pid<0)
+ {
+ perror("fork");
+ return EXIT_FAILURE;
+ }
+ if (setsid()<0)
+ return EXIT_FAILURE;
+ pid=fork();
+ if (pid)
+ _exit(0);
+ umask(0);
+ chdir("/");
+ close(STDIN_FILENO);
+ close(STDOUT_FILENO);
+ close(STDERR_FILENO);
+ }
+
+ if (pid_file)
+ {
+ FILE *f=fopen("pid_file","w");
+ if (f)
+ {
+ fprintf(f,"%i",getpid());
+ fclose(f);
+ }
+ }
+
triton_run();
signal(SIGTERM,sigterm);
@@ -23,7 +88,16 @@ int main(int argc,char **argv)
sigdelset(&set, SIGBUS);
sigsuspend(&set);
+
+ triton_terminate();
return EXIT_SUCCESS;
+usage:
+ printf("usage: pptpd [-d] [-p <file>] -c <file>\
+ where:\
+ -d - daemon mode\
+ -p - write pid to <file>\
+ -c - config file\n");
+ return EXIT_FAILURE;
}