diff options
Diffstat (limited to 'src/rc/rc-sysvinit.c')
-rw-r--r-- | src/rc/rc-sysvinit.c | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/src/rc/rc-sysvinit.c b/src/rc/rc-sysvinit.c index d9d17146..4ef074ca 100644 --- a/src/rc/rc-sysvinit.c +++ b/src/rc/rc-sysvinit.c @@ -26,31 +26,21 @@ #include "einfo.h" #include "rc-sysvinit.h" -void sysvinit_runlevel(char rl) +static void sysvinit_send_cmd(struct init_request *request) { - struct init_request request; int fd; char *p; size_t bytes; ssize_t r; - if (!rl) - return; - fd = open("/run/initctl", O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY); if (fd < 0) { if (errno != ENOENT) eerror("Failed to open initctl fifo: %s", strerror(errno)); return; } - request = (struct init_request) { - .magic = INIT_MAGIC, - .sleeptime = 0, - .cmd = INIT_CMD_RUNLVL, - .runlevel = rl, - }; - p = (char *) &request; - bytes = sizeof(request); + p = (char *) request; + bytes = sizeof(*request); do { r = write(fd, p, bytes); if (r < 0) { @@ -62,5 +52,51 @@ void sysvinit_runlevel(char rl) p += r; bytes -= r; } while (bytes > 0); - exit(0); +} + +void sysvinit_runlevel(char rl) +{ + struct init_request request; + + if (!rl) + return; + + request = (struct init_request) { + .magic = INIT_MAGIC, + .sleeptime = 0, + .cmd = INIT_CMD_RUNLVL, + .runlevel = rl, + }; + sysvinit_send_cmd(&request); + return; +} + +/* + * Set environment variables in the init process. + */ +void sysvinit_setenv(char *name, char *value) +{ + struct init_request request; + size_t nl; + size_t vl; + + memset(&request, 0, sizeof(request)); + request.magic = INIT_MAGIC; + request.cmd = INIT_CMD_SETENV; + nl = strlen(name); + if (value) + vl = strlen(value); +else + vl = 0; + + if (nl + vl + 3 >= (int)sizeof(request.i.data)) + return -1; + + memcpy(request.i.data, name, nl); + if (value) { + request.i.data[nl] = '='; + memcpy(request.i.data + nl + 1, value, vl); + } + sysvinit_send_cmd(&request); + return 0; } |