add pidfile function

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8889 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
2000-08-04 09:48:26 +00:00
parent f17785a56c
commit 209e0af265

View File

@@ -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);
}