summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHATAYAMA Daisuke <d.hatayama@fujitsu.com>2020-03-01 06:31:38 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-03-02 18:27:55 +0900
commit27f31daf3e2288583c6d1e2a11e578463eecef0a (patch)
treef38da8bb115b56f178856ad6d402a271db155784
parentef62949a23a2d6dc722659cc527f6e0006135dc9 (diff)
downloadsystemd-27f31daf3e2288583c6d1e2a11e578463eecef0a.tar.gz
shared/logs-show: Remove unused OUTPUT_FOLLOW
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.
-rw-r--r--src/shared/logs-show.c111
-rw-r--r--src/shared/output-mode.h17
2 files changed, 58 insertions, 70 deletions
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index b83f543ba8..2bfd0b60c2 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -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;
diff --git a/src/shared/output-mode.h b/src/shared/output-mode.h
index 00b6032056..1b4765b3ec 100644
--- a/src/shared/output-mode.h
+++ b/src/shared/output-mode.h
@@ -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);