From cfbe9c2ede24dac530ef58e5c35bd57f22a788a3 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 23 Aug 2017 14:16:49 -0500 Subject: move get_pid function to a shared file --- src/rc/rc-misc.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/rc/rc-misc.c') 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; +} -- cgit v1.2.3