]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/logs-show: Remove unused OUTPUT_FOLLOW
authorHATAYAMA Daisuke <d.hatayama@fujitsu.com>
Sat, 29 Feb 2020 21:31:38 +0000 (06:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 2 Mar 2020 09:27:55 +0000 (18:27 +0900)
As of the commit aae9a96d4b3a8562af9e8c6a23871b442645b954 removing --follow
option in systemctl command, OUTPUT_FOLLOW has never been set anywhere. Let's
remove it.

The condition expression of the if-statement in show_journal() that refers to
OUTPUT_FOLLOW now thus evaluates always to true. Hence, the call of
sd_journal_wait() is in dead code, and the outer infinite for-loop is
meaningless, which we remove as cleanup.

There is no functional change by this commit.

src/shared/logs-show.c
src/shared/output-mode.h

index b83f543ba8ea50b7710707d67164fef69ec8ebc1..2bfd0b60c26b1198eb1802ec91ab8c52123a5b1e 100644 (file)
@@ -1181,85 +1181,74 @@ int show_journal(
         }
 
         for (;;) {
-                for (;;) {
-                        usec_t usec;
+                usec_t usec;
 
-                        if (need_seek) {
-                                r = sd_journal_next(j);
-                                if (r < 0)
-                                        return log_error_errno(r, "Failed to iterate through journal: %m");
-                        }
-
-                        if (r == 0)
-                                break;
+                if (need_seek) {
+                        r = sd_journal_next(j);
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to iterate through journal: %m");
+                }
 
-                        need_seek = true;
+                if (r == 0)
+                        break;
 
-                        if (not_before > 0) {
-                                r = sd_journal_get_monotonic_usec(j, &usec, NULL);
+                need_seek = true;
 
-                                /* -ESTALE is returned if the
-                                   timestamp is not from this boot */
-                                if (r == -ESTALE)
-                                        continue;
-                                else if (r < 0)
-                                        return log_error_errno(r, "Failed to get journal time: %m");
+                if (not_before > 0) {
+                        r = sd_journal_get_monotonic_usec(j, &usec, NULL);
 
-                                if (usec < not_before)
-                                        continue;
-                        }
+                        /* -ESTALE is returned if the timestamp is not from this boot */
+                        if (r == -ESTALE)
+                                continue;
+                        else if (r < 0)
+                                return log_error_errno(r, "Failed to get journal time: %m");
 
-                        line++;
-                        maybe_print_begin_newline(f, &flags);
-
-                        r = show_journal_entry(f, j, mode, n_columns, flags, NULL, NULL, ellipsized);
-                        if (r < 0)
-                                return r;
+                        if (usec < not_before)
+                                continue;
                 }
 
-                if (warn_cutoff && line < how_many && not_before > 0) {
-                        sd_id128_t boot_id;
-                        usec_t cutoff = 0;
-
-                        /* Check whether the cutoff line is too early */
+                line++;
+                maybe_print_begin_newline(f, &flags);
 
-                        r = sd_id128_get_boot(&boot_id);
-                        if (r < 0)
-                                return log_error_errno(r, "Failed to get boot id: %m");
+                r = show_journal_entry(f, j, mode, n_columns, flags, NULL, NULL, ellipsized);
+                if (r < 0)
+                        return r;
+        }
 
-                        r = sd_journal_get_cutoff_monotonic_usec(j, boot_id, &cutoff, NULL);
-                        if (r < 0)
-                                return log_error_errno(r, "Failed to get journal cutoff time: %m");
+        if (warn_cutoff && line < how_many && not_before > 0) {
+                sd_id128_t boot_id;
+                usec_t cutoff = 0;
 
-                        if (r > 0 && not_before < cutoff) {
-                                maybe_print_begin_newline(f, &flags);
+                /* Check whether the cutoff line is too early */
 
-                                /* If we logged *something* and no permission error happened, than we can
-                                 * reliably emit the warning about rotation. If we didn't log anything and
-                                 * access errors happened, emit hint about permissions. Otherwise, give a
-                                 * generic message, since we can't diagnose the issue. */
+                r = sd_id128_get_boot(&boot_id);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to get boot id: %m");
 
-                                bool noaccess = journal_access_blocked(j);
+                r = sd_journal_get_cutoff_monotonic_usec(j, boot_id, &cutoff, NULL);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to get journal cutoff time: %m");
 
-                                if (line == 0 && noaccess)
-                                        fprintf(f, "Warning: some journal files were not opened due to insufficient permissions.");
-                                else if (!noaccess)
-                                        fprintf(f, "Warning: journal has been rotated since unit was started, output may be incomplete.\n");
-                                else
-                                        fprintf(f, "Warning: journal has been rotated since unit was started and some journal "
-                                                "files were not opened due to insufficient permissions, output may be incomplete.\n");
-                        }
+                if (r > 0 && not_before < cutoff) {
+                        maybe_print_begin_newline(f, &flags);
 
-                        warn_cutoff = false;
-                }
+                        /* If we logged *something* and no permission error happened, than we can reliably
+                         * emit the warning about rotation. If we didn't log anything and access errors
+                         * happened, emit hint about permissions. Otherwise, give a generic message, since we
+                         * can't diagnose the issue. */
 
-                if (!(flags & OUTPUT_FOLLOW))
-                        break;
+                        bool noaccess = journal_access_blocked(j);
 
-                r = sd_journal_wait(j, USEC_INFINITY);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to wait for journal: %m");
+                        if (line == 0 && noaccess)
+                                fprintf(f, "Warning: some journal files were not opened due to insufficient permissions.");
+                        else if (!noaccess)
+                                fprintf(f, "Warning: journal has been rotated since unit was started, output may be incomplete.\n");
+                        else
+                                fprintf(f, "Warning: journal has been rotated since unit was started and some journal "
+                                        "files were not opened due to insufficient permissions, output may be incomplete.\n");
+                }
 
+                warn_cutoff = false;
         }
 
         return 0;
index 00b603205671902e5c93ec95b65f82ab1727898f..1b4765b3ec10e41faa2a0fafc55acc1151beb9c3 100644 (file)
@@ -33,15 +33,14 @@ static inline bool OUTPUT_MODE_IS_JSON(OutputMode m) {
 
 typedef enum OutputFlags {
         OUTPUT_SHOW_ALL       = 1 << 0,
-        OUTPUT_FOLLOW         = 1 << 1,
-        OUTPUT_WARN_CUTOFF    = 1 << 2,
-        OUTPUT_FULL_WIDTH     = 1 << 3,
-        OUTPUT_COLOR          = 1 << 4,
-        OUTPUT_CATALOG        = 1 << 5,
-        OUTPUT_BEGIN_NEWLINE  = 1 << 6,
-        OUTPUT_UTC            = 1 << 7,
-        OUTPUT_KERNEL_THREADS = 1 << 8,
-        OUTPUT_NO_HOSTNAME    = 1 << 9,
+        OUTPUT_WARN_CUTOFF    = 1 << 1,
+        OUTPUT_FULL_WIDTH     = 1 << 2,
+        OUTPUT_COLOR          = 1 << 3,
+        OUTPUT_CATALOG        = 1 << 4,
+        OUTPUT_BEGIN_NEWLINE  = 1 << 5,
+        OUTPUT_UTC            = 1 << 6,
+        OUTPUT_KERNEL_THREADS = 1 << 7,
+        OUTPUT_NO_HOSTNAME    = 1 << 8,
 } OutputFlags;
 
 JsonFormatFlags output_mode_to_json_format_flags(OutputMode m);