chiark / gitweb /
path-lookup: monitor /etc/systemd/user for user manager
[elogind.git] / src / initctl.c
index 15da4593d0a63648d70885b480085ce6d830e761..eaa717ad916bdb55115870696123397bb012759e 100644 (file)
 #include "special.h"
 #include "sd-daemon.h"
 #include "dbus-common.h"
+#include "def.h"
 
 #define SERVER_FD_MAX 16
-#define TIMEOUT ((int) (10*MSEC_PER_SEC))
+#define TIMEOUT_MSEC ((int) (DEFAULT_EXIT_USEC/USEC_PER_MSEC))
 
 typedef struct Fifo Fifo;
 
@@ -92,6 +93,8 @@ static const char *translate_runlevel(int runlevel, bool *isolate) {
         for (i = 0; i < ELEMENTSOF(table); i++)
                 if (table[i].runlevel == runlevel) {
                         *isolate = table[i].isolate;
+                        if (runlevel == '6' && kexec_loaded())
+                                return SPECIAL_KEXEC_TARGET;
                         return table[i].special;
                 }
 
@@ -164,7 +167,24 @@ static void request_process(Server *s, const struct init_request *req) {
                 if (!isprint(req->runlevel))
                         log_error("Got invalid runlevel. Ignoring.");
                 else
-                        change_runlevel(s, req->runlevel);
+                        switch (req->runlevel) {
+
+                        /* we are async anyway, so just use kill for reexec/reload */
+                        case 'u':
+                        case 'U':
+                                if (kill(1, SIGTERM) < 0)
+                                        log_error("kill() failed: %m");
+                                break;
+
+                        case 'q':
+                        case 'Q':
+                                if (kill(1, SIGHUP) < 0)
+                                        log_error("kill() failed: %m");
+                                break;
+
+                        default:
+                                change_runlevel(s, req->runlevel);
+                        }
                 return;
 
         case INIT_CMD_POWERFAIL:
@@ -363,6 +383,8 @@ int main(int argc, char *argv[]) {
         log_parse_environment();
         log_open();
 
+        umask(0022);
+
         if ((n = sd_listen_fds(true)) < 0) {
                 log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
                 return EXIT_FAILURE;
@@ -388,7 +410,7 @@ int main(int argc, char *argv[]) {
 
                 if ((k = epoll_wait(server.epoll_fd,
                                     &event, 1,
-                                    TIMEOUT)) < 0) {
+                                    TIMEOUT_MSEC)) < 0) {
 
                         if (errno == EINTR)
                                 continue;