From 209e0af265275f43f02d6c1f3a5f012f707f5eaf Mon Sep 17 00:00:00 2001 From: Johan Danielsson Date: Fri, 4 Aug 2000 09:48:26 +0000 Subject: [PATCH] add pidfile function git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8889 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/roken/write_pid.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/roken/write_pid.c b/lib/roken/write_pid.c index 71e1f766e..e5b72d615 100644 --- a/lib/roken/write_pid.c +++ b/lib/roken/write_pid.c @@ -49,7 +49,7 @@ pid_file_write (const char *progname) FILE *fp; char *ret; - asprintf (&ret, _PATH_VARRUN "%s.pid", progname); + asprintf (&ret, "%s%s.pid", _PATH_VARRUN, progname); if (ret == NULL) return NULL; fp = fopen (ret, "w"); @@ -71,3 +71,23 @@ pid_file_delete (char **filename) *filename = NULL; } } + +static char *pidfile_path; + +static void +pidfile_cleanup(void) +{ + if(pidfile_path != NULL) + pid_file_delete(&pidfile_path); +} + +void +pidfile(const char *basename) +{ + if(pidfile_path != NULL) + return; + if(basename == NULL) + basename = __progname; + pidfile_path = pid_file_write(basename); + atexit(pidfile_cleanup); +}