summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-02-27 19:51:57 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-02-27 19:52:08 +0100
commit1a8f0ce64fd205960dc92305dc42ba3bf5d71902 (patch)
tree72853b75fc6945ab513fde51668cb086e38c7102
parent1ad448673ed3bfb0f989909485f01f485888d90d (diff)
downloadsystemd-1a8f0ce64fd205960dc92305dc42ba3bf5d71902.tar.gz
systemctl: be more specific when emitting warning about rotated journal
See inline comment for disucssion. Fixes #14281.
-rw-r--r--src/shared/journal-util.c6
-rw-r--r--src/shared/journal-util.h2
-rw-r--r--src/shared/logs-show.c17
3 files changed, 22 insertions, 3 deletions
diff --git a/src/shared/journal-util.c b/src/shared/journal-util.c
index 2f672c2935..cb3762df43 100644
--- a/src/shared/journal-util.c
+++ b/src/shared/journal-util.c
@@ -80,6 +80,10 @@ static int access_check_var_log_journal(sd_journal *j, bool want_other_users) {
return 1;
}
+int journal_access_blocked(sd_journal *j) {
+ return hashmap_contains(j->errors, INT_TO_PTR(-EACCES));
+}
+
int journal_access_check_and_warn(sd_journal *j, bool quiet, bool want_other_users) {
Iterator it;
void *code;
@@ -95,7 +99,7 @@ int journal_access_check_and_warn(sd_journal *j, bool quiet, bool want_other_use
return 0;
}
- if (hashmap_contains(j->errors, INT_TO_PTR(-EACCES))) {
+ if (journal_access_blocked(j)) {
if (!quiet)
(void) access_check_var_log_journal(j, want_other_users);
diff --git a/src/shared/journal-util.h b/src/shared/journal-util.h
index da86434a67..34ad1bfc8e 100644
--- a/src/shared/journal-util.h
+++ b/src/shared/journal-util.h
@@ -7,5 +7,5 @@
#include "sd-journal.h"
bool journal_field_valid(const char *p, size_t l, bool allow_protected);
-
+int journal_access_blocked(sd_journal *j);
int journal_access_check_and_warn(sd_journal *j, bool quiet, bool want_other_users);
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 605412aec5..b83f543ba8 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -20,6 +20,7 @@
#include "id128-util.h"
#include "io-util.h"
#include "journal-internal.h"
+#include "journal-util.h"
#include "json.h"
#include "log.h"
#include "logs-show.h"
@@ -1232,7 +1233,21 @@ int show_journal(
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");
+
+ /* 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. */
+
+ bool noaccess = journal_access_blocked(j);
+
+ 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;