chiark / gitweb /
man: bring systemctl man page and --help text into the same order
[elogind.git] / src / systemctl / systemctl.c
index 060bfe28e4e96403260eaad43110712c42a46ac6..74528dd5b6cbbefae35d610b0af78c745ab76085 100644 (file)
@@ -176,7 +176,6 @@ static void ask_password_agent_open_if_enabled(void) {
         ask_password_agent_open();
 }
 
-#ifdef HAVE_LOGIND
 static void polkit_agent_open_if_enabled(void) {
 
         /* Open the polkit agent as a child process if necessary */
@@ -192,7 +191,15 @@ static void polkit_agent_open_if_enabled(void) {
 
         polkit_agent_open();
 }
-#endif
+
+static OutputFlags get_output_flags(void) {
+        return
+                arg_all * OUTPUT_SHOW_ALL |
+                arg_full * OUTPUT_FULL_WIDTH |
+                (!on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
+                on_tty() * OUTPUT_COLOR |
+                !arg_quiet * OUTPUT_WARN_CUTOFF;
+}
 
 static int translate_bus_error_to_exit_status(int r, const sd_bus_error *error) {
         assert(error);
@@ -1951,32 +1958,6 @@ static void dump_unit_file_changes(const UnitFileChange *changes, unsigned n_cha
         }
 }
 
-static int deserialize_and_dump_unit_file_changes(sd_bus_message *m) {
-        const char *type, *path, *source;
-        int r;
-
-        r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(sss)");
-        if (r < 0)
-                return bus_log_parse_error(r);
-
-        while ((r = sd_bus_message_read(m, "(sss)", &type, &path, &source)) > 0) {
-                if (!arg_quiet) {
-                        if (streq(type, "symlink"))
-                                log_info("Created symlink from %s to %s.", path, source);
-                        else
-                                log_info("Removed symlink %s.", path);
-                }
-        }
-        if (r < 0)
-                return bus_log_parse_error(r);
-
-        r = sd_bus_message_exit_container(m);
-        if (r < 0)
-                return bus_log_parse_error(r);
-
-        return 0;
-}
-
 static int set_default(sd_bus *bus, char **args) {
         _cleanup_free_ char *unit = NULL;
         UnitFileChange *changes = NULL;
@@ -2024,7 +2005,7 @@ static int set_default(sd_bus *bus, char **args) {
                         return r;
                 }
 
-                r = deserialize_and_dump_unit_file_changes(reply);
+                r = bus_deserialize_and_dump_unit_file_changes(reply, arg_quiet);
                 if (r < 0)
                         return r;
 
@@ -2723,6 +2704,7 @@ static int start_unit(sd_bus *bus, char **args) {
         assert(bus);
 
         ask_password_agent_open_if_enabled();
+        polkit_agent_open_if_enabled();
 
         if (arg_action == ACTION_SYSTEMCTL) {
                 enum action action;
@@ -2992,7 +2974,7 @@ static int start_special(sd_bus *bus, char **args) {
              a == ACTION_HIBERNATE ||
              a == ACTION_HYBRID_SLEEP)) {
                 r = reboot_with_logind(bus, a);
-                if (r >= 0)
+                if (r >= 0 || IN_SET(r, -ENOTSUP, -EINPROGRESS))
                         return r;
         }
 
@@ -3046,6 +3028,8 @@ static int kill_unit(sd_bus *bus, char **args) {
         assert(bus);
         assert(args);
 
+        polkit_agent_open_if_enabled();
+
         if (!arg_kill_who)
                 arg_kill_who = "all";
 
@@ -3250,12 +3234,6 @@ static void print_status_info(
         char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1;
         char since2[FORMAT_TIMESTAMP_MAX], *s2;
         const char *path;
-        int flags =
-                arg_all * OUTPUT_SHOW_ALL |
-                (!on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
-                on_tty() * OUTPUT_COLOR |
-                !arg_quiet * OUTPUT_WARN_CUTOFF |
-                arg_full * OUTPUT_FULL_WIDTH;
         char **t, **t2;
 
         assert(i);
@@ -3525,21 +3503,23 @@ static void print_status_info(
                         if (i->control_pid > 0)
                                 extra[k++] = i->control_pid;
 
-                        show_cgroup_and_extra(SYSTEMD_CGROUP_CONTROLLER, i->control_group, prefix, c, false, extra, k, flags);
+                        show_cgroup_and_extra(SYSTEMD_CGROUP_CONTROLLER, i->control_group, prefix, c, false, extra, k, get_output_flags());
                 }
         }
 
         if (i->id && arg_transport == BUS_TRANSPORT_LOCAL) {
-                show_journal_by_unit(stdout,
-                                     i->id,
-                                     arg_output,
-                                     0,
-                                     i->inactive_exit_timestamp_monotonic,
-                                     arg_lines,
-                                     getuid(),
-                                     flags | OUTPUT_BEGIN_NEWLINE,
-                                     arg_scope == UNIT_FILE_SYSTEM,
-                                     ellipsized);
+                show_journal_by_unit(
+                                stdout,
+                                i->id,
+                                arg_output,
+                                0,
+                                i->inactive_exit_timestamp_monotonic,
+                                arg_lines,
+                                getuid(),
+                                get_output_flags() | OUTPUT_BEGIN_NEWLINE,
+                                SD_JOURNAL_LOCAL_ONLY,
+                                arg_scope == UNIT_FILE_SYSTEM,
+                                ellipsized);
         }
 
         if (i->need_daemon_reload)
@@ -4403,13 +4383,6 @@ static int show_system_status(sd_bus *bus) {
 
         printf("   CGroup: %s\n", mi.control_group ?: "/");
         if (arg_transport == BUS_TRANSPORT_LOCAL || arg_transport == BUS_TRANSPORT_MACHINE) {
-                int flags =
-                        arg_all * OUTPUT_SHOW_ALL |
-                        (!on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
-                        on_tty() * OUTPUT_COLOR |
-                        !arg_quiet * OUTPUT_WARN_CUTOFF |
-                        arg_full * OUTPUT_FULL_WIDTH;
-
                 static const char prefix[] = "           ";
                 unsigned c;
 
@@ -4419,7 +4392,7 @@ static int show_system_status(sd_bus *bus) {
                 else
                         c = 0;
 
-                show_cgroup(SYSTEMD_CGROUP_CONTROLLER, strempty(mi.control_group), prefix, c, false, flags);
+                show_cgroup(SYSTEMD_CGROUP_CONTROLLER, strempty(mi.control_group), prefix, c, false, get_output_flags());
         }
 
         free(mi.state);
@@ -4541,11 +4514,7 @@ static int init_home_and_lookup_paths(char **user_home, char **user_runtime, Loo
                         return log_error_errno(ENOTDIR, "Cannot find units: $XDG_RUNTIME_DIR is not set.");
         }
 
-        r = lookup_paths_init(lp,
-                              arg_scope == UNIT_FILE_SYSTEM ? SYSTEMD_SYSTEM : SYSTEMD_USER,
-                              arg_scope == UNIT_FILE_USER,
-                              arg_root,
-                              NULL, NULL, NULL);
+        r = lookup_paths_init_from_scope(lp, arg_scope, arg_root);
         if (r < 0)
                 return log_error_errno(r, "Failed to lookup unit lookup paths: %m");
 
@@ -4633,6 +4602,8 @@ static int set_property(sd_bus *bus, char **args) {
         char **i;
         int r;
 
+        polkit_agent_open_if_enabled();
+
         r = sd_bus_message_new_method_call(
                         bus,
                         &m,
@@ -4693,6 +4664,8 @@ static int snapshot(sd_bus *bus, char **args) {
         const char *path;
         int r;
 
+        polkit_agent_open_if_enabled();
+
         if (strv_length(args) > 1)
                 n = unit_name_mangle_with_suffix(args[1], MANGLE_NOGLOB, ".snapshot");
         else
@@ -4755,6 +4728,8 @@ static int delete_snapshot(sd_bus *bus, char **args) {
 
         assert(args);
 
+        polkit_agent_open_if_enabled();
+
         r = expand_names(bus, args + 1, ".snapshot", &names);
         if (r < 0)
                 log_error_errno(r, "Failed to expand names: %m");
@@ -4798,6 +4773,8 @@ static int daemon_reload(sd_bus *bus, char **args) {
         const char *method;
         int r;
 
+        polkit_agent_open_if_enabled();
+
         if (arg_action == ACTION_RELOAD)
                 method = "Reload";
         else if (arg_action == ACTION_REEXEC)
@@ -4856,6 +4833,8 @@ static int reset_failed(sd_bus *bus, char **args) {
         if (strv_length(args) <= 1)
                 return daemon_reload(bus, args);
 
+        polkit_agent_open_if_enabled();
+
         r = expand_names(bus, args + 1, NULL, &names);
         if (r < 0)
                 log_error_errno(r, "Failed to expand names: %m");
@@ -5214,8 +5193,10 @@ static int enable_sysv_units(const char *verb, char **args) {
                         return -EPROTO;
 
                 /* Remove this entry, so that we don't try enabling it as native unit */
-                assert(f > 0 && streq(args[f-1], name));
-                assert_se(strv_remove(args + f - 1, name));
+                assert(f > 0);
+                f--;
+                assert(args[f] == name);
+                strv_remove(args, name);
         }
 
 #endif
@@ -5315,6 +5296,8 @@ static int enable_unit(sd_bus *bus, char **args) {
                 bool send_force = true, send_preset_mode = false;
                 const char *method;
 
+                polkit_agent_open_if_enabled();
+
                 if (streq(verb, "enable")) {
                         method = "EnableUnitFiles";
                         expect_carries_install_info = true;
@@ -5389,7 +5372,7 @@ static int enable_unit(sd_bus *bus, char **args) {
                                 return bus_log_parse_error(r);
                 }
 
-                r = deserialize_and_dump_unit_file_changes(reply);
+                r = bus_deserialize_and_dump_unit_file_changes(reply, arg_quiet);
                 if (r < 0)
                         return r;
 
@@ -5460,6 +5443,8 @@ static int add_dependency(sd_bus *bus, char **args) {
                 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL, *m = NULL;
                 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
 
+                polkit_agent_open_if_enabled();
+
                 r = sd_bus_message_new_method_call(
                                 bus,
                                 &m,
@@ -5488,7 +5473,7 @@ static int add_dependency(sd_bus *bus, char **args) {
                         return r;
                 }
 
-                r = deserialize_and_dump_unit_file_changes(reply);
+                r = bus_deserialize_and_dump_unit_file_changes(reply, arg_quiet);
                 if (r < 0)
                         return r;
 
@@ -5523,6 +5508,8 @@ static int preset_all(sd_bus *bus, char **args) {
                 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
                 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
 
+                polkit_agent_open_if_enabled();
+
                 r = sd_bus_message_new_method_call(
                                 bus,
                                 &m,
@@ -5552,7 +5539,7 @@ static int preset_all(sd_bus *bus, char **args) {
                         return r;
                 }
 
-                r = deserialize_and_dump_unit_file_changes(reply);
+                r = bus_deserialize_and_dump_unit_file_changes(reply, arg_quiet);
                 if (r < 0)
                         return r;
 
@@ -6088,7 +6075,7 @@ static void systemctl_help(void) {
                "                                  based on preset configuration\n"
                "  preset-all                      Enable/disable all unit files based on\n"
                "                                  preset configuration\n"
-               "  is-enabled NAME...              Check whether unit files are enabled\n\n"
+               "  is-enabled NAME...              Check whether unit files are enabled\n"
                "  mask NAME...                    Mask one or more units\n"
                "  unmask NAME...                  Unmask one or more units\n"
                "  link PATH...                    Link one or more units files into\n"
@@ -6097,10 +6084,9 @@ static void systemctl_help(void) {
                "                                  on specified one or more units\n"
                "  add-requires TARGET NAME...     Add 'Requires' dependency for the target\n"
                "                                  on specified one or more units\n"
-               "  get-default                     Get the name of the default target\n"
-               "  set-default NAME                Set the default target\n"
                "  edit NAME...                    Edit one or more unit files\n"
-               "\n"
+               "  get-default                     Get the name of the default target\n"
+               "  set-default NAME                Set the default target\n\n"
                "Machine Commands:\n"
                "  list-machines [PATTERN...]      List local containers and host\n\n"
                "Job Commands:\n"
@@ -7437,6 +7423,11 @@ int main(int argc, char*argv[]) {
                 goto finish;
         }
 
+        /* Increase max number of open files to 16K if we can, we
+         * might needs this when browsing journal files, which might
+         * be split up into many files. */
+        setrlimit_closest(RLIMIT_NOFILE, &RLIMIT_MAKE_CONST(16384));
+
         if (!avoid_bus())
                 r = bus_open_transport_systemd(arg_transport, arg_host, arg_scope != UNIT_FILE_SYSTEM, &bus);