chiark / gitweb /
udev: allow firmware requests to bypass the dependency tracking
[elogind.git] / src / systemctl / systemctl.c
index 729d4dd324ea1848f419da30e167f3dc3404880e..a4290c4754939d9f4fa0419b2dad2a847b88c795 100644 (file)
@@ -186,6 +186,14 @@ static void polkit_agent_open_if_enabled(void) {
 }
 #endif
 
+static const char *ansi_highlight(bool b) {
+
+        if (!on_tty())
+                return "";
+
+        return b ? ANSI_HIGHLIGHT_ON : ANSI_HIGHLIGHT_OFF;
+}
+
 static const char *ansi_highlight_red(bool b) {
 
         if (!on_tty())
@@ -372,15 +380,6 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
         } else
                 id_len = max_id_len;
 
-        if (!arg_no_legend) {
-                printf("%-*s %-6s %-*s %-*s %-*s ", id_len, "UNIT", "LOAD",
-                       active_len, "ACTIVE", sub_len, "SUB", job_len, "JOB");
-                if (!arg_full && arg_no_pager)
-                        printf("%.*s\n", desc_len, "DESCRIPTION");
-                else
-                        printf("%s\n", "DESCRIPTION");
-        }
-
         for (u = unit_infos; u < unit_infos + c; u++) {
                 char *e;
                 const char *on_loaded, *off_loaded;
@@ -389,6 +388,15 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
                 if (!output_show_unit(u))
                         continue;
 
+                if (!n_shown && !arg_no_legend) {
+                        printf("%-*s %-6s %-*s %-*s %-*s ", id_len, "UNIT", "LOAD",
+                               active_len, "ACTIVE", sub_len, "SUB", job_len, "JOB");
+                        if (!arg_full && arg_no_pager)
+                                printf("%.*s\n", desc_len, "DESCRIPTION");
+                        else
+                                printf("%s\n", "DESCRIPTION");
+                }
+
                 n_shown++;
 
                 if (streq(u->load_state, "error")) {
@@ -420,17 +428,28 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
         }
 
         if (!arg_no_legend) {
-                printf("\nLOAD   = Reflects whether the unit definition was properly loaded.\n"
-                       "ACTIVE = The high-level unit activation state, i.e. generalization of SUB.\n"
-                       "SUB    = The low-level unit activation state, values depend on unit type.\n"
-                       "JOB    = Pending job for the unit.\n");
+                const char *on, *off;
+
+                if (n_shown) {
+                        printf("\nLOAD   = Reflects whether the unit definition was properly loaded.\n"
+                               "ACTIVE = The high-level unit activation state, i.e. generalization of SUB.\n"
+                               "SUB    = The low-level unit activation state, values depend on unit type.\n"
+                               "JOB    = Pending job for the unit.\n\n");
+                        on = ansi_highlight(true);
+                        off = ansi_highlight(false);
+                } else {
+                        on = ansi_highlight_red(true);
+                        off = ansi_highlight_red(false);
+                }
 
                 if (arg_all)
-                        printf("\n%u loaded units listed.\n"
-                               "To show all installed unit files use 'systemctl list-unit-files'.\n", n_shown);
+                        printf("%s%u loaded units listed.%s\n"
+                               "To show all installed unit files use 'systemctl list-unit-files'.\n",
+                               on, n_shown, off);
                 else
-                        printf("\n%u loaded units listed. Pass --all to see loaded but inactive units, too.\n"
-                               "To show all installed unit files use 'systemctl list-unit-files'.\n", n_shown);
+                        printf("%s%u loaded units listed.%s Pass --all to see loaded but inactive units, too.\n"
+                               "To show all installed unit files use 'systemctl list-unit-files'.\n",
+                               on, n_shown, off);
         }
 }
 
@@ -1445,7 +1464,7 @@ static void check_triggering_units(
                 DBusConnection *bus,
                 const char *unit_name) {
 
-        DBusMessage _cleanup_dbus_msg_unref_ *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         DBusMessageIter iter, sub;
         char *service_trigger = NULL;
         const char *interface = "org.freedesktop.systemd1.Unit",
@@ -1523,7 +1542,7 @@ static int start_unit_one(
                 DBusError *error,
                 Set *s) {
 
-        DBusMessage _cleanup_dbus_msg_unref_ *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         const char *path;
         int r;
         _cleanup_free_ char *n, *p = NULL;
@@ -1584,11 +1603,6 @@ static int start_unit_one(
                 p = NULL;
         }
 
-        /* When stopping a unit warn if it can still be triggered by
-         * another active unit (socket, path, timer) */
-        if (!arg_quiet && streq(method, "StopUnit"))
-                check_triggering_units(bus, name);
-
         return 0;
 }
 
@@ -1723,6 +1737,16 @@ static int start_unit(DBusConnection *bus, char **args) {
                         ret = r;
                         goto finish;
                 }
+
+                /* When stopping units, warn if they can still be triggered by
+                 * another active unit (socket, path, timer) */
+                if (!arg_quiet && streq(method, "StopUnit")) {
+                        if (one_name)
+                                check_triggering_units(bus, one_name);
+                        else
+                                STRV_FOREACH(name, args+1)
+                                        check_triggering_units(bus, *name);
+                }
         }
 
 finish:
@@ -2274,9 +2298,13 @@ static void print_status_info(UnitStatusInfo *i) {
                         on_tty() * OUTPUT_COLOR;
 
                 printf("\n");
-                show_journal_by_unit(i->id, arg_output, 0,
+                show_journal_by_unit(stdout,
+                                     i->id,
+                                     arg_output,
+                                     0,
                                      i->inactive_exit_timestamp_monotonic,
-                                     arg_lines, flags);
+                                     arg_lines,
+                                     flags);
         }
 
         if (i->need_daemon_reload)