From 14a25a4ac26ef30a87cdc15e09507b47b9eaadb2 Mon Sep 17 00:00:00 2001 From: lotherk Date: Sun, 15 Nov 2026 00:06:43 +0000 Subject: [PATCH] McdeSys: the bar's status reads end after 2 s (t0080) A hung pactl made mcde_sys_volume_get wait 40 s (pactl info, then get-sink-volume, then get-sink-mute; measured with a fake pactl that sleeps 20 s in a private mount namespace). The reads the bar repeats to show a state -- volume (pactl, mixerctl, amixer), Bluetooth (bluetoothctl, btconfig), the Wi-Fi network (iw) -- now use mcde_sys_capture_limited with MCDE_SYS_STATUS_SECONDS (2 s, private.h). Pactl() keeps its answer: a "yes" until a read fails, a "no" for 30 s, so a stopped server costs one 2 s wait, then the mixer answers. Measured after: pactl hangs: 2.0 s, then 0.0 s (mixer); amixer hangs: 2.0 s a call, rc=-6; bluetoothctl hangs: 2.0 s, present=1 on=0; no shim: 0.0 s. make mcde-linux check: 4 of 4 tests pass. Wi-Fi scan and join, network configuration, disks and updates keep the unlimited call: they do real work. AGENTS.md says so. Co-Authored-By: Claude Sonnet 5.5 --- AGENTS.md | 6 +++++- lib/McdeSys/linux.c | 9 ++++++--- lib/McdeSys/netbsd.c | 9 ++++++--- lib/McdeSys/private.h | 7 +++++++ lib/McdeSys/sound.c | 40 +++++++++++++++++++++++++++++++++++----- 5 files changed, 59 insertions(+), 12 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 55aeb43d..62177d02 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -25,7 +25,11 @@ narratives and test notes, is `docs/reference/mcde-agents-history-2026-11-13.txt `ifconfig`, `wpa_supplicant`, edits `/etc/rc.conf` or calls `systemctl` itself, and never has an `#ifdef __NetBSD__`. Each system has one backend (`lib/McdeSys/netbsd.c`, `linux.c`, plus `disk_*.c`); `common.c` is POSIX. - A backend uses the system's own tools the documented way. + A backend uses the system's own tools the documented way. A call that + a program repeats to show a state (the bar: volume, Bluetooth, Wi-Fi) asks + its tool through `mcde_sys_capture_limited` with `MCDE_SYS_STATUS_SECONDS` + (`private.h`), never unbounded: a stopped sound server froze the bar for + 40 s a read (measured, tasksd t0080; 2 s since). 4. **Installed with pkgsrc, in conflict with CDE**: `pkgsrc/Makefile` has `CONFLICTS+= cde-[0-9]*`. 5. **One look**: the MCDE palette generates the X resources and the GTK/Qt diff --git a/lib/McdeSys/linux.c b/lib/McdeSys/linux.c index 497934a5..74d913c1 100644 --- a/lib/McdeSys/linux.c +++ b/lib/McdeSys/linux.c @@ -129,7 +129,8 @@ mcde_sys_if_kind(const char *name, char *ssid, size_t len) if ((p = mcde_sys_which(iw)) != NULL) { argv[0] = (char *) p; - if (mcde_sys_capture(argv, out, sizeof out) == MCDE_SYS_OK && + if (mcde_sys_capture_limited(argv, out, sizeof out, + MCDE_SYS_STATUS_SECONDS) == MCDE_SYS_OK && (s = strstr(out, "SSID: ")) != NULL) { s += 6; if ((e = strchr(s, '\n')) != NULL) @@ -168,7 +169,8 @@ mcde_sys_mixer_get(int *percent, int *muted) "mixer."); argv[0] = (char *) p; /* "Mono: Playback 40 [63%] [-24.00dB] [on]" */ - if (mcde_sys_capture(argv, out, sizeof out) != MCDE_SYS_OK || + if (mcde_sys_capture_limited(argv, out, sizeof out, + MCDE_SYS_STATUS_SECONDS) != MCDE_SYS_OK || (s = strchr(out, '[')) == NULL) return mcde_sys_fail(MCDE_SYS_EFAIL, "The mixer tells no volume."); *percent = atoi(s + 1); @@ -230,7 +232,8 @@ mcde_sys_bluetooth(McdeSysBluetooth *bt) if (!bt->present || p == NULL) return MCDE_SYS_OK; argv[0] = (char *) p; - if (mcde_sys_capture(argv, out, sizeof out) == MCDE_SYS_OK) + if (mcde_sys_capture_limited(argv, out, sizeof out, + MCDE_SYS_STATUS_SECONDS) == MCDE_SYS_OK) bt->on = strstr(out, "Powered: yes") != NULL; return MCDE_SYS_OK; } diff --git a/lib/McdeSys/netbsd.c b/lib/McdeSys/netbsd.c index acc7bd5c..ff441ee9 100644 --- a/lib/McdeSys/netbsd.c +++ b/lib/McdeSys/netbsd.c @@ -169,11 +169,13 @@ mcde_sys_mixer_get(int *percent, int *muted) char *v[] = { mixerctl, "-n", "outputs.master", NULL }; char *m[] = { mixerctl, "-n", "outputs.master.mute", NULL }; - if (mcde_sys_capture(v, out, sizeof out) != MCDE_SYS_OK) + if (mcde_sys_capture_limited(v, out, sizeof out, + MCDE_SYS_STATUS_SECONDS) != MCDE_SYS_OK) return mcde_sys_fail(MCDE_SYS_ENOTSUP, "The mixer has no " "outputs.master."); *percent = (atoi(out) * 100 + 127) / 255; /* "l,r": the left */ - *muted = mcde_sys_capture(m, out, sizeof out) == MCDE_SYS_OK && + *muted = mcde_sys_capture_limited(m, out, sizeof out, + MCDE_SYS_STATUS_SECONDS) == MCDE_SYS_OK && strncmp(out, "on", 2) == 0; return MCDE_SYS_OK; } @@ -209,7 +211,8 @@ mcde_sys_bluetooth(McdeSysBluetooth *bt) char *argv[] = { btconfig, NULL }; memset(bt, 0, sizeof *bt); - if (mcde_sys_capture(argv, out, sizeof out) != MCDE_SYS_OK || + if (mcde_sys_capture_limited(argv, out, sizeof out, + MCDE_SYS_STATUS_SECONDS) != MCDE_SYS_OK || (colon = strchr(out, ':')) == NULL) return MCDE_SYS_OK; *colon = '\0'; diff --git a/lib/McdeSys/private.h b/lib/McdeSys/private.h index 91816956..94600910 100644 --- a/lib/McdeSys/private.h +++ b/lib/McdeSys/private.h @@ -29,6 +29,13 @@ int mcde_sys_run_input(char *const argv[], const char *input); int mcde_sys_file_value(const char *file, const char *key, char *buf, size_t len); +/* How long a question to a system tool may take when a program asks it again + * and again to show a state (the bar: volume, Bluetooth, Wi-Fi): after this + * many seconds the tool is killed and the read fails. Without it a stopped + * PulseAudio froze the bar (tasksd t0080). Not for tools that do real work + * (disks, updates): those may take minutes. */ +#define MCDE_SYS_STATUS_SECONDS 2 + /* the backend: the processes (mcde_sys_processes checks the arguments) */ int mcde_sys_processes_backend(McdeSysProcess **out, size_t *n); diff --git a/lib/McdeSys/sound.c b/lib/McdeSys/sound.c index 43fe7409..a59a3900 100644 --- a/lib/McdeSys/sound.c +++ b/lib/McdeSys/sound.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -28,7 +29,21 @@ static const char *const pactlPaths[] = { "/usr/bin/pactl", "/usr/pkg/bin/pactl", "/usr/local/bin/pactl", NULL }; -/* pactl, if a server answers it */ +/* pactl, if a server answers it. The answer is kept: asked once, a "yes" + * stays until a read fails (the server went away or hangs), a "no" for 30 s -- + * the bar read the volume every few seconds and ran `pactl info' first each + * time, and a stopped server made that wait for ever (tasksd t0080). The + * question itself is limited to MCDE_SYS_STATUS_SECONDS. */ +static const char *pactlKnown; /* the pactl that answered */ +static time_t pactlNone; /* when nobody did; 0 = not asked */ + +static void +PactlForget(void) +{ + pactlKnown = NULL; + pactlNone = time(NULL); /* no new question for 30 s */ +} + static const char * Pactl(void) { @@ -38,8 +53,19 @@ Pactl(void) if (p == NULL) return NULL; + if (pactlKnown != NULL) + return pactlKnown; + if (pactlNone != 0 && time(NULL) - pactlNone < 30) + return NULL; argv[0] = (char *) p; - return mcde_sys_capture(argv, out, sizeof out) == MCDE_SYS_OK ? p : NULL; + if (mcde_sys_capture_limited(argv, out, sizeof out, + MCDE_SYS_STATUS_SECONDS) == MCDE_SYS_OK) { + pactlKnown = p; + pactlNone = 0; + return p; + } + pactlNone = time(NULL); + return NULL; } int @@ -57,15 +83,19 @@ mcde_sys_volume_get(int *percent, int *muted) NULL }; /* "Volume: front-left: 26214 / 40% / -23.88 dB, ..." */ - if (mcde_sys_capture(v, out, sizeof out) != MCDE_SYS_OK || - (pc = strchr(out, '%')) == NULL) + if (mcde_sys_capture_limited(v, out, sizeof out, + MCDE_SYS_STATUS_SECONDS) != MCDE_SYS_OK || + (pc = strchr(out, '%')) == NULL) { + PactlForget(); /* gone or hung: the mixer, for a while */ return mcde_sys_fail(MCDE_SYS_EFAIL, "The sound server tells no volume."); + } while (pc > out && pc[-1] >= '0' && pc[-1] <= '9') pc--; *percent = atoi(pc); /* "Mute: no" */ - *muted = mcde_sys_capture(m, out, sizeof out) == MCDE_SYS_OK && + *muted = mcde_sys_capture_limited(m, out, sizeof out, + MCDE_SYS_STATUS_SECONDS) == MCDE_SYS_OK && strstr(out, "yes") != NULL; } return MCDE_SYS_OK;