[systemd-commits] 5 commits - src/shared src/systemctl

Lennart Poettering lennart at kemper.freedesktop.org
Wed Mar 12 20:18:15 PDT 2014


 src/shared/logs-show.c    |   20 +++-
 src/shared/output-mode.h  |    3 
 src/systemctl/systemctl.c |  228 ++++++++++++++++++++++------------------------
 3 files changed, 133 insertions(+), 118 deletions(-)

New commits:
commit c3441de0613490a1f29d5f1fd0856e07e7c90b49
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Mar 13 03:58:56 2014 +0100

    systemctl: autopage always if systemctl status is invoked without args

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 21bf51b..254ca10 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4154,9 +4154,7 @@ static int show(sd_bus *bus, char **args) {
 
         if (show_status && strv_length(args) <= 1) {
 
-                if (arg_all)
-                        pager_open_if_enabled();
-
+                pager_open_if_enabled();
                 show_system_status(bus);
                 new_line = true;
 

commit ea6c2dd1f819c3d481fc590849809aeb552c1d48
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Mar 13 03:58:03 2014 +0100

    systemctl: suppress duplicate newline if there's not log output in "systemctl status"

diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 12d4a1c..f7d84fc 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -927,6 +927,21 @@ int output_journal(
         return ret;
 }
 
+static int maybe_print_begin_newline(FILE *f, OutputFlags *flags) {
+        assert(f);
+        assert(flags);
+
+        if (!(*flags & OUTPUT_BEGIN_NEWLINE))
+                return 0;
+
+        /* Print a beginning new line if that's request, but only once
+         * on the first line we print. */
+
+        fputc('\n', f);
+        *flags &= ~OUTPUT_BEGIN_NEWLINE;
+        return 0;
+}
+
 static int show_journal(FILE *f,
                         sd_journal *j,
                         OutputMode mode,
@@ -984,6 +999,7 @@ static int show_journal(FILE *f,
                         }
 
                         line ++;
+                        maybe_print_begin_newline(f, &flags);
 
                         r = output_journal(f, j, mode, n_columns, flags, ellipsized);
                         if (r < 0)
@@ -1004,8 +1020,10 @@ static int show_journal(FILE *f,
                         if (r < 0)
                                 goto finish;
 
-                        if (r > 0 && not_before < cutoff)
+                        if (r > 0 && not_before < cutoff) {
+                                maybe_print_begin_newline(f, &flags);
                                 fprintf(f, "Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.\n");
+                        }
 
                         warn_cutoff = false;
                 }
diff --git a/src/shared/output-mode.h b/src/shared/output-mode.h
index 9da789d..ac1bb01 100644
--- a/src/shared/output-mode.h
+++ b/src/shared/output-mode.h
@@ -42,5 +42,6 @@ typedef enum OutputFlags {
         OUTPUT_WARN_CUTOFF    = 1 << 2,
         OUTPUT_FULL_WIDTH     = 1 << 3,
         OUTPUT_COLOR          = 1 << 4,
-        OUTPUT_CATALOG        = 1 << 5
+        OUTPUT_CATALOG        = 1 << 5,
+        OUTPUT_BEGIN_NEWLINE  = 1 << 6,
 } OutputFlags;
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 3cb1096..21bf51b 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -3226,7 +3226,6 @@ static void print_status_info(
         }
 
         if (i->id && arg_transport == BUS_TRANSPORT_LOCAL) {
-                printf("\n");
                 show_journal_by_unit(stdout,
                                      i->id,
                                      arg_output,
@@ -3234,7 +3233,7 @@ static void print_status_info(
                                      i->inactive_exit_timestamp_monotonic,
                                      arg_lines,
                                      getuid(),
-                                     flags,
+                                     flags | OUTPUT_BEGIN_NEWLINE,
                                      arg_scope == UNIT_FILE_SYSTEM,
                                      ellipsized);
         }

commit 15ef11449b31e2fc91f2172c8afedb20ecad5ae9
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Mar 13 03:44:32 2014 +0100

    systemctl: reorder verbs

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 9e48115..3cb1096 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4069,100 +4069,6 @@ static int show_all(
         return 0;
 }
 
-static int cat(sd_bus *bus, char **args) {
-        _cleanup_free_ char *unit = NULL;
-        _cleanup_strv_free_ char **names = NULL;
-        char **name;
-        bool first = true;
-        int r = 0;
-
-        assert(bus);
-        assert(args);
-
-        r = expand_names(bus, args + 1, NULL, &names);
-        if (r < 0)
-                log_error("Failed to expand names: %s", strerror(-r));
-
-        pager_open_if_enabled();
-
-        STRV_FOREACH(name, names) {
-                _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
-                _cleanup_strv_free_ char **dropin_paths = NULL;
-                _cleanup_free_ char *fragment_path = NULL;
-                char **path;
-
-                unit = unit_dbus_path_from_name(*name);
-                if (!unit)
-                        return log_oom();
-
-                if (need_daemon_reload(bus, *name) > 0)
-                        log_warning("Unit file of %s changed on disk. Run 'systemctl%s daemon-reload'.",
-                                    *name, arg_scope == UNIT_FILE_SYSTEM ? "" : " --user");
-
-                r = sd_bus_get_property_string(
-                                bus,
-                                "org.freedesktop.systemd1",
-                                unit,
-                                "org.freedesktop.systemd1.Unit",
-                                "FragmentPath",
-                                &error,
-                                &fragment_path);
-                if (r < 0) {
-                        log_warning("Failed to get FragmentPath: %s", bus_error_message(&error, r));
-                        continue;
-                }
-
-                r = sd_bus_get_property_strv(
-                                bus,
-                                "org.freedesktop.systemd1",
-                                unit,
-                                "org.freedesktop.systemd1.Unit",
-                                "DropInPaths",
-                                &error,
-                                &dropin_paths);
-                if (r < 0) {
-                        log_warning("Failed to get DropInPaths: %s", bus_error_message(&error, r));
-                        continue;
-                }
-
-                if (first)
-                        first = false;
-                else
-                        puts("");
-
-                if (!isempty(fragment_path)) {
-                        printf("%s# %s%s\n",
-                               ansi_highlight_blue(),
-                               fragment_path,
-                               ansi_highlight_off());
-                        fflush(stdout);
-
-                        r = sendfile_full(STDOUT_FILENO, fragment_path);
-                        if (r < 0) {
-                                log_warning("Failed to cat %s: %s", fragment_path, strerror(-r));
-                                continue;
-                        }
-                }
-
-                STRV_FOREACH(path, dropin_paths) {
-                        printf("%s%s# %s%s\n",
-                               isempty(fragment_path) && path == dropin_paths ? "" : "\n",
-                               ansi_highlight_blue(),
-                               *path,
-                               ansi_highlight_off());
-                        fflush(stdout);
-
-                        r = sendfile_full(STDOUT_FILENO, *path);
-                        if (r < 0) {
-                                log_warning("Failed to cat %s: %s", *path, strerror(-r));
-                                continue;
-                        }
-                }
-        }
-
-        return r < 0 ? r : 0;
-}
-
 static int show_system_status(sd_bus *bus) {
         char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], since2[FORMAT_TIMESTAMP_MAX];
         _cleanup_free_ char *hn = NULL;
@@ -4312,6 +4218,100 @@ static int show(sd_bus *bus, char **args) {
         return ret;
 }
 
+static int cat(sd_bus *bus, char **args) {
+        _cleanup_free_ char *unit = NULL;
+        _cleanup_strv_free_ char **names = NULL;
+        char **name;
+        bool first = true;
+        int r = 0;
+
+        assert(bus);
+        assert(args);
+
+        r = expand_names(bus, args + 1, NULL, &names);
+        if (r < 0)
+                log_error("Failed to expand names: %s", strerror(-r));
+
+        pager_open_if_enabled();
+
+        STRV_FOREACH(name, names) {
+                _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+                _cleanup_strv_free_ char **dropin_paths = NULL;
+                _cleanup_free_ char *fragment_path = NULL;
+                char **path;
+
+                unit = unit_dbus_path_from_name(*name);
+                if (!unit)
+                        return log_oom();
+
+                if (need_daemon_reload(bus, *name) > 0)
+                        log_warning("Unit file of %s changed on disk. Run 'systemctl%s daemon-reload'.",
+                                    *name, arg_scope == UNIT_FILE_SYSTEM ? "" : " --user");
+
+                r = sd_bus_get_property_string(
+                                bus,
+                                "org.freedesktop.systemd1",
+                                unit,
+                                "org.freedesktop.systemd1.Unit",
+                                "FragmentPath",
+                                &error,
+                                &fragment_path);
+                if (r < 0) {
+                        log_warning("Failed to get FragmentPath: %s", bus_error_message(&error, r));
+                        continue;
+                }
+
+                r = sd_bus_get_property_strv(
+                                bus,
+                                "org.freedesktop.systemd1",
+                                unit,
+                                "org.freedesktop.systemd1.Unit",
+                                "DropInPaths",
+                                &error,
+                                &dropin_paths);
+                if (r < 0) {
+                        log_warning("Failed to get DropInPaths: %s", bus_error_message(&error, r));
+                        continue;
+                }
+
+                if (first)
+                        first = false;
+                else
+                        puts("");
+
+                if (!isempty(fragment_path)) {
+                        printf("%s# %s%s\n",
+                               ansi_highlight_blue(),
+                               fragment_path,
+                               ansi_highlight_off());
+                        fflush(stdout);
+
+                        r = sendfile_full(STDOUT_FILENO, fragment_path);
+                        if (r < 0) {
+                                log_warning("Failed to cat %s: %s", fragment_path, strerror(-r));
+                                continue;
+                        }
+                }
+
+                STRV_FOREACH(path, dropin_paths) {
+                        printf("%s%s# %s%s\n",
+                               isempty(fragment_path) && path == dropin_paths ? "" : "\n",
+                               ansi_highlight_blue(),
+                               *path,
+                               ansi_highlight_off());
+                        fflush(stdout);
+
+                        r = sendfile_full(STDOUT_FILENO, *path);
+                        if (r < 0) {
+                                log_warning("Failed to cat %s: %s", *path, strerror(-r));
+                                continue;
+                        }
+                }
+        }
+
+        return r < 0 ? r : 0;
+}
+
 static int set_property(sd_bus *bus, char **args) {
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;

commit 3df538da67091623044f00c2dbf488a194a689c6
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Mar 13 03:44:21 2014 +0100

    systemctl: make sure status -a doesn't terminate too soon

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 4690ba0..9e48115 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4062,7 +4062,7 @@ static int show_all(
                         return log_oom();
 
                 r = show_one(verb, bus, p, show_properties, new_line, ellipsized);
-                if (r != 0)
+                if (r < 0)
                         return r;
         }
 

commit b0d14c69b2907798ffde32b49b4f28a90242dbb7
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Mar 13 03:43:36 2014 +0100

    systemctl: show a colored red dot in "status" output indicating the state of a unit

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 8f85413..4690ba0 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2963,7 +2963,7 @@ static void print_status_info(
                 bool *ellipsized) {
 
         ExecStatusInfo *p;
-        const char *on, *off, *ss;
+        const char *active_on, *active_off, *on, *off, *ss;
         usec_t timestamp;
         char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1;
         char since2[FORMAT_TIMESTAMP_MAX], *s2;
@@ -2981,7 +2981,16 @@ static void print_status_info(
         /* This shows pretty information about a unit. See
          * print_property() for a low-level property printer */
 
-        printf("%s", strna(i->id));
+        if (streq_ptr(i->active_state, "failed")) {
+                active_on = ansi_highlight_red();
+                active_off = ansi_highlight_off();
+        } else if (streq_ptr(i->active_state, "active") || streq_ptr(i->active_state, "reloading")) {
+                active_on = ansi_highlight_green();
+                active_off = ansi_highlight_off();
+        } else
+                active_on = active_off = "";
+
+        printf("%s%s%s%s", active_on, draw_special_char(DRAW_BLACK_CIRCLE), active_off, strna(i->id));
 
         if (i->description && !streq_ptr(i->id, i->description))
                 printf(" - %s", i->description);
@@ -3040,22 +3049,12 @@ static void print_status_info(
         }
 
         ss = streq_ptr(i->active_state, i->sub_state) ? NULL : i->sub_state;
-
-        if (streq_ptr(i->active_state, "failed")) {
-                on = ansi_highlight_red();
-                off = ansi_highlight_off();
-        } else if (streq_ptr(i->active_state, "active") || streq_ptr(i->active_state, "reloading")) {
-                on = ansi_highlight_green();
-                off = ansi_highlight_off();
-        } else
-                on = off = "";
-
         if (ss)
                 printf("   Active: %s%s (%s)%s",
-                       on, strna(i->active_state), ss, off);
+                       active_on, strna(i->active_state), ss, active_off);
         else
                 printf("   Active: %s%s%s",
-                       on, strna(i->active_state), off);
+                       active_on, strna(i->active_state), active_off);
 
         if (!isempty(i->result) && !streq(i->result, "success"))
                 printf(" (Result: %s)", i->result);
@@ -4181,8 +4180,6 @@ static int show_system_status(sd_bus *bus) {
                 return r;
         }
 
-        printf("%s\n", arg_host ? arg_host : hn);
-
         if (streq_ptr(mi.state, "degraded")) {
                 on = ansi_highlight_red();
                 off = ansi_highlight_off();
@@ -4192,6 +4189,8 @@ static int show_system_status(sd_bus *bus) {
         } else
                 on = off = "";
 
+        printf("%s%s%s%s\n", on, draw_special_char(DRAW_BLACK_CIRCLE), off, arg_host ? arg_host : hn);
+
         printf("    State: %s%s%s\n",
                on, strna(mi.state), off);
 



More information about the systemd-commits mailing list