| index 73749cd..2a69f3b 100644 | ||
| --- a/src/plugin_services.c | ||
| +++ b/src/plugin_services.c | ||
| @@ -820,11 +820,37 @@ static void collect_systemd(void) | ||
| 820 | 820 | char *sb = read_file_all(show_mock, &len); |
| 821 | 821 | if (sb) { apply_show(sb); free(sb); } |
| 822 | 822 | } else if (!mock || !*mock) { |
| 823 | - if (capture("systemctl show --type=service --all -p Id -p MainPID " | |
| 824 | - "-p ActiveEnterTimestamp -p MemoryCurrent " | |
| 825 | - "-p UnitFileState -p ActiveState -p SubState " | |
| 826 | - "-p Description 2>/dev/null", out, sizeof out) > 0) | |
| 827 | - apply_show(out); | |
| 823 | + /* `systemctl show --type=service --all` prints NOTHING on systemd | |
| 824 | + * 249 (verified on the fleet): the --all/--type pair silently | |
| 825 | + * selects an empty set, so the first live install reported 111 | |
| 826 | + * units with pid 0 and enabled "-" for every one of them. Asking | |
| 827 | + * for the units by name is the form that works everywhere, and | |
| 828 | + * every name is re-validated before it goes into the command, in | |
| 829 | + * batches small enough to stay well inside ARG_MAX. */ | |
| 830 | + char *names[MAX_SERVICES]; | |
| 831 | + int i, n_names = 0; | |
| 832 | + for (i = 0; i < g_count; i++) { | |
| 833 | + if (!valid_unit(g_svc[i].name)) continue; | |
| 834 | + names[n_names++] = g_svc[i].name; | |
| 835 | + } | |
| 836 | + for (i = 0; i < n_names; i += 40) { | |
| 837 | + char cmd[8192]; | |
| 838 | + size_t used; | |
| 839 | + int k, upto = i + 40; | |
| 840 | + snprintf(cmd, sizeof cmd, | |
| 841 | + "systemctl show -p Id -p MainPID -p ActiveEnterTimestamp " | |
| 842 | + "-p MemoryCurrent -p UnitFileState -p ActiveState " | |
| 843 | + "-p SubState -p Description 2>/dev/null"); | |
| 844 | + used = strlen(cmd); | |
| 845 | + if (upto > n_names) upto = n_names; | |
| 846 | + for (k = i; k < upto && used + NAME_SZ + 2 < sizeof cmd; k++) { | |
| 847 | + cmd[used++] = ' '; | |
| 848 | + str_copy(cmd + used, sizeof cmd - used, names[k]); | |
| 849 | + used += strlen(names[k]); | |
| 850 | + cmd[used] = '\0'; | |
| 851 | + } | |
| 852 | + if (capture(cmd, out, sizeof out) > 0) apply_show(out); | |
| 853 | + } | |
| 828 | 854 | } |
| 829 | 855 | } |
| 830 | 856 | } |
| index 66d2045..d59ea44 100644 | ||
| --- a/tests/run.sh | ||
| +++ b/tests/run.sh | ||
| @@ -382,6 +382,8 @@ grep -q 'QueryServiceConfigA' src/plugin_services.c && pass "Windows reads the s | ||
| 382 | 382 | grep -q '_DARWIN_C_SOURCE' src/plugin_services.c && pass "_DARWIN_C_SOURCE is defined for Apple" || fail "_DARWIN_C_SOURCE missing" |
| 383 | 383 | grep -q 'launchctl list' src/plugin_services.c && pass "macOS reads launchctl list" || fail "no launchctl list" |
| 384 | 384 | grep -q 'output=json' src/plugin_services.c && pass "systemd uses --output=json first" || fail "no --output=json" |
| 385 | +grep -q 'systemctl show --type=service --all' src/plugin_services.c && fail "the empty-set 'show --type= --all' form is back" || pass "show asks for units by name, not the empty --type/--all set" | |
| 386 | +grep -q 'systemctl show -p Id' src/plugin_services.c && pass "the enrichment pass asks for units by name" || fail "no per-unit show call" | |
| 385 | 387 | grep -q 'not-found' src/plugin_services.c && pass "there is a legacy-table fallback path" || fail "no not-found handling" |
| 386 | 388 | grep -q 'init_system' src/plugin_services.c && pass "the API reports init_system" || fail "no init_system" |
| 387 | 389 | grep -q 'control_enabled' src/plugin_services.c && pass "the API reports control_enabled" || fail "no control_enabled" |
| 388 | 390 |
| index 73749cd..2a69f3b 100644 | index 73749cd..2a69f3b 100644 | ||
| --- a/src/plugin_services.c | --- a/src/plugin_services.c | ||
| +++ b/src/plugin_services.c | +++ b/src/plugin_services.c | ||
| @@ -820,11 +820,37 @@ static void collect_systemd(void) | @@ -820,11 +820,37 @@ static void collect_systemd(void) | ||
| 820 | char *sb = read_file_all(show_mock, &len); | 820 | char *sb = read_file_all(show_mock, &len); |
| 821 | if (sb) { apply_show(sb); free(sb); } | 821 | if (sb) { apply_show(sb); free(sb); } |
| 822 | } else if (!mock || !*mock) { | 822 | } else if (!mock || !*mock) { |
| 823 | - if (capture("systemctl show --type=service --all -p Id -p MainPID " | 823 | + /* `systemctl show --type=service --all` prints NOTHING on systemd |
| 824 | - "-p ActiveEnterTimestamp -p MemoryCurrent " | 824 | + * 249 (verified on the fleet): the --all/--type pair silently |
| 825 | - "-p UnitFileState -p ActiveState -p SubState " | 825 | + * selects an empty set, so the first live install reported 111 |
| 826 | - "-p Description 2>/dev/null", out, sizeof out) > 0) | 826 | + * units with pid 0 and enabled "-" for every one of them. Asking |
| 827 | - apply_show(out); | 827 | + * for the units by name is the form that works everywhere, and |
| 828 | + * every name is re-validated before it goes into the command, in | ||
| 829 | + * batches small enough to stay well inside ARG_MAX. */ | ||
| 830 | + char *names[MAX_SERVICES]; | ||
| 831 | + int i, n_names = 0; | ||
| 832 | + for (i = 0; i < g_count; i++) { | ||
| 833 | + if (!valid_unit(g_svc[i].name)) continue; | ||
| 834 | + names[n_names++] = g_svc[i].name; | ||
| 835 | + } | ||
| 836 | + for (i = 0; i < n_names; i += 40) { | ||
| 837 | + char cmd[8192]; | ||
| 838 | + size_t used; | ||
| 839 | + int k, upto = i + 40; | ||
| 840 | + snprintf(cmd, sizeof cmd, | ||
| 841 | + "systemctl show -p Id -p MainPID -p ActiveEnterTimestamp " | ||
| 842 | + "-p MemoryCurrent -p UnitFileState -p ActiveState " | ||
| 843 | + "-p SubState -p Description 2>/dev/null"); | ||
| 844 | + used = strlen(cmd); | ||
| 845 | + if (upto > n_names) upto = n_names; | ||
| 846 | + for (k = i; k < upto && used + NAME_SZ + 2 < sizeof cmd; k++) { | ||
| 847 | + cmd[used++] = ' '; | ||
| 848 | + str_copy(cmd + used, sizeof cmd - used, names[k]); | ||
| 849 | + used += strlen(names[k]); | ||
| 850 | + cmd[used] = '\0'; | ||
| 851 | + } | ||
| 852 | + if (capture(cmd, out, sizeof out) > 0) apply_show(out); | ||
| 853 | + } | ||
| 828 | } | 854 | } |
| 829 | } | 855 | } |
| 830 | } | 856 | } |
| index 66d2045..d59ea44 100644 | index 66d2045..d59ea44 100644 | ||
| --- a/tests/run.sh | --- a/tests/run.sh | ||
| +++ b/tests/run.sh | +++ b/tests/run.sh | ||
| @@ -382,6 +382,8 @@ grep -q 'QueryServiceConfigA' src/plugin_services.c && pass "Windows reads the s | @@ -382,6 +382,8 @@ grep -q 'QueryServiceConfigA' src/plugin_services.c && pass "Windows reads the s | ||
| 382 | grep -q '_DARWIN_C_SOURCE' src/plugin_services.c && pass "_DARWIN_C_SOURCE is defined for Apple" || fail "_DARWIN_C_SOURCE missing" | 382 | grep -q '_DARWIN_C_SOURCE' src/plugin_services.c && pass "_DARWIN_C_SOURCE is defined for Apple" || fail "_DARWIN_C_SOURCE missing" |
| 383 | grep -q 'launchctl list' src/plugin_services.c && pass "macOS reads launchctl list" || fail "no launchctl list" | 383 | grep -q 'launchctl list' src/plugin_services.c && pass "macOS reads launchctl list" || fail "no launchctl list" |
| 384 | grep -q 'output=json' src/plugin_services.c && pass "systemd uses --output=json first" || fail "no --output=json" | 384 | grep -q 'output=json' src/plugin_services.c && pass "systemd uses --output=json first" || fail "no --output=json" |
| 385 | +grep -q 'systemctl show --type=service --all' src/plugin_services.c && fail "the empty-set 'show --type= --all' form is back" || pass "show asks for units by name, not the empty --type/--all set" | ||
| 386 | +grep -q 'systemctl show -p Id' src/plugin_services.c && pass "the enrichment pass asks for units by name" || fail "no per-unit show call" | ||
| 385 | grep -q 'not-found' src/plugin_services.c && pass "there is a legacy-table fallback path" || fail "no not-found handling" | 387 | grep -q 'not-found' src/plugin_services.c && pass "there is a legacy-table fallback path" || fail "no not-found handling" |
| 386 | grep -q 'init_system' src/plugin_services.c && pass "the API reports init_system" || fail "no init_system" | 388 | grep -q 'init_system' src/plugin_services.c && pass "the API reports init_system" || fail "no init_system" |
| 387 | grep -q 'control_enabled' src/plugin_services.c && pass "the API reports control_enabled" || fail "no control_enabled" | 389 | grep -q 'control_enabled' src/plugin_services.c && pass "the API reports control_enabled" || fail "no control_enabled" |
| 388 | 390 |