refactor some code out to write_pidfile() in util.c

This commit is contained in:
Yang Tse
2008-02-26 15:06:44 +00:00
parent 9682c2037e
commit 0d09f342c4
5 changed files with 32 additions and 52 deletions

View File

@@ -222,3 +222,19 @@ int wait_ms(int timeout_ms)
return r;
}
bool write_pidfile(const char *filename)
{
FILE *pidfile;
long pid;
pid = (long)getpid();
pidfile = fopen(filename, "w");
if(!pidfile) {
logmsg("Couldn't write pid file: %s %s", filename, strerror(ERRNO));
return FALSE;
}
fprintf(pidfile, "%ld\n", pid);
fclose(pidfile);
logmsg("Wrote pid %ld to %s", pid, filename);
return true;
}