systemd: serve kernel-log, the kernel's messages of one boot (issue 1975)
journalctl --dmesg --boot=N under the same escalation, window, priority, fixed-string match, 2000-line cap and redaction as the journal verb (shapeLines is the one filter both use); a boot is 0 or a negative whole number, refused otherwise before anything runs. No scope: the kernel belongs to no manager. Builds: issue 1975, the operator's request of 2026-11-12 (the lead's handover; no design line names the verb) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -28,6 +28,8 @@ const (
|
||||
LongestLine = 4096
|
||||
// LongestMatch is the longest text a match may be.
|
||||
LongestMatch = 256
|
||||
// MostBoots is how far back a kernel-log read may name a boot.
|
||||
MostBoots = 9999
|
||||
)
|
||||
|
||||
// JournalQuery is what a journal read is narrowed by.
|
||||
@@ -37,6 +39,8 @@ type JournalQuery struct {
|
||||
Until string
|
||||
Match string
|
||||
Priority string
|
||||
// Boot is which boot a kernel-log read is of: "0" this boot, "-1" the one before, and so on (empty is "0").
|
||||
Boot string
|
||||
}
|
||||
|
||||
// relative is a time journalctl reads relative to now: -30min, +1h, 2h30min ago, and the day words.
|
||||
@@ -101,6 +105,13 @@ func (q JournalQuery) valid() (JournalQuery, error) {
|
||||
return q, fmt.Errorf("priority %q: 0-7, or emerg, alert, crit, err, warning, notice, info, debug", q.Priority)
|
||||
}
|
||||
}
|
||||
if q.Boot != "" {
|
||||
n, err := strconv.Atoi(q.Boot)
|
||||
if err != nil || n > 0 || n < -MostBoots {
|
||||
return q, fmt.Errorf("boot %q: 0 for this boot, -1 for the one before, and so on (down to -%d)", q.Boot, MostBoots)
|
||||
}
|
||||
q.Boot = strconv.Itoa(n)
|
||||
}
|
||||
if len(q.Match) > LongestMatch {
|
||||
return q, fmt.Errorf("a match is at most %d bytes", LongestMatch)
|
||||
}
|
||||
@@ -112,7 +123,21 @@ func (q JournalQuery) valid() (JournalQuery, error) {
|
||||
|
||||
// argv is journalctl's words for a valid query: each value inside the word of its own option.
|
||||
func (q JournalQuery) argv(unit string, lines int) []string {
|
||||
args := []string{"--no-pager", "--output=short-iso", "--unit=" + unit}
|
||||
return q.window([]string{"--no-pager", "--output=short-iso", "--unit=" + unit}, lines)
|
||||
}
|
||||
|
||||
// kernelArgv is journalctl's words for a valid query of the kernel's messages of one boot (-k, as dmesg
|
||||
// reads them, but also of an earlier boot and in a window).
|
||||
func (q JournalQuery) kernelArgv(lines int) []string {
|
||||
boot := q.Boot
|
||||
if boot == "" {
|
||||
boot = "0"
|
||||
}
|
||||
return q.window([]string{"--no-pager", "--output=short-iso", "--dmesg", "--boot=" + boot}, lines)
|
||||
}
|
||||
|
||||
// window adds the window, the priority and the line count to the words that choose what is read.
|
||||
func (q JournalQuery) window(args []string, lines int) []string {
|
||||
if q.Since != "" {
|
||||
v, _, _ := when("since", q.Since, false)
|
||||
args = append(args, "--since="+v)
|
||||
@@ -149,7 +174,7 @@ func journalQuery(a map[string]any) (JournalQuery, error) {
|
||||
default:
|
||||
return q, fmt.Errorf("lines: a whole number")
|
||||
}
|
||||
for name, into := range map[string]*string{"since": &q.Since, "until": &q.Until, "match": &q.Match, "priority": &q.Priority} {
|
||||
for name, into := range map[string]*string{"since": &q.Since, "until": &q.Until, "match": &q.Match, "priority": &q.Priority, "boot": &q.Boot} {
|
||||
switch v := a[name].(type) {
|
||||
case nil:
|
||||
case string:
|
||||
@@ -159,7 +184,7 @@ func journalQuery(a map[string]any) (JournalQuery, error) {
|
||||
*into = strings.TrimSpace(v)
|
||||
}
|
||||
case float64:
|
||||
if name != "priority" {
|
||||
if name != "priority" && name != "boot" {
|
||||
return q, fmt.Errorf("%s: text", name)
|
||||
}
|
||||
*into = strconv.FormatFloat(v, 'f', -1, 64)
|
||||
|
||||
Reference in New Issue
Block a user