diff options
| author | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2009-04-01 19:46:01 -0400 |
|---|---|---|
| committer | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2009-04-01 19:46:01 -0400 |
| commit | 26036576cc67ee3552ed3ee5648f33c07b811254 (patch) | |
| tree | ab33df5ffab5a1a32b909de01436a01b5a3efe5b /src | |
| parent | e9e45b52a7ccf311b98683ca2e3ee241a0ec8c08 (diff) | |
| download | credmonger-26036576cc67ee3552ed3ee5648f33c07b811254.tar.gz credmonger-26036576cc67ee3552ed3ee5648f33c07b811254.tar.xz credmonger-26036576cc67ee3552ed3ee5648f33c07b811254.zip | |
- clean up the organization of things, add a simple daemon mode and pid
file
Diffstat (limited to 'src')
| -rw-r--r-- | src/credmonger.c | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/src/credmonger.c b/src/credmonger.c index 9af86bd..c4d8fbc 100644 --- a/src/credmonger.c +++ b/src/credmonger.c @@ -79,6 +79,11 @@ entries_read(void) fccache_pattern = strchr(principal, ':'); if (fccache_pattern != NULL) { *fccache_pattern++ = '\0'; + /* Close the principal name. */ + p = strchr(fccache_pattern, ':'); + if (p != NULL) { + *p++ = '\0'; + } } /* Now figure out the UID/GID. */ uid = (uid_t) strtol(uids, &p, 10); @@ -481,16 +486,63 @@ setquit(int signum) int main(int argc, char **argv) { - time_t now, howlong; + time_t howlong; + char *pidfile; + int c, nofork; + FILE *fp; + + nofork = 0; + pidfile = NULL; + while ((c = getopt(argc, argv, "np:")) != -1) { + switch (c) { + case 'n': + nofork++; + break; + case 'p': + pidfile = optarg; + break; + default: + break; + } + } + + if (!nofork) { + daemon(0, 0); + } + 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 = -1; while (quit == 0) { - entries_reload(); - now = time(NULL); + /* Either (re-)initialize, or don't. */ + if (howlong == 0) { + /* Normal. */ + entries_poll(); + } else { + /* Load or reload configuration. */ + entries_reload(); + } + /* If there are no entries, bail. */ + if (entries == NULL) { + break; + } + /* Figure out how long to wait. */ howlong = entries_waittime(); fprintf(stderr, "Waiting for %ld seconds.\n", (long) howlong); - sleep(howlong); + howlong = sleep(howlong); }; + /* Clean up. */ entries_unload(); + if (pidfile != NULL) { + fprintf(stderr, "Removing \"%s\".\n", pidfile); + unlink(pidfile); + } return 0; } |
