]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Add --pid-file option to kpropd 703/head
authorGreg Hudson <ghudson@mit.edu>
Mon, 18 Sep 2017 22:34:42 +0000 (18:34 -0400)
committerGreg Hudson <ghudson@mit.edu>
Fri, 22 Sep 2017 16:52:55 +0000 (12:52 -0400)
ticket: 8607

doc/admin/admin_commands/kpropd.rst
src/slave/kpropd.c

index 5e01e2f14bc1d6f7ef74f7ffcf829a3e8e23cd63..5468b06754e16f89c88fcd1c9f76881690ec8797 100644 (file)
@@ -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
 -----------
index feb1fd1efa987d1455167986e0881c9cbe7b4bbf..d621f108f3fa13fea229127178b18d5b87beb7d2 100644 (file)
@@ -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();
         }