Documentation
¶
Overview ¶
Package quadlet parses systemd unit files with Quadlet semantics.
The format is systemd's INI dialect, which differs from common INI in ways that matter here:
- Keys may repeat within a section. `Volume=` appearing five times is five mounts, not one key overwritten four times, so the model is a list of entries rather than a map.
- A line ending in a backslash continues onto the next line. systemd joins the fragments with a space, so the joined value is not simply the concatenation of the parts.
- Both `#` and `;` start a comment, but only at the beginning of a line. A `#` inside a value is part of the value.
- The same section may appear more than once; systemd treats the second occurrence as a continuation of the first.
Parsing preserves enough of the original text to render it back byte for byte. The fix engine depends on that: rewriting one mount option must not reflow comments or reorder keys elsewhere in the file.
Reference: systemd.syntax(7) and podman-systemd.unit(5).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
Entry is a single Key=value assignment together with the section it appeared in. Rules work in terms of entries.
type File ¶
type File struct {
// Path is where the file came from. Findings cite it.
Path string
// Lines is every logical line in order, including blanks and comments.
Lines []Line
// contains filtered or unexported fields
}
File is a parsed unit file that can be rendered back to its original bytes.
func Parse ¶
Parse reads a unit file. It does not fail on unrecognised lines: a linter that refuses to parse is useless on exactly the malformed files a user most needs linted. Such lines are kept as LineUnknown for a rule to report.
func (*File) HasSection ¶
HasSection reports whether the named section appears at all, even empty. The distinction matters for `[Install]`: an empty one is still a statement of intent, whereas an absent one means the unit will never autostart.
func (*File) Lookup ¶
Lookup returns the last value of a key within a section. systemd's last-one-wins applies to keys that are not list-valued; for list-valued keys use Values.
func (*File) Render ¶
Render writes the file back out. For an unmodified file the result is byte-identical to the input; this is asserted by a round-trip test over every fixture.
type Line ¶
type Line struct {
Kind LineKind
// Raw holds the original physical lines, without their terminators, so
// the file can be rendered back exactly as it arrived.
Raw []string
// Number is the 1-based physical line number where this logical line
// starts. Findings cite it.
Number int
// Section is set for LineSection: the name inside the brackets.
Section string
// Key and Value are set for LineEntry. Value is the logical value, with
// continuations already joined; Raw retains how it was written.
Key string
Value string
}
Line is one logical line of a unit file. A logical line spans several physical lines when continuations are used.
type LineKind ¶
type LineKind int
LineKind classifies a physical line, so rendering can reproduce the original file without keeping a second copy of it.
const ( // LineBlank is an empty or whitespace-only line. LineBlank LineKind = iota // LineComment is a line whose first non-space character is '#' or ';'. LineComment // LineSection is a `[Section]` header. LineSection // LineEntry is a `Key=value` assignment, possibly spanning continuations. LineEntry // LineUnknown is a line we could not classify. It is preserved verbatim // and reported, rather than being silently dropped. LineUnknown )