diff --git a/modules/systemd/cmd/systemd-tools/client.go b/modules/systemd/cmd/systemd-tools/client.go index 3dd64ecbe..4eaf14651 100644 --- a/modules/systemd/cmd/systemd-tools/client.go +++ b/modules/systemd/cmd/systemd-tools/client.go @@ -319,6 +319,9 @@ func (m *Manager) Journal(scope Scope, unit string, q JournalQuery) (map[string] if err := unitArg(unit); err != nil { return nil, err } + if q.Boot != "" { + return nil, fmt.Errorf("boot %q: the journal of a unit is not read by boot; kernel-log takes a boot", q.Boot) + } q, err := q.valid() if err != nil { return nil, err diff --git a/modules/systemd/cmd/systemd-tools/journal_test.go b/modules/systemd/cmd/systemd-tools/journal_test.go index d7be03174..bf005b220 100644 --- a/modules/systemd/cmd/systemd-tools/journal_test.go +++ b/modules/systemd/cmd/systemd-tools/journal_test.go @@ -242,7 +242,7 @@ func TestFailedIsOnTheSeatAndNarrowsToAScope(t *testing.T) { } } -// The kernel-log verb (issue 1975): the kernel's messages of one boot, in the journal verb's window, priority, +// 1975/AC1: kernel-log reads journalctl --dmesg --boot=N under journal's escalation (issue 1975): the kernel's messages of one boot, in the journal verb's window, priority, // match, cap and redaction, and a boot named 0, -1, and so on. func TestTheKernelLogIsOneBootsMessagesInTheJournalsForms(t *testing.T) { var calls []call @@ -274,6 +274,7 @@ func TestTheKernelLogIsOneBootsMessagesInTheJournalsForms(t *testing.T) { } } +// 1975/AC2: a boot that is not 0 to -9999 is refused and no command runs. func TestAKernelLogBootIsRefusedBeforeAnythingRunsUnlessItIsZeroOrBefore(t *testing.T) { for _, bad := range []string{"1", "abc", "--user", "-1 --merge", "-10000", "0x1", "-1;id"} { var calls []call @@ -287,6 +288,7 @@ func TestAKernelLogBootIsRefusedBeforeAnythingRunsUnlessItIsZeroOrBefore(t *test } } +// 1975/AC3: the window, priority, match, 2000-line cap and redaction are journal's. func TestTheKernelLogKeepsTheCapTheMatchAndTheRedaction(t *testing.T) { var calls []call m := journalOf([]string{"k one", "k password=hunter2secretvalue here", "k two"}, "", &calls) @@ -313,3 +315,15 @@ func TestTheKernelLogKeepsTheCapTheMatchAndTheRedaction(t *testing.T) { t.Errorf("a secret in a kernel line was answered: %v", got) } } + +// 1975/AC4: journal refuses a boot argument it does not use, never reading this boot quietly. +func TestJournalRefusesABootArgument(t *testing.T) { + var calls []call + m := journalOf([]string{"a"}, "", &calls) + if _, err := m.Journal(System, "mail.service", JournalQuery{Boot: "-1"}); err == nil { + t.Fatal("journal accepted a boot and read this boot") + } + if len(calls) != 0 { + t.Fatalf("a refused boot reached the manager: %v", calls) + } +}