krb5 commit: Add --pid-file option to kpropd

Greg Hudson ghudson at mit.edu
Fri Sep 22 13:19:19 EDT 2017


https://github.com/krb5/krb5/commit/99f631ac5f7dfb6a9a9c77b2ce46c8fb3e8943cf
commit 99f631ac5f7dfb6a9a9c77b2ce46c8fb3e8943cf
Author: Greg Hudson <ghudson at mit.edu>
Date:   Mon Sep 18 18:34:42 2017 -0400

    Add --pid-file option to kpropd
    
    ticket: 8607

 doc/admin/admin_commands/kpropd.rst |    5 ++++
 src/slave/kpropd.c                  |   36 +++++++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/doc/admin/admin_commands/kpropd.rst b/doc/admin/admin_commands/kpropd.rst
index 5e01e2f..5468b06 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 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(&params, 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();
         }


More information about the cvs-krb5 mailing list