diff options
| author | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2009-04-02 16:27:47 -0400 |
|---|---|---|
| committer | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2009-04-02 16:27:47 -0400 |
| commit | d35c014630633a3548d3ebc9a4dd3ea6993ec265 (patch) | |
| tree | 0936c65fa3809c54d5377ac5fb8bfa7a89ccd4b3 /src/credmonger.c | |
| parent | 318d43b46c3546bc9dac7be343ec4858ce0007ad (diff) | |
| download | credmonger-d35c014630633a3548d3ebc9a4dd3ea6993ec265.tar.gz credmonger-d35c014630633a3548d3ebc9a4dd3ea6993ec265.tar.xz credmonger-d35c014630633a3548d3ebc9a4dd3ea6993ec265.zip | |
- add an autogen script
- catch SIGHUP for reload correctly
- use killproc correctly for reloading
Diffstat (limited to 'src/credmonger.c')
| -rw-r--r-- | src/credmonger.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/credmonger.c b/src/credmonger.c index 4bef2ca..aff8c40 100644 --- a/src/credmonger.c +++ b/src/credmonger.c @@ -59,6 +59,8 @@ static struct monger_entry { krb5_timestamp when; /* When the creds in the ccache expire. */ } **entries, **cleanup; +/* Time to reload. */ +static int reload = 0; /* Time to exit. */ static int quit = 0; @@ -568,6 +570,12 @@ entries_waittime(void) } static void +setreload(int signum) +{ + reload++; +} + +static void setquit(int signum) { quit++; @@ -604,12 +612,14 @@ main(int argc, char **argv) } } + /* Load the configuration. */ entries = entries_read(); if (entries == NULL) { log_err(LOG_ERR, "nothing configured\n"); return 1; } + /* Go background. */ if (!nofork) { if (daemon(0, 0) != 0) { log_err(LOG_ERR, "error going to background: %s\n", @@ -618,34 +628,36 @@ main(int argc, char **argv) } } + /* Write the pidfile. */ fp = fopen(pidfile, "w"); if (fp != NULL) { fprintf(fp, "%lu\n", (long unsigned) (getpid())); fclose(fp); } - signal(SIGINT, setquit); - signal(SIGQUIT, setquit); - - /* Make sure we initialize the first time through. */ - howlong = 0; + /* Make sure we don't reinitialize the first time through. */ + reload = 0; while (quit == 0) { /* Either (re-)initialize, or don't. */ - if (howlong == 0) { - /* Normal. */ - entries_poll(); - } else { + if (reload) { /* Load or reload configuration. */ + reload = 0; entries_reload(); - } - /* If there are no entries, bail. */ - if (entries == NULL) { - break; + /* If there are no entries now, bail. */ + if (entries == NULL) { + break; + } + } else { + /* Just run through the entries. */ + entries_poll(); } /* Figure out how long to wait. */ howlong = entries_waittime(); log_err(LOG_DEBUG, "waiting for %ld seconds\n", (long) howlong); + signal(SIGHUP, setreload); + signal(SIGINT, setquit); + signal(SIGQUIT, setquit); howlong = sleep(howlong); }; /* Clean up. */ |
