From: "William Hubbs" <williamh@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/openrc:master commit in: src/includes/, src/rc/
Date: Wed, 23 Aug 2017 19:38:12 +0000 (UTC) [thread overview]
Message-ID: <1503517010.cfbe9c2ede24dac530ef58e5c35bd57f22a788a3.williamh@OpenRC> (raw)
commit: cfbe9c2ede24dac530ef58e5c35bd57f22a788a3
Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Wed Aug 23 19:16:49 2017 +0000
Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Wed Aug 23 19:36:50 2017 +0000
URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=cfbe9c2e
move get_pid function to a shared file
src/includes/rc-misc.h | 1 +
src/rc/rc-misc.c | 24 ++++++++++++++++++++++++
src/rc/start-stop-daemon.c | 31 +++----------------------------
src/rc/supervise-daemon.c | 28 ++--------------------------
4 files changed, 30 insertions(+), 54 deletions(-)
diff --git a/src/includes/rc-misc.h b/src/includes/rc-misc.h
index 95ccbc33..9a55c413 100644
--- a/src/includes/rc-misc.h
+++ b/src/includes/rc-misc.h
@@ -71,5 +71,6 @@ bool _rc_can_find_pids(void);
RC_SERVICE lookup_service_state(const char *service);
void from_time_t(char *time_string, time_t tv);
time_t to_time_t(char *timestring);
+pid_t get_pid(const char *applet, const char *pidfile);
#endif
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;
+}
diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index c88bc962..451d4a5c 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -368,31 +368,6 @@ parse_schedule(const char *string, int timeout)
return;
}
-static pid_t
-get_pid(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;
-}
-
/* return number of processed killed, -1 on error */
static int
do_stop(const char *exec, const char *const *argv,
@@ -472,7 +447,7 @@ run_stop_schedule(const char *exec, const char *const *argv,
}
if (pidfile) {
- pid = get_pid(pidfile);
+ pid = get_pid(applet, pidfile);
if (pid == -1)
return 0;
}
@@ -1090,7 +1065,7 @@ int main(int argc, char **argv)
}
if (pidfile)
- pid = get_pid(pidfile);
+ pid = get_pid(applet, pidfile);
else
pid = 0;
@@ -1365,7 +1340,7 @@ int main(int argc, char **argv)
alive = true;
} else {
if (pidfile) {
- pid = get_pid(pidfile);
+ pid = get_pid(applet, pidfile);
if (pid == -1) {
eerrorx("%s: did not "
"create a valid"
diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index dc6d6c12..c59fb099 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -147,30 +147,6 @@ static void cleanup(void)
free(changeuser);
}
-static pid_t get_pid(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;
-}
-
static void child_process(char *exec, char **argv, char *svcname,
int start_count)
{
@@ -673,7 +649,7 @@ int main(int argc, char **argv)
*exec_file ? exec_file : exec);
if (stop) {
- pid = get_pid(pidfile);
+ pid = get_pid(applet, pidfile);
if (pid == -1)
i = pid;
else
@@ -697,7 +673,7 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
}
- pid = get_pid(pidfile);
+ pid = get_pid(applet, pidfile);
if (pid != -1)
if (kill(pid, 0) == 0)
eerrorx("%s: %s is already running", applet, exec);
next reply other threads:[~2017-08-23 19:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-23 19:38 William Hubbs [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-05-18 22:27 [gentoo-commits] proj/openrc:master commit in: src/includes/, src/rc/ William Hubbs
2016-01-19 6:12 William Hubbs
2016-01-12 20:12 William Hubbs
2016-01-12 20:12 William Hubbs
2016-01-12 20:12 William Hubbs
2015-12-08 18:43 William Hubbs
2012-01-26 19:47 Christian Ruppert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1503517010.cfbe9c2ede24dac530ef58e5c35bd57f22a788a3.williamh@OpenRC \
--to=williamh@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox