diff options
author | venaas <venaas> | 2009-02-13 15:54:40 +0000 |
---|---|---|
committer | venaas <venaas@e88ac4ed-0b26-0410-9574-a7f39faa03bf> | 2009-02-13 15:54:40 +0000 |
commit | ccb73e4109f9c1d7318c1b5053ae0ff1cc9f2a99 (patch) | |
tree | cabe9d656259dfc15ef405ddec1e88b10095658a /radsecproxy.c | |
parent | 55be0e6590f835ec7c8c65c88f706a2d3f9edc14 (diff) |
added -i option for pid file, HUP for reopening log file
git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@471 e88ac4ed-0b26-0410-9574-a7f39faa03bf
Diffstat (limited to 'radsecproxy.c')
-rw-r--r-- | radsecproxy.c | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/radsecproxy.c b/radsecproxy.c index 794af5b..97bd560 100644 --- a/radsecproxy.c +++ b/radsecproxy.c @@ -3012,10 +3012,10 @@ void getmainconfig(const char *configfile) { setprotoopts(i, listenargs[i], sourcearg[i]); } -void getargs(int argc, char **argv, uint8_t *foreground, uint8_t *pretend, uint8_t *loglevel, char **configfile) { +void getargs(int argc, char **argv, uint8_t *foreground, uint8_t *pretend, uint8_t *loglevel, char **configfile, char **pidfile) { int c; - while ((c = getopt(argc, argv, "c:d:fpv")) != -1) { + while ((c = getopt(argc, argv, "c:d:i:fpv")) != -1) { switch (c) { case 'c': *configfile = optarg; @@ -3028,6 +3028,9 @@ void getargs(int argc, char **argv, uint8_t *foreground, uint8_t *pretend, uint8 case 'f': *foreground = 1; break; + case 'i': + *pidfile = optarg; + break; case 'p': *pretend = 1; break; @@ -3055,7 +3058,7 @@ void getargs(int argc, char **argv, uint8_t *foreground, uint8_t *pretend, uint8 return; usage: - debugx(1, DBG_ERR, "Usage:\n%s [ -c configfile ] [ -d debuglevel ] [ -f ] [ -p ] [ -v ]", argv[0]); + debugx(1, DBG_ERR, "Usage:\n%s [ -c configfile ] [ -d debuglevel ] [ -f ] [ -i pidfile ] [ -p ] [ -v ]", argv[0]); } #ifdef SYS_SOLARIS9 @@ -3081,13 +3084,17 @@ void *sighandler(void *arg) { for(;;) { sigemptyset(&sigset); + sigaddset(&sigset, SIGHUP); sigaddset(&sigset, SIGPIPE); sigwait(&sigset, &sig); - /* only get SIGPIPE right now, so could simplify below code */ switch (sig) { case 0: /* completely ignoring this */ break; + case SIGHUP: + debug(DBG_INFO, "sighandler: got SIGHUP"); + debug_reopen_log(); + break; case SIGPIPE: debug(DBG_WARN, "sighandler: got SIGPIPE, TLS write error?"); break; @@ -3097,12 +3104,20 @@ void *sighandler(void *arg) { } } +int createpidfile(const char *pidfile) { + int r; + FILE *f = fopen(pidfile, "w"); + if (f) + r = fprintf(f, "%d\n", getpid()); + return f && !fclose(f) && r >= 0; +} + int main(int argc, char **argv) { pthread_t sigth; sigset_t sigset; struct list_node *entry; uint8_t foreground = 0, pretend = 0, loglevel = 0; - char *configfile = NULL; + char *configfile = NULL, *pidfile = NULL; struct clsrvconf *srvconf; int i; @@ -3115,7 +3130,7 @@ int main(int argc, char **argv) { /* needed even if no TLS/DTLS transport */ sslinit(); - getargs(argc, argv, &foreground, &pretend, &loglevel, &configfile); + getargs(argc, argv, &foreground, &pretend, &loglevel, &configfile, &pidfile); if (loglevel) debug_set_level(loglevel); getmainconfig(configfile ? configfile : CONFIG_MAIN); @@ -3140,9 +3155,12 @@ int main(int argc, char **argv) { debug_timestamp_on(); debug(DBG_INFO, "radsecproxy revision $Rev$ starting"); - + if (pidfile && !createpidfile(pidfile)) + debugx(1, DBG_ERR, "failed to create pidfile %s: %s", pidfile, strerror(errno)); + sigemptyset(&sigset); - /* exit on all but SIGPIPE, ignore more? */ + /* exit on all but SIGHUP|SIGPIPE, ignore more? */ + sigaddset(&sigset, SIGHUP); sigaddset(&sigset, SIGPIPE); pthread_sigmask(SIG_BLOCK, &sigset, NULL); pthread_create(&sigth, NULL, sighandler, NULL); |