X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Finitctl.c;h=53d03a9e10721f79efe2d6a3dd8d44698bfda517;hp=7096a824b0ecfc092d1e752710c1533224ba6577;hb=9b1a953e08917030489cd9adb2a17dfd407ce14b;hpb=4c12626c8e3491570b395d68380543e10c98ad33 diff --git a/src/initctl.c b/src/initctl.c index 7096a824b..53d03a9e1 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -34,13 +34,13 @@ #include #include +#include #include "util.h" #include "log.h" #include "list.h" #include "initreq.h" #include "special.h" -#include "sd-daemon.h" #include "dbus-common.h" #include "def.h" @@ -56,6 +56,8 @@ typedef struct Server { unsigned n_fifos; DBusConnection *bus; + + bool quit; } Server; struct Fifo { @@ -93,6 +95,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; } @@ -165,7 +169,31 @@ 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"); + + /* The bus connection will be + * terminated if PID 1 is reexecuted, + * hence let's just exit here, and + * rely on that we'll be restarted on + * the next request */ + s->quit = true; + 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: @@ -360,7 +388,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - log_set_target(LOG_TARGET_SYSLOG_OR_KMSG); + log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); @@ -385,7 +413,7 @@ int main(int argc, char *argv[]) { "READY=1\n" "STATUS=Processing requests..."); - for (;;) { + while (!server.quit) { struct epoll_event event; int k;