summaryrefslogtreecommitdiffstats
path: root/src/kdc/main.c
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2010-01-01 05:09:57 +0000
committerRuss Allbery <rra@stanford.edu>2010-01-01 05:09:57 +0000
commitb54e343cb8b672585875fa7400a08ea338b1500d (patch)
tree356cf8a95bc565e066ddd95e1a31b936d06259da /src/kdc/main.c
parentebfd96a98ccb8f7df042cadbeefa00ee4761b9fa (diff)
downloadkrb5-b54e343cb8b672585875fa7400a08ea338b1500d.tar.gz
krb5-b54e343cb8b672585875fa7400a08ea338b1500d.tar.xz
krb5-b54e343cb8b672585875fa7400a08ea338b1500d.zip
Add a new -P option to krb5kdc and kadmind which, if given, specifies
the path to which to write the PID file of the daemon after it finishes initializing. Ticket: 6618 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23560 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/kdc/main.c')
-rw-r--r--src/kdc/main.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/kdc/main.c b/src/kdc/main.c
index 925019c4be..9fd63756d6 100644
--- a/src/kdc/main.c
+++ b/src/kdc/main.c
@@ -59,6 +59,7 @@
#include <signal.h>
#include <errno.h>
#include <netdb.h>
+#include <unistd.h>
#include "k5-int.h"
#include "com_err.h"
@@ -90,6 +91,7 @@ void initialize_realms (krb5_context, int, char **);
void finish_realms (void);
static int nofork = 0;
+static const char *pid_file = NULL;
static int rkey_init_done = 0;
#ifdef POSIX_SIGNALS
@@ -558,7 +560,7 @@ setup_sam(void)
void
usage(char *name)
{
- fprintf(stderr, "usage: %s [-x db_args]* [-d dbpathname] [-r dbrealmname]\n\t\t[-R replaycachename] [-m] [-k masterenctype] [-M masterkeyname]\n\t\t[-p port] [/]\n"
+ fprintf(stderr, "usage: %s [-x db_args]* [-d dbpathname] [-r dbrealmname]\n\t\t[-R replaycachename] [-m] [-k masterenctype] [-M masterkeyname]\n\t\t[-p port] [-P pid_file] [/]\n"
"\nwhere,\n\t[-x db_args]* - Any number of database specific arguments. Look at\n"
"\t\t\teach database module documentation for supported\n\t\t\targuments\n",
name);
@@ -634,7 +636,7 @@ initialize_realms(krb5_context kcontext, int argc, char **argv)
* Loop through the option list. Each time we encounter a realm name,
* use the previously scanned options to fill in for defaults.
*/
- while ((c = getopt(argc, argv, "x:r:d:mM:k:R:e:p:s:n4:X3")) != -1) {
+ while ((c = getopt(argc, argv, "x:r:d:mM:k:R:e:P:p:s:n4:X3")) != -1) {
switch(c) {
case 'x':
db_args_size++;
@@ -723,6 +725,8 @@ initialize_realms(krb5_context kcontext, int argc, char **argv)
case 'R':
rcname = optarg;
break;
+ case 'P':
+ pid_file = optarg;
case 'p':
if (default_udp_ports)
free(default_udp_ports);
@@ -803,6 +807,21 @@ initialize_realms(krb5_context kcontext, int argc, char **argv)
return;
}
+static krb5_error_code
+write_pid_file(const char *path)
+{
+ FILE *file;
+ unsigned long pid;
+
+ file = fopen(path, "w");
+ if (file == NULL)
+ return errno;
+ pid = (unsigned long) getpid();
+ if (fprintf(file, "%ld\n", pid) < 0 || fclose(file) == EOF)
+ return errno;
+ return 0;
+}
+
void
finish_realms()
{
@@ -905,6 +924,14 @@ int main(int argc, char **argv)
finish_realms();
return 1;
}
+ if (pid_file != NULL) {
+ retval = write_pid_file(pid_file);
+ if (retval) {
+ kdc_err(kcontext, retval, "while creating PID file");
+ finish_realms();
+ return 1;
+ }
+ }
krb5_klog_syslog(LOG_INFO, "commencing operation");
if (nofork)
fprintf(stderr, "%s: starting...\n", kdc_progname);