commit:     f9acd65497c6e561fbf5420386a99d681fede859
Author:     Alexander Vershilov <alexander.vershilov <AT> gmail <DOT> com>
AuthorDate: Mon Oct 20 00:41:36 2014 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Mon Oct 20 20:44:19 2014 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=f9acd654

librc:look for the pid file in a chroot if defined

X-Gentoo-Bug: 524388
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=524388

---
 src/librc/librc-daemon.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index 8793075..04f25b1 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -553,16 +553,28 @@ rc_service_daemons_crashed(const char *service)
                }
                fclose(fp);
 
+               char *ch_root = rc_service_value_get(basename_c(service), 
"chroot");
+               char *spidfile = pidfile;
+               if (ch_root) {
+                       spidfile = malloc(strlen(ch_root) + strlen(pidfile));
+                       strcpy(spidfile, ch_root);
+                       strcat(spidfile, pidfile);
+               }
+
                pid = 0;
-               if (pidfile) {
+               if (spidfile) {
                        retval = true;
-                       if ((fp = fopen(pidfile, "r"))) {
+                       if ((fp = fopen(spidfile, "r"))) {
                                if (fscanf(fp, "%d", &pid) == 1)
                                        retval = false;
                                fclose(fp);
                        }
-                       free(pidfile);
-                       pidfile = NULL;
+                       free(spidfile);
+                       spidfile = NULL;
+                       if (ch_root) {
+                               free(pidfile);
+                               pidfile = NULL;
+                       }
 
                        /* We have the pid, so no need to match
                           on exec or name */

Reply via email to