diff options
author | William Hubbs <w.d.hubbs@gmail.com> | 2017-08-23 14:16:49 -0500 |
---|---|---|
committer | William Hubbs <w.d.hubbs@gmail.com> | 2017-08-23 14:36:50 -0500 |
commit | cfbe9c2ede24dac530ef58e5c35bd57f22a788a3 (patch) | |
tree | 6b98d014c8e40c7b6eaa2f5d30150ed90e1ebd88 /src/rc/rc-misc.c | |
parent | df28002b728b033c00c2da64dedf2bcd4ab5e11b (diff) |
move get_pid function to a shared file
Diffstat (limited to 'src/rc/rc-misc.c')
-rw-r--r-- | src/rc/rc-misc.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c index a6cc788e..d43f1274 100644 --- a/src/rc/rc-misc.c +++ b/src/rc/rc-misc.c @@ -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; +} |