chiark / gitweb /
journalctl: unify ellipsation handling between journalctl and systemctl
authorLennart Poettering <lennart@poettering.net>
Thu, 18 Oct 2012 21:34:37 +0000 (23:34 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 18 Oct 2012 21:35:44 +0000 (23:35 +0200)
src/journal/journalctl.c
src/shared/pager.c
src/shared/pager.h
src/systemctl/systemctl.c

index 5185b4b..d6f19e9 100644 (file)
@@ -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);
index 36b409c..6799787 100644 (file)
@@ -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;
+}
index 0b4afc0..5e7b5ab 100644 (file)
@@ -23,5 +23,6 @@
 
 #include <stdbool.h>
 
-bool pager_open(void);
+int pager_open(void);
 void pager_close(void);
+bool pager_have(void);
index 7d6a6a2..82c801e 100644 (file)
@@ -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,