move get_pid function to a shared file

This commit is contained in:
William Hubbs
2017-08-23 14:16:49 -05:00
parent df28002b72
commit cfbe9c2ede
4 changed files with 30 additions and 54 deletions

View File

@ -474,3 +474,27 @@ time_t to_time_t(char *timestring)
}
return result;
}
pid_t get_pid(const char *applet,const char *pidfile)
{
FILE *fp;
pid_t pid;
if (! pidfile)
return -1;
if ((fp = fopen(pidfile, "r")) == NULL) {
ewarnv("%s: fopen `%s': %s", applet, pidfile, strerror(errno));
return -1;
}
if (fscanf(fp, "%d", &pid) != 1) {
ewarnv("%s: no pid found in `%s'", applet, pidfile);
fclose(fp);
return -1;
}
fclose(fp);
return pid;
}