--- krb5-1.4.1/src/kadmin/server/ovsec_kadmd.c..pidfile 2004-09-21 22:20:16 +0400 +++ krb5-1.4.1/src/kadmin/server/ovsec_kadmd.c 2005-06-18 20:43:46 +0400 @@ -117,6 +117,9 @@ void kadm5_set_use_password_server (void); #endif +static int pidfd = -1; +static const char *pidfile = "/var/run/kadmind.pid"; + /* * Function: usage * @@ -139,6 +142,32 @@ } /* + * Creates/truncates pidfile + */ +static void create_pidfile(void) +{ + FILE *fp; + + unlink(pidfile); + fp = fopen(pidfile, "w"); + if (!fp) + krb5_klog_syslog(LOG_ERR, "Opening %s failed: %s", + pidfile, error_message(errno)); + + fprintf(fp, "%d\n", getpid()); + pidfd = dup(fileno(fp)); + if (fclose(fp) < 0) + krb5_klog_syslog(LOG_NOTICE, "Flushing pid file %s failed", + pidfile); +} + +static void truncate_pidfile(void) +{ + if (pidfd >= 0) + ftruncate(pidfd, 0); +} + +/* * Function: display_status * * Purpose: displays GSS-API messages @@ -603,6 +632,8 @@ } setup_signal_handlers(); + create_pidfile(); + atexit(truncate_pidfile); krb5_klog_syslog(LOG_INFO, "starting"); kadm_svc_run(¶ms); krb5_klog_syslog(LOG_INFO, "finished, exiting");