-
Type:
Problem report
-
Resolution: Unresolved
-
Priority:
Trivial
-
None
-
Affects Version/s: 7.0.25rc1, 7.4.6, 7.4.9rc1
-
Component/s: Agent2 (G)
-
Environment:- Any Linux system using systemd
- Units with generated unit files (e.g., auto-mounted filesystems)
Steps to Reproduce
1. Create or trigger a generated mount unit (e.g., mount a filesystem that gets automatically registered with systemd)
2. Run the discovery: systemd.unit.discovery[mount]
3. Observe that generated units are not in the JSON output
Actual Result
Generated units are excluded from discovery results.
Expected Result
Generated units should appear in discovery results with proper UnitFileState information.
Root Cause Analysis
Bug #1: Missing "generated" state in stateNames array
Location: systemd.go, function setUnitStates(), lines 371-394
The stateNames array for UnitFileState does not include "generated":
"UnitFileState", []string{ "enabled", "enabled-runtime", "linked", "linked-runtime", "masked", "masked-runtime", "static", "disabled", "invalid", // "generated" is MISSING! },
Impact: When setUnitStates() processes a unit with UnitFileState="generated", it maps to state
{0, "generated"}(unknown state with value 0).
Additional missing states: "static", "linked", "linked-runtime", "enabled-indirect", "transient", "linking" may also not be properly handled.
Bug #2: discovery() does not call setUnitStates()
Location: systemd.go, function discovery(), lines 216-299
The setUnitStates() function is only called in get() (line 189), but NOT in discovery().
Impact: Even if setUnitStates() had the correct states, the discovery function wouldn't use it to convert states to structured format.
Bug #3: Second loop only processes "disabled" units
Location: systemd.go, function discovery(), lines 276-291
The second loop is intended to add disabled unit files that aren't in the runtime list:
if f.EnablementState != "disabled" || (len(ext) != 0 && ext != unitFileExt) || strings.HasSuffix(strings.TrimSuffix(f.Name, unitFileExt), "@") || isEnabledUnit(array, basePath) { continue }
Impact: This loop only adds units with EnablementState="disabled". However, the first loop should be handling all units from ListUnits, so this isn't the primary issue for generated units that ARE in the runtime list.