| index 0c8be54..73749cd 100644 | ||
| --- a/src/plugin_services.c | ||
| +++ b/src/plugin_services.c | ||
| @@ -877,12 +877,26 @@ static void collect_launchd(void) | ||
| 877 | 877 | str_trim(label); |
| 878 | 878 | if (!label[0]) continue; |
| 879 | 879 | if (strcmp(pid_s, "-") != 0) pid = atoi(pid_s); |
| 880 | - /* A job with no pid whose last exit status is non-zero failed. */ | |
| 881 | - if (pid <= 0 && strcmp(st_s, "0") != 0) | |
| 880 | + /* launchd reports a job with no pid as "<last status>". A positive | |
| 881 | + * value is a real exit code and means the job failed. A NEGATIVE | |
| 882 | + * value is a signal: -9 (SIGKILL) and -15 (SIGTERM) are how launchd | |
| 883 | + * reaps idle on-demand agents on memory pressure, so they are | |
| 884 | + * "inactive", not failures - reporting 73 of those as failed would | |
| 885 | + * make the board useless on a real Mac. Any other signal is a | |
| 886 | + * crash and stays failed. */ | |
| 887 | + if (pid > 0) { | |
| 888 | + svc_add(label, "launchd job", "running", "running", pid); | |
| 889 | + } else if (st_s[0] == '-') { | |
| 890 | + int sig = atoi(st_s + 1); | |
| 891 | + if (sig == 9 || sig == 15) | |
| 892 | + svc_add(label, "launchd job", "inactive", "exited", 0); | |
| 893 | + else | |
| 894 | + svc_add(label, "launchd job", "failed", "failed", 0); | |
| 895 | + } else if (st_s[0] && strcmp(st_s, "0") != 0) { | |
| 882 | 896 | svc_add(label, "launchd job", "failed", "failed", 0); |
| 883 | - else | |
| 884 | - svc_add(label, "launchd job", pid > 0 ? "running" : "inactive", | |
| 885 | - pid > 0 ? "running" : "exited", pid); | |
| 897 | + } else { | |
| 898 | + svc_add(label, "launchd job", "inactive", "exited", 0); | |
| 899 | + } | |
| 886 | 900 | { |
| 887 | 901 | svc_t *s = &g_svc[g_count - 1]; |
| 888 | 902 | str_copy(s->enabled, sizeof s->enabled, "launchd"); |
| index 98de868..66d2045 100644 | ||
| --- a/tests/run.sh | ||
| +++ b/tests/run.sh | ||
| @@ -249,12 +249,24 @@ PID Status Label | ||
| 249 | 249 | - 0 com.apple.periodic-daily |
| 250 | 250 | 4242 0 com.example.agent |
| 251 | 251 | - 78 com.example.broken |
| 252 | +- -9 com.apple.idleagent | |
| 253 | +- -15 com.apple.termagent | |
| 254 | +- -11 com.example.segv | |
| 252 | 255 | LAUNCH |
| 253 | 256 | |
| 254 | 257 | LL=$(body "$(run 'action=list' SERVICES_MOCK_LAUNCHCTL="$WORK/launchctl.txt" SERVICES_FORCE_INIT=launchd)") |
| 255 | 258 | json_ok "launchctl output parses" "$LL" "d['ok'] is True" |
| 256 | 259 | json_ok "launchd reports init_system=launchd when mocked through the platform path" "$LL" "d['init_system'] in ('launchd','none','systemd')" |
| 257 | 260 | json_ok "the header line is not a service" "$LL" "all('Label' not in s['name'] for s in d['services'])" |
| 261 | +json_ok "launchctl output parses every job" "$LL" "d['count']==7" | |
| 262 | +json_ok "a launchd job with a pid is running" "$LL" "[s for s in d['services'] if s['name']=='com.apple.securityd'][0]['active']=='running'" | |
| 263 | +json_ok "a launchd job with status 0 and no pid is inactive" "$LL" "[s for s in d['services'] if s['name']=='com.apple.periodic-daily'][0]['active']=='inactive'" | |
| 264 | +json_ok "a positive exit status is a failure" "$LL" "[s for s in d['services'] if s['name']=='com.example.broken'][0]['failed'] is True" | |
| 265 | +json_ok "the failure keeps its exit code in since" "$LL" "'78' in [s for s in d['services'] if s['name']=='com.example.broken'][0]['since']" | |
| 266 | +json_ok "SIGKILL (reaped idle agent) is inactive, not failed" "$LL" "[s for s in d['services'] if s['name']=='com.apple.idleagent'][0]['active']=='inactive'" | |
| 267 | +json_ok "SIGTERM (reaped idle agent) is inactive, not failed" "$LL" "[s for s in d['services'] if s['name']=='com.apple.termagent'][0]['active']=='inactive'" | |
| 268 | +json_ok "a real crash signal stays failed" "$LL" "[s for s in d['services'] if s['name']=='com.example.segv'][0]['failed'] is True" | |
| 269 | +json_ok "the launchd summary counts one real failure" "$LL" "d['summary']['failed']==2" | |
| 258 | 270 | |
| 259 | 271 | # ---------------------------------------------------------------- show |
| 260 | 272 | section "mode 2e - action=show" |
| 261 | 273 |
| index 0c8be54..73749cd 100644 | index 0c8be54..73749cd 100644 | ||
| --- a/src/plugin_services.c | --- a/src/plugin_services.c | ||
| +++ b/src/plugin_services.c | +++ b/src/plugin_services.c | ||
| @@ -877,12 +877,26 @@ static void collect_launchd(void) | @@ -877,12 +877,26 @@ static void collect_launchd(void) | ||
| 877 | str_trim(label); | 877 | str_trim(label); |
| 878 | if (!label[0]) continue; | 878 | if (!label[0]) continue; |
| 879 | if (strcmp(pid_s, "-") != 0) pid = atoi(pid_s); | 879 | if (strcmp(pid_s, "-") != 0) pid = atoi(pid_s); |
| 880 | - /* A job with no pid whose last exit status is non-zero failed. */ | 880 | + /* launchd reports a job with no pid as "<last status>". A positive |
| 881 | - if (pid <= 0 && strcmp(st_s, "0") != 0) | 881 | + * value is a real exit code and means the job failed. A NEGATIVE |
| 882 | + * value is a signal: -9 (SIGKILL) and -15 (SIGTERM) are how launchd | ||
| 883 | + * reaps idle on-demand agents on memory pressure, so they are | ||
| 884 | + * "inactive", not failures - reporting 73 of those as failed would | ||
| 885 | + * make the board useless on a real Mac. Any other signal is a | ||
| 886 | + * crash and stays failed. */ | ||
| 887 | + if (pid > 0) { | ||
| 888 | + svc_add(label, "launchd job", "running", "running", pid); | ||
| 889 | + } else if (st_s[0] == '-') { | ||
| 890 | + int sig = atoi(st_s + 1); | ||
| 891 | + if (sig == 9 || sig == 15) | ||
| 892 | + svc_add(label, "launchd job", "inactive", "exited", 0); | ||
| 893 | + else | ||
| 894 | + svc_add(label, "launchd job", "failed", "failed", 0); | ||
| 895 | + } else if (st_s[0] && strcmp(st_s, "0") != 0) { | ||
| 882 | svc_add(label, "launchd job", "failed", "failed", 0); | 896 | svc_add(label, "launchd job", "failed", "failed", 0); |
| 883 | - else | 897 | + } else { |
| 884 | - svc_add(label, "launchd job", pid > 0 ? "running" : "inactive", | 898 | + svc_add(label, "launchd job", "inactive", "exited", 0); |
| 885 | - pid > 0 ? "running" : "exited", pid); | 899 | + } |
| 886 | { | 900 | { |
| 887 | svc_t *s = &g_svc[g_count - 1]; | 901 | svc_t *s = &g_svc[g_count - 1]; |
| 888 | str_copy(s->enabled, sizeof s->enabled, "launchd"); | 902 | str_copy(s->enabled, sizeof s->enabled, "launchd"); |
| index 98de868..66d2045 100644 | index 98de868..66d2045 100644 | ||
| --- a/tests/run.sh | --- a/tests/run.sh | ||
| +++ b/tests/run.sh | +++ b/tests/run.sh | ||
| @@ -249,12 +249,24 @@ PID Status Label | @@ -249,12 +249,24 @@ PID Status Label | ||
| 249 | - 0 com.apple.periodic-daily | 249 | - 0 com.apple.periodic-daily |
| 250 | 4242 0 com.example.agent | 250 | 4242 0 com.example.agent |
| 251 | - 78 com.example.broken | 251 | - 78 com.example.broken |
| 252 | +- -9 com.apple.idleagent | ||
| 253 | +- -15 com.apple.termagent | ||
| 254 | +- -11 com.example.segv | ||
| 252 | LAUNCH | 255 | LAUNCH |
| 253 | 256 | ||
| 254 | LL=$(body "$(run 'action=list' SERVICES_MOCK_LAUNCHCTL="$WORK/launchctl.txt" SERVICES_FORCE_INIT=launchd)") | 257 | LL=$(body "$(run 'action=list' SERVICES_MOCK_LAUNCHCTL="$WORK/launchctl.txt" SERVICES_FORCE_INIT=launchd)") |
| 255 | json_ok "launchctl output parses" "$LL" "d['ok'] is True" | 258 | json_ok "launchctl output parses" "$LL" "d['ok'] is True" |
| 256 | json_ok "launchd reports init_system=launchd when mocked through the platform path" "$LL" "d['init_system'] in ('launchd','none','systemd')" | 259 | json_ok "launchd reports init_system=launchd when mocked through the platform path" "$LL" "d['init_system'] in ('launchd','none','systemd')" |
| 257 | json_ok "the header line is not a service" "$LL" "all('Label' not in s['name'] for s in d['services'])" | 260 | json_ok "the header line is not a service" "$LL" "all('Label' not in s['name'] for s in d['services'])" |
| 261 | +json_ok "launchctl output parses every job" "$LL" "d['count']==7" | ||
| 262 | +json_ok "a launchd job with a pid is running" "$LL" "[s for s in d['services'] if s['name']=='com.apple.securityd'][0]['active']=='running'" | ||
| 263 | +json_ok "a launchd job with status 0 and no pid is inactive" "$LL" "[s for s in d['services'] if s['name']=='com.apple.periodic-daily'][0]['active']=='inactive'" | ||
| 264 | +json_ok "a positive exit status is a failure" "$LL" "[s for s in d['services'] if s['name']=='com.example.broken'][0]['failed'] is True" | ||
| 265 | +json_ok "the failure keeps its exit code in since" "$LL" "'78' in [s for s in d['services'] if s['name']=='com.example.broken'][0]['since']" | ||
| 266 | +json_ok "SIGKILL (reaped idle agent) is inactive, not failed" "$LL" "[s for s in d['services'] if s['name']=='com.apple.idleagent'][0]['active']=='inactive'" | ||
| 267 | +json_ok "SIGTERM (reaped idle agent) is inactive, not failed" "$LL" "[s for s in d['services'] if s['name']=='com.apple.termagent'][0]['active']=='inactive'" | ||
| 268 | +json_ok "a real crash signal stays failed" "$LL" "[s for s in d['services'] if s['name']=='com.example.segv'][0]['failed'] is True" | ||
| 269 | +json_ok "the launchd summary counts one real failure" "$LL" "d['summary']['failed']==2" | ||
| 258 | 270 | ||
| 259 | # ---------------------------------------------------------------- show | 271 | # ---------------------------------------------------------------- show |
| 260 | section "mode 2e - action=show" | 272 | section "mode 2e - action=show" |
| 261 | 273 |