From aa73b0d955b603f623a191cc745b0173f230f02e Mon Sep 17 00:00:00 2001 From: auric Date: Sat, 21 Feb 2026 14:20:29 -0600 Subject: Use active probing for unit state in list command Previously, `umbrella-cli list` reported each unit's cached internal state, while `umbrella-cli status ` used probe_rcon_state() to actively verify RCON units via systemd and a live network probe. This caused the list to show stale or inconsistent state compared to status. Move probe_rcon_state() before cmd_list() and use it there so both commands share the same state determination logic. Co-Authored-By: Claude Sonnet 4.6 --- src/client.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src/client.c') diff --git a/src/client.c b/src/client.c index 034ea74..e1816f2 100644 --- a/src/client.c +++ b/src/client.c @@ -134,28 +134,6 @@ void client_broadcast_output(const char *unit_name, /* ── Command handlers ────────────────────────────────────────────────────── */ -static void cmd_list(Client *c) { - /* Build a JSON array of unit summaries */ - char buf[PROTO_MAX_MSG]; - int pos = 0; - - pos += snprintf(buf + pos, sizeof(buf) - pos, - "{\"type\":\"list\",\"units\":["); - - for (int i = 0; i < g.unit_count; i++) { - Unit *u = &g.units[i]; - if (i > 0) - pos += snprintf(buf + pos, sizeof(buf) - pos, ","); - pos += snprintf(buf + pos, sizeof(buf) - pos, - "{\"name\":\"%s\",\"display\":\"%s\"," - "\"state\":\"%s\"}", - u->name, u->display, unit_state_str(u->state)); - } - - snprintf(buf + pos, sizeof(buf) - pos, "]}"); - proto_send(c->fd, buf); -} - static const char *probe_rcon_state(Unit *u) { if (u->console.type != CONSOLE_RCON) return unit_state_str(u->state); @@ -177,6 +155,28 @@ static const char *probe_rcon_state(Unit *u) { return (r == 0) ? "running" : "unreachable"; } +static void cmd_list(Client *c) { + /* Build a JSON array of unit summaries, using active probing for state */ + char buf[PROTO_MAX_MSG]; + int pos = 0; + + pos += snprintf(buf + pos, sizeof(buf) - pos, + "{\"type\":\"list\",\"units\":["); + + for (int i = 0; i < g.unit_count; i++) { + Unit *u = &g.units[i]; + if (i > 0) + pos += snprintf(buf + pos, sizeof(buf) - pos, ","); + pos += snprintf(buf + pos, sizeof(buf) - pos, + "{\"name\":\"%s\",\"display\":\"%s\"," + "\"state\":\"%s\"}", + u->name, u->display, probe_rcon_state(u)); + } + + snprintf(buf + pos, sizeof(buf) - pos, "]}"); + proto_send(c->fd, buf); +} + static void cmd_status(Client *c, const char *unit_name) { Unit *u = unit_find(unit_name); if (!u) { proto_send_error(c->fd, "unit not found"); return; } -- cgit v1.2.3