[openbnc-cvs] openbnc/src openbnc.c,1.7,1.8
Status: Beta
Brought to you by:
andrereis
From: Mateusz K. <sh...@us...> - 2004-07-06 19:37:21
|
Update of /cvsroot/openbnc/openbnc/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14275/openbnc/src Modified Files: openbnc.c Log Message: - Add --pid-file | -p to command line ( write pid to specified file ) Index: openbnc.c =================================================================== RCS file: /cvsroot/openbnc/openbnc/src/openbnc.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- openbnc.c 6 Jul 2004 13:47:50 -0000 1.7 +++ openbnc.c 6 Jul 2004 19:37:12 -0000 1.8 @@ -228,7 +228,7 @@ { int rc; char *pt; - char buf[200]; + char buf[200],t_pid[200]; char *bversion; FILE *pidfile,*conffile; int i,t_uid,t_gid=0; @@ -239,11 +239,13 @@ strcpy(configfile,"openbnc.conf"); } */ + + + strcpy(configfile,"openbnc.conf"); - - /* Checking parametrs */ + /* Checking parametrs */ if ( argc > 1 ) { @@ -265,6 +267,22 @@ } } + /* --pid-file | -p - Write pid to specified file */ + if ( !strcasecmp("--pid-file",argv[i]) || !strcasecmp("-p",argv[i]) ) { + if ( argv[i+1] != NULL ) { + + if ( strlen(argv[i+1]) < 201 ) { + strcpy(t_pid,argv[i+1]); + } else { + printf("ERROR: Pid file name too long!\n"); + } + + } else { + printf("ERROR: --pid-file without parametr!\n"); + exit(127); + } + } + /* --help | -h - Display Help */ if ( !strcasecmp("--help",argv[i]) || !strcasecmp("-h",argv[i]) ) { printf("%s %s\n\n",APPNAME,APPVER); @@ -273,6 +291,7 @@ printf("-h, --help Display help and exit\n"); printf("-v, --version Display Version and exit\n"); printf("-c, --config [file] Read configuration from specified file\n"); + printf("-p, --pid-file [file] Write pid to specified file\n"); printf("-u, --user [user] Run as specific user [*]\n"); printf("-g, --group [group] Run as specific group [*]\n"); printf("-l, --user-limit Max no. of users\n"); @@ -406,12 +425,19 @@ exit (0x0); } /* creating background */ - pidfile = fopen(lngtxt(1003),"w"); - if(pidfile==NULL) - { - printf(lngtxt(1004)); - exit(0x0); - } + + /* UGLY! */ + if ( t_pid == NULL ) { + pidfile = fopen(lngtxt(1003),"w"); + } else { + pidfile = fopen(t_pid,"w"); + } + + if(pidfile==NULL) + { + printf(lngtxt(1004)); + exit(0x0); + } if(mainlog!=NULL) { fclose(mainlog); |