[systemd-commits] 4 commits - man/sd_journal_query_unique.xml src/journal src/shared src/systemctl

Lennart Poettering lennart at kemper.freedesktop.org
Thu Oct 18 14:35:52 PDT 2012


 man/sd_journal_query_unique.xml |    2 +-
 src/journal/journalctl.c        |   24 +++++++++++++++---------
 src/shared/logs-show.c          |    2 +-
 src/shared/pager.c              |   22 ++++++++++++++--------
 src/shared/pager.h              |    3 ++-
 src/systemctl/systemctl.c       |    5 +++--
 6 files changed, 36 insertions(+), 22 deletions(-)

New commits:
commit f89a3b6f5bf695186e7b9e6cc63993b1272e7569
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Oct 18 23:34:37 2012 +0200

    journalctl: unify ellipsation handling between journalctl and systemctl

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 5185b4b..d6f19e9 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -840,7 +840,6 @@ int main(int argc, char *argv[]) {
         bool need_seek = false;
         sd_id128_t previous_boot_id;
         bool previous_boot_id_valid = false;
-        bool have_pager;
         unsigned n_shown = 0;
 
         log_parse_environment();
@@ -984,7 +983,9 @@ int main(int argc, char *argv[]) {
         }
 
         on_tty();
-        have_pager = !arg_no_pager && !arg_follow && pager_open();
+
+        if (!arg_no_pager && !arg_follow)
+                pager_open();
 
         if (!arg_quiet) {
                 usec_t start, end;
@@ -1048,7 +1049,7 @@ int main(int argc, char *argv[]) {
 
                         flags =
                                 arg_all * OUTPUT_SHOW_ALL |
-                                (!on_tty() || have_pager) * OUTPUT_FULL_WIDTH |
+                                (!on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
                                 on_tty() * OUTPUT_COLOR;
 
                         r = output_journal(stdout, j, arg_output, 0, flags);
diff --git a/src/shared/pager.c b/src/shared/pager.c
index 36b409c..6799787 100644
--- a/src/shared/pager.c
+++ b/src/shared/pager.c
@@ -44,20 +44,21 @@ _noreturn_ static void pager_fallback(void) {
         _exit(EXIT_SUCCESS);
 }
 
-bool pager_open(void) {
+int pager_open(void) {
         int fd[2];
         const char *pager;
         pid_t parent_pid;
+        int r;
 
         if (pager_pid > 0)
-                return false;
+                return 1;
 
         if ((pager = getenv("SYSTEMD_PAGER")) || (pager = getenv("PAGER")))
                 if (!*pager || streq(pager, "cat"))
-                        return false;
+                        return 0;
 
         if (isatty(STDOUT_FILENO) <= 0)
-                return false;
+                return 0;
 
         /* Determine and cache number of columns before we spawn the
          * pager so that we get the value from the actual tty */
@@ -65,16 +66,17 @@ bool pager_open(void) {
 
         if (pipe(fd) < 0) {
                 log_error("Failed to create pager pipe: %m");
-                return false;
+                return -errno;
         }
 
         parent_pid = getpid();
 
         pager_pid = fork();
         if (pager_pid < 0) {
+                r = -errno;
                 log_error("Failed to fork pager: %m");
                 close_pipe(fd);
-                return false;
+                return r;
         }
 
         /* In the child start the pager */
@@ -117,11 +119,11 @@ bool pager_open(void) {
         /* Return in the parent */
         if (dup2(fd[1], STDOUT_FILENO) < 0) {
                 log_error("Failed to duplicate pager pipe: %m");
-                return false;
+                return -errno;
         }
 
         close_pipe(fd);
-        return true;
+        return 1;
 }
 
 void pager_close(void) {
@@ -135,3 +137,7 @@ void pager_close(void) {
         wait_for_terminate(pager_pid, NULL);
         pager_pid = 0;
 }
+
+bool pager_have(void) {
+        return pager_pid > 0;
+}
diff --git a/src/shared/pager.h b/src/shared/pager.h
index 0b4afc0..5e7b5ab 100644
--- a/src/shared/pager.h
+++ b/src/shared/pager.h
@@ -23,5 +23,6 @@
 
 #include <stdbool.h>
 
-bool pager_open(void);
+int pager_open(void);
 void pager_close(void);
+bool pager_have(void);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 7d6a6a2..82c801e 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2293,9 +2293,10 @@ static void print_status_info(UnitStatusInfo *i) {
         if (i->id && arg_transport != TRANSPORT_SSH) {
                 int flags =
                         arg_all * OUTPUT_SHOW_ALL |
+                        (!on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
+                        on_tty() * OUTPUT_COLOR |
                         arg_follow * OUTPUT_FOLLOW |
-                        !arg_quiet * OUTPUT_WARN_CUTOFF |
-                        on_tty() * OUTPUT_COLOR;
+                        !arg_quiet * OUTPUT_WARN_CUTOFF;
 
                 printf("\n");
                 show_journal_by_unit(stdout,

commit cd4b13e0bfe9281a0d2c0c3bef1c589d0684950b
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Oct 18 23:22:56 2012 +0200

    journalctl: don't ellipsize unless on a tty

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 7564c48..5185b4b 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -57,7 +57,7 @@
 
 static OutputMode arg_output = OUTPUT_SHORT;
 static bool arg_follow = false;
-static bool arg_show_all = false;
+static bool arg_all = false;
 static bool arg_no_pager = false;
 static unsigned arg_lines = 0;
 static bool arg_no_tail = false;
@@ -87,15 +87,15 @@ static enum {
 
 static int help(void) {
 
-        printf("%s [OPTIONS...] [MATCH]\n\n"
+        printf("%s [OPTIONS...] [MATCHES...]\n\n"
                "Query the journal.\n\n"
                "Flags:\n"
-               "  -c --cursor=CURSOR     Start showing entries from specified cursor\n"
                "     --since=DATE        Start showing entries newer or of the specified date\n"
                "     --until=DATE        Stop showing entries older or of the specified date\n"
+               "  -c --cursor=CURSOR     Start showing entries from specified cursor\n"
                "  -b --this-boot         Show data only from current boot\n"
                "  -u --unit=UNIT         Show data only from the specified unit\n"
-               "  -p --priority=RANGE    Show only messages within the specified priority range\n\n"
+               "  -p --priority=RANGE    Show only messages within the specified priority range\n"
                "  -f --follow            Follow journal\n"
                "  -n --lines[=INTEGER]   Number of journal entries to show\n"
                "     --no-tail           Show all lines, even in follow mode\n"
@@ -217,7 +217,7 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case 'a':
-                        arg_show_all = true;
+                        arg_all = true;
                         break;
 
                 case 'n':
@@ -1047,8 +1047,8 @@ int main(int argc, char *argv[]) {
                         }
 
                         flags =
-                                arg_show_all * OUTPUT_SHOW_ALL |
-                                have_pager * OUTPUT_FULL_WIDTH |
+                                arg_all * OUTPUT_SHOW_ALL |
+                                (!on_tty() || have_pager) * OUTPUT_FULL_WIDTH |
                                 on_tty() * OUTPUT_COLOR;
 
                         r = output_journal(stdout, j, arg_output, 0, flags);
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 0589536..63a48e4 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -243,7 +243,7 @@ static int output_short(
                 }
         }
 
-        if (flags)
+        if (flags & OUTPUT_SHOW_ALL)
                 fprintf(f, ": %s%.*s%s\n", color_on, (int) message_len, message, color_off);
         else if (!utf8_is_printable_n(message, message_len)) {
                 char bytes[FORMAT_BYTES_MAX];

commit fd6e88753716d8136037277c7db2196e0f979675
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Oct 18 22:55:12 2012 +0200

    journalctl: honour -n if -F is used

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 5980eb0..7564c48 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -926,11 +926,16 @@ int main(int argc, char *argv[]) {
                 SD_JOURNAL_FOREACH_UNIQUE(j, data, size) {
                         const void *eq;
 
+                        if (arg_lines > 0 && n_shown >= arg_lines)
+                                break;
+
                         eq = memchr(data, '=', size);
                         if (eq)
                                 printf("%.*s\n", (int) (size - ((const uint8_t*) eq - (const uint8_t*) data + 1)), (const char*) eq + 1);
                         else
                                 printf("%.*s\n", (int) size, (const char*) data);
+
+                        n_shown ++;
                 }
 
                 r = 0;

commit 0902aa1838ecf3b252ab0d02842ce4f9c1cab58d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Oct 18 22:54:58 2012 +0200

    man: ensure example of sd_journal_query_unique() compiles cleanly

diff --git a/man/sd_journal_query_unique.xml b/man/sd_journal_query_unique.xml
index 278506a..b0e43df 100644
--- a/man/sd_journal_query_unique.xml
+++ b/man/sd_journal_query_unique.xml
@@ -176,7 +176,7 @@
 
 int main(int argc, char *argv[]) {
         sd_journal *j;
-        const char *d;
+        const void *d;
         size_t l;
         int r;
 



More information about the systemd-commits mailing list