From: Greg Hudson Date: Mon, 18 Sep 2017 22:34:42 +0000 (-0400) Subject: Add --pid-file option to kpropd X-Git-Tag: krb5-1.16-beta1~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99f631ac5f7dfb6a9a9c77b2ce46c8fb3e8943cf;p=thirdparty%2Fkrb5.git Add --pid-file option to kpropd ticket: 8607 --- diff --git a/doc/admin/admin_commands/kpropd.rst b/doc/admin/admin_commands/kpropd.rst index 5e01e2f14b..5468b06754 100644 --- a/doc/admin/admin_commands/kpropd.rst +++ b/doc/admin/admin_commands/kpropd.rst @@ -14,6 +14,7 @@ SYNOPSIS [**-F** *principal_database*] [**-p** *kdb5_util_prog*] [**-P** *port*] +[**--pid-file**\ =\ *pid_file*] [**-d**] [**-t**] @@ -104,6 +105,10 @@ OPTIONS Allows the user to specify the path to the kpropd.acl file; by default the path used is |kdcdir|\ ``/kpropd.acl``. +**--pid-file**\ =\ *pid_file* + In standalone mode, write the process ID of the daemon into + *pid_file*. + ENVIRONMENT ----------- diff --git a/src/slave/kpropd.c b/src/slave/kpropd.c index feb1fd1efa..d621f108f3 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(); }