chiark / gitweb /
systemctl: hide all information on --kill-mode= since it is mostly useless
[elogind.git] / src / systemctl.c
index b584e7032b9558672b5424d854096ffdaf974a6e..c01a82c9305e8f0ca6733f600b9f36fd1c2a48d8 100644 (file)
@@ -33,7 +33,6 @@
 #include <sys/stat.h>
 #include <stddef.h>
 #include <sys/prctl.h>
-
 #include <dbus/dbus.h>
 
 #include "log.h"
@@ -56,6 +55,7 @@
 #include "bus-errors.h"
 #include "build.h"
 #include "unit-name.h"
+#include "pager.h"
 
 static const char *arg_type = NULL;
 static char **arg_property = NULL;
@@ -80,8 +80,8 @@ static bool arg_failed = false;
 static char **arg_wall = NULL;
 static const char *arg_kill_who = NULL;
 static const char *arg_kill_mode = NULL;
-static const char *arg_root = NULL;
 static int arg_signal = SIGTERM;
+static const char *arg_root = NULL;
 static usec_t arg_when = 0;
 static enum action {
         ACTION_INVALID,
@@ -118,11 +118,9 @@ static const char *arg_host = NULL;
 
 static bool private_bus = false;
 
-static pid_t pager_pid = 0;
 static pid_t agent_pid = 0;
 
 static int daemon_reload(DBusConnection *bus, char **args, unsigned n);
-static void pager_open(void);
 
 static bool on_tty(void) {
         static int t = -1;
@@ -139,6 +137,13 @@ static bool on_tty(void) {
         return t;
 }
 
+static void pager_open_if_enabled(void) {
+        on_tty();
+
+        if (!arg_no_pager)
+                pager_open();
+}
+
 static void spawn_ask_password_agent(void) {
         pid_t parent;
 
@@ -274,22 +279,6 @@ static int translate_bus_error_to_exit_status(int r, const DBusError *error) {
         return EXIT_FAILURE;
 }
 
-static int bus_iter_get_basic_and_next(DBusMessageIter *iter, int type, void *data, bool next) {
-
-        assert(iter);
-        assert(data);
-
-        if (dbus_message_iter_get_arg_type(iter) != type)
-                return -EIO;
-
-        dbus_message_iter_get_basic(iter, data);
-
-        if (!dbus_message_iter_next(iter) != !next)
-                return -EIO;
-
-        return 0;
-}
-
 static void warn_wall(enum action action) {
         static const char *table[_ACTION_MAX] = {
                 [ACTION_HALT]      = "The system is going down for system halt NOW!",
@@ -475,7 +464,7 @@ static int list_units(DBusConnection *bus, char **args, unsigned n) {
 
         assert(bus);
 
-        pager_open();
+        pager_open_if_enabled();
 
         if (!(m = dbus_message_new_method_call(
                               "org.freedesktop.systemd1",
@@ -796,7 +785,7 @@ static int dot(DBusConnection *bus, char **args, unsigned n) {
                  "                 red       = Conflicts\n"
                  "                 green     = After\n");
 
-        if (isatty(fileno(stdout)))
+        if (on_tty())
                 log_notice("-- You probably want to process this output with graphviz' dot tool.\n"
                            "-- Try a shell pipeline like 'systemctl dot | dot -Tsvg > systemd.svg'!\n");
 
@@ -825,7 +814,7 @@ static int list_jobs(DBusConnection *bus, char **args, unsigned n) {
 
         assert(bus);
 
-        pager_open();
+        pager_open_if_enabled();
 
         if (!(m = dbus_message_new_method_call(
                               "org.freedesktop.systemd1",
@@ -852,7 +841,7 @@ static int list_jobs(DBusConnection *bus, char **args, unsigned n) {
 
         dbus_message_iter_recurse(&iter, &sub);
 
-        if (isatty(STDOUT_FILENO))
+        if (on_tty())
                 printf("%4s %-25s %-15s %-7s\n", "JOB", "UNIT", "TYPE", "STATE");
 
         while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
@@ -888,7 +877,7 @@ static int list_jobs(DBusConnection *bus, char **args, unsigned n) {
                 dbus_message_iter_next(&sub);
         }
 
-        if (isatty(STDOUT_FILENO))
+        if (on_tty())
                 printf("\n%u jobs listed.\n", k);
 
         r = 0;
@@ -2652,7 +2641,7 @@ static int show(DBusConnection *bus, char **args, unsigned n) {
         show_properties = !streq(args[0], "status");
 
         if (show_properties)
-                pager_open();
+                pager_open_if_enabled();
 
         if (show_properties && n <= 1) {
                 /* If not argument is specified inspect the manager
@@ -3048,7 +3037,7 @@ static int dump(DBusConnection *bus, char **args, unsigned n) {
 
         dbus_error_init(&error);
 
-        pager_open();
+        pager_open_if_enabled();
 
         if (!(m = dbus_message_new_method_call(
                               "org.freedesktop.systemd1",
@@ -3419,7 +3408,7 @@ static int show_enviroment(DBusConnection *bus, char **args, unsigned n) {
 
         dbus_error_init(&error);
 
-        pager_open();
+        pager_open_if_enabled();
 
         if (!(m = dbus_message_new_method_call(
                               "org.freedesktop.systemd1",
@@ -4363,7 +4352,6 @@ static int systemctl_help(void) {
                "                      pending\n"
                "     --ignore-dependencies\n"
                "                      When queueing a new job, ignore all its dependencies\n"
-               "     --kill-mode=MODE How to send signal\n"
                "     --kill-who=WHO   Who to send signal to\n"
                "  -s --signal=SIGNAL  Which signal to send\n"
                "  -H --host=[user@]host\n"
@@ -4374,7 +4362,7 @@ static int systemctl_help(void) {
                "     --no-wall        Don't send wall message before halt/power-off/reboot\n"
                "     --no-reload      When enabling/disabling unit files, don't reload daemon\n"
                "                      configuration\n"
-               "     --no-pager       Do not pipe output into a pager.\n"
+               "     --no-pager       Do not pipe output into a pager\n"
                "     --no-ask-password\n"
                "                      Do not ask for system passwords\n"
                "     --order          When generating graph for dot, show only order\n"
@@ -4547,7 +4535,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                 { "force",     no_argument,       NULL, 'f'           },
                 { "no-reload", no_argument,       NULL, ARG_NO_RELOAD },
                 { "defaults",  no_argument,       NULL, ARG_DEFAULTS  },
-                { "kill-mode", required_argument, NULL, ARG_KILL_MODE },
+                { "kill-mode", required_argument, NULL, ARG_KILL_MODE }, /* undocumented on purpose */
                 { "kill-who",  required_argument, NULL, ARG_KILL_WHO  },
                 { "signal",    required_argument, NULL, 's'           },
                 { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },
@@ -5422,7 +5410,7 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError
         return verbs[i].dispatch(bus, argv + optind, left);
 }
 
-static int send_shutdownd(usec_t t, char mode, bool warn, const char *message) {
+static int send_shutdownd(usec_t t, char mode, bool dry_run, bool warn, const char *message) {
         int fd = -1;
         struct msghdr msghdr;
         struct iovec iovec;
@@ -5432,6 +5420,7 @@ static int send_shutdownd(usec_t t, char mode, bool warn, const char *message) {
         zero(c);
         c.elapse = t;
         c.mode = mode;
+        c.dry_run = dry_run;
         c.warn_wall = warn;
 
         if (message)
@@ -5527,6 +5516,7 @@ static int halt_main(DBusConnection *bus) {
                                    arg_action == ACTION_HALT     ? 'H' :
                                    arg_action == ACTION_POWEROFF ? 'P' :
                                                                    'r',
+                                   arg_dry,
                                    !arg_no_wall,
                                    m);
                 free(m);
@@ -5600,96 +5590,6 @@ static int runlevel_main(void) {
         return 0;
 }
 
-static void pager_open(void) {
-        int fd[2];
-        const char *pager;
-        pid_t parent_pid;
-
-        if (pager_pid > 0)
-                return;
-
-        if (!on_tty() || arg_no_pager)
-                return;
-
-        if ((pager = getenv("SYSTEMD_PAGER")) || (pager = getenv("PAGER")))
-                if (!*pager || streq(pager, "cat"))
-                        return;
-
-        /* Determine and cache number of columns before we spawn the
-         * pager so that we get the value from the actual tty */
-        columns();
-
-        if (pipe(fd) < 0) {
-                log_error("Failed to create pager pipe: %m");
-                return;
-        }
-
-        parent_pid = getpid();
-
-        pager_pid = fork();
-        if (pager_pid < 0) {
-                log_error("Failed to fork pager: %m");
-                close_pipe(fd);
-                return;
-        }
-
-        /* In the child start the pager */
-        if (pager_pid == 0) {
-
-                dup2(fd[0], STDIN_FILENO);
-                close_pipe(fd);
-
-                setenv("LESS", "FRSX", 0);
-
-                /* Make sure the pager goes away when the parent dies */
-                if (prctl(PR_SET_PDEATHSIG, SIGTERM) < 0)
-                        _exit(EXIT_FAILURE);
-
-                /* Check whether our parent died before we were able
-                 * to set the death signal */
-                if (getppid() != parent_pid)
-                        _exit(EXIT_SUCCESS);
-
-                if (pager) {
-                        execlp(pager, pager, NULL);
-                        execl("/bin/sh", "sh", "-c", pager, NULL);
-                } else {
-                        /* Debian's alternatives command for pagers is
-                         * called 'pager'. Note that we do not call
-                         * sensible-pagers here, since that is just a
-                         * shell script that implements a logic that
-                         * is similar to this one anyway, but is
-                         * Debian-specific. */
-                        execlp("pager", "pager", NULL);
-
-                        execlp("less", "less", NULL);
-                        execlp("more", "more", NULL);
-                }
-
-                log_error("Unable to execute pager: %m");
-                _exit(EXIT_FAILURE);
-        }
-
-        /* Return in the parent */
-        if (dup2(fd[1], STDOUT_FILENO) < 0)
-                log_error("Failed to duplicate pager pipe: %m");
-
-        close_pipe(fd);
-}
-
-static void pager_close(void) {
-        siginfo_t dummy;
-
-        if (pager_pid <= 0)
-                return;
-
-        /* Inform pager that we are done */
-        fclose(stdout);
-        kill(pager_pid, SIGCONT);
-        wait_for_terminate(pager_pid, &dummy);
-        pager_pid = 0;
-}
-
 static void agent_close(void) {
         siginfo_t dummy;
 
@@ -5774,7 +5674,7 @@ int main(int argc, char*argv[]) {
                 break;
 
         case ACTION_CANCEL_SHUTDOWN:
-                r = send_shutdownd(0, 0, false, NULL);
+                r = send_shutdownd(0, 0, false, false, NULL);
                 break;
 
         case ACTION_INVALID: