From: Michael Biebl <biebl@debian.org>
Date: Tue, 24 Jun 2014 12:35:25 +0200
Subject: Add /run/initctl support to SysV compat tools

sysvinit in Debian uses /run/initctl as FIFO to communicate with PID 1.
Make the SysV compat tools in systemd-sysv try both /run/initctl and the
traditional /dev/initctl. This makes them usable when running sysvinit
as PID 1.
---
 src/systemctl/systemctl.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 3147c4a..61d181b 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -5589,19 +5589,24 @@ static int talk_initctl(void) {
         request.cmd = INIT_CMD_RUNLVL;
         request.runlevel = rl;
 
-        fd = open(INIT_FIFO, O_WRONLY|O_NDELAY|O_CLOEXEC|O_NOCTTY);
+        /* Try /run/initctl first since that is what sysvinit in Debian uses */
+        fd = open("/run/initctl", O_WRONLY|O_NDELAY|O_CLOEXEC|O_NOCTTY);
         if (fd < 0) {
-                if (errno == ENOENT)
-                        return 0;
+                /* Fall back to /dev/initctl */
+                fd = open(INIT_FIFO, O_WRONLY|O_NDELAY|O_CLOEXEC|O_NOCTTY);
+                if (fd < 0) {
+                        if (errno == ENOENT)
+                                return 0;
 
-                log_error("Failed to open "INIT_FIFO": %m");
-                return -errno;
+                        log_error("Failed to open initctl FIFO: %m");
+                        return -errno;
+                }
         }
 
         errno = 0;
         r = loop_write(fd, &request, sizeof(request), false) != sizeof(request);
         if (r) {
-                log_error("Failed to write to "INIT_FIFO": %m");
+                log_error("Failed to write to initctl FIFO: %m");
                 return errno > 0 ? -errno : -EIO;
         }
 
