diff options
| author | Russ Allbery <rra@stanford.edu> | 2010-01-01 05:09:57 +0000 |
|---|---|---|
| committer | Russ Allbery <rra@stanford.edu> | 2010-01-01 05:09:57 +0000 |
| commit | b54e343cb8b672585875fa7400a08ea338b1500d (patch) | |
| tree | 356cf8a95bc565e066ddd95e1a31b936d06259da /src/kadmin/server | |
| parent | ebfd96a98ccb8f7df042cadbeefa00ee4761b9fa (diff) | |
| download | krb5-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/kadmin/server')
| -rw-r--r-- | src/kadmin/server/kadmind.M | 9 | ||||
| -rw-r--r-- | src/kadmin/server/ovsec_kadmd.c | 50 |
2 files changed, 59 insertions, 0 deletions
diff --git a/src/kadmin/server/kadmind.M b/src/kadmin/server/kadmind.M index 2a227fb4e..3e9d87638 100644 --- a/src/kadmin/server/kadmind.M +++ b/src/kadmin/server/kadmind.M @@ -5,6 +5,7 @@ kadmind \- KADM5 administration server .B kadmind [\fB\-x\fP \fIdb_args\fP] [\fB-r\fP \fIrealm\fP] [\fB\-m\fP] [\fB\-nofork\fP] [\fB\-port\fP \fIport-number\fP] + [\fB\-P\fP \fIpid_file\fP] .SH DESCRIPTION This command starts the KADM5 administration server. If the database is db2, the administration server runs on the master Kerberos server, which stores the KDC @@ -122,6 +123,14 @@ specifies the port on which the administration server listens for connections. The default is is controlled by the .I kadmind_port configuration variable (see below). +.TP +\fB\-P\fP \fIpid_file\fP +specifies the file to which the PID of +.B kadmind +process should be written to after it starts up. This can be used to +identify whether +.B kadmind +is still running and to allow init scripts to stop the correct process. .SH CONFIGURATION VALUES .PP In addition to the relations defined in kdc.conf(5), kadmind diff --git a/src/kadmin/server/ovsec_kadmd.c b/src/kadmin/server/ovsec_kadmd.c index 1615877fb..e32a08937 100644 --- a/src/kadmin/server/ovsec_kadmd.c +++ b/src/kadmin/server/ovsec_kadmd.c @@ -30,6 +30,7 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ +#include <errno.h> #include <stdio.h> #include <signal.h> #include <syslog.h> @@ -134,6 +135,7 @@ static void usage() "[-passwordserver] " #endif "[-port port-number]\n" + "\t\t[-P pid_file]\n" "\nwhere,\n\t[-x db_args]* - any number of database specific arguments.\n" "\t\t\tLook at each database documentation for supported arguments\n" ); @@ -191,6 +193,36 @@ static void display_status_1(m, code, type) } } +/* + * Function: write_pid_file + * + * Purpose: writes the current process PID to a file + * + * Arguments: + * + * pid_file path to output file + * <return value> 0 on success, error code on failure + * + * Effects: + * + * The current process PID, obtained from getpid(), is written to the path + * given in pid_file, overwriting the existing contents if the file already + * exists. The PID will be followed by a newline. + */ +static int +write_pid_file(const char *pid_file) +{ + FILE *file; + unsigned long pid; + + file = fopen(pid_file, "w"); + if (file == NULL) + return errno; + pid = (unsigned long) getpid(); + if (fprintf(file, "%ld\n", pid) < 0 || fclose(file) == EOF) + return errno; + return 0; +} /* XXX yuck. the signal handlers need this */ static krb5_context context; @@ -216,6 +248,7 @@ int main(int argc, char *argv[]) char *errmsg; int i; int strong_random = 1; + const char *pid_file = NULL; kdb_log_context *log_ctx; @@ -286,6 +319,11 @@ int main(int argc, char *argv[]) usage(); params.kadmind_port = atoi(*argv); params.mask |= KADM5_CONFIG_KADMIND_PORT; + } else if (strcmp(*argv, "-P") == 0) { + argc--; argv++; + if (!argc) + usage(); + pid_file = *argv; } else if (strcmp(*argv, "-W") == 0) { strong_random = 0; } else @@ -468,6 +506,18 @@ kterr: krb5_klog_close(context); exit(1); } + if (pid_file != NULL) { + ret = write_pid_file(pid_file); + if (ret) { + errmsg = krb5_get_error_message(context, ret); + krb5_klog_syslog(LOG_ERR, "Cannot create PID file %s: %s", + pid_file, errmsg); + svcauth_gssapi_unset_names(); + kadm5_destroy(global_server_handle); + krb5_klog_close(context); + exit(1); + } + } krb5_klog_syslog(LOG_INFO, "Seeding random number generator"); ret = krb5_c_random_os_entropy(context, strong_random, NULL); |
