diff options
author | Greg Hudson <ghudson@mit.edu> | 2017-09-18 18:34:42 -0400 |
---|---|---|
committer | Greg Hudson <ghudson@mit.edu> | 2017-09-22 12:52:55 -0400 |
commit | 99f631ac5f7dfb6a9a9c77b2ce46c8fb3e8943cf (patch) | |
tree | a8591e1e3479e202af2a6d162b9bb433866ca0eb /src/slave | |
parent | 8f86903a4023113d1c63de996c03a3ee2377ccb4 (diff) | |
download | krb5-99f631ac5f7dfb6a9a9c77b2ce46c8fb3e8943cf.zip krb5-99f631ac5f7dfb6a9a9c77b2ce46c8fb3e8943cf.tar.gz krb5-99f631ac5f7dfb6a9a9c77b2ce46c8fb3e8943cf.tar.bz2 |
Add --pid-file option to kpropd
ticket: 8607
Diffstat (limited to 'src/slave')
-rw-r--r-- | src/slave/kpropd.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/slave/kpropd.c b/src/slave/kpropd.c index feb1fd1..d621f10 100644 --- a/src/slave/kpropd.c +++ b/src/slave/kpropd.c @@ -119,6 +119,7 @@ static int debug = 0; static int nodaemon = 0; static char *srvtab = NULL; static int standalone = 0; +static const char *pid_file = NULL; static pid_t fullprop_child = (pid_t)-1; @@ -171,10 +172,25 @@ usage() progname); fprintf(stderr, _("\t[-F kerberos_db_file ] [-p kdb5_util_pathname]\n")); fprintf(stderr, _("\t[-x db_args]* [-P port] [-a acl_file]\n")); - fprintf(stderr, _("\t[-A admin_server]\n")); + fprintf(stderr, _("\t[-A admin_server] [--pid-file=pid_file]\n")); exit(1); } +static krb5_error_code +write_pid_file(const char *path) +{ + FILE *fp; + unsigned long pid; + + fp = fopen(path, "w"); + if (fp == NULL) + return errno; + pid = (unsigned long)getpid(); + if (fprintf(fp, "%ld\n", pid) < 0 || fclose(fp) == EOF) + return errno; + return 0; +} + typedef void (*sig_handler_fn)(int sig); static void @@ -262,6 +278,14 @@ main(int argc, char **argv) printf(_("ready\n")); fflush(stdout); } + if (pid_file != NULL) { + retval = write_pid_file(pid_file); + if (retval) { + syslog(LOG_ERR, _("Could not write pid file %s: %s"), + pid_file, strerror(errno)); + exit(1); + } + } } else { /* * We're an inetd nowait service. Let's not risk anything @@ -1020,6 +1044,10 @@ parse_args(int argc, char **argv) char **newargs; int c; krb5_error_code retval; + enum { PID_FILE = 256 }; + struct option long_options[] = { + { "pid-file", 1, NULL, PID_FILE }, + }; memset(¶ms, 0, sizeof(params)); @@ -1032,7 +1060,8 @@ parse_args(int argc, char **argv) } progname = argv[0]; - while ((c = getopt(argc, argv, "A:f:F:p:P:r:s:DdSa:tx:")) != -1) { + while ((c = getopt_long(argc, argv, "A:f:F:p:P:r:s:DdSa:tx:", + long_options, NULL)) != -1) { switch (c) { case 'A': params.mask |= KADM5_CONFIG_ADMIN_SERVER; @@ -1084,6 +1113,9 @@ parse_args(int argc, char **argv) db_args[db_args_size + 1] = NULL; db_args_size++; break; + case PID_FILE: + pid_file = optarg; + break; default: usage(); } |