summaryrefslogtreecommitdiff
path: root/src/client.c
diff options
context:
space:
mode:
authorauric <auric@japegames.com>2026-02-21 14:20:29 -0600
committerauric <auric@japegames.com>2026-02-21 14:20:29 -0600
commitaa73b0d955b603f623a191cc745b0173f230f02e (patch)
tree9c06126117d50a2c6b3e67b1ff4e978f276b645a /src/client.c
parentaf012ffe7594350021741c62bd1205b65dfec07f (diff)
Use active probing for unit state in list command
Previously, `umbrella-cli list` reported each unit's cached internal state, while `umbrella-cli status <unit>` 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 <noreply@anthropic.com>
Diffstat (limited to 'src/client.c')
-rw-r--r--src/client.c44
1 files changed, 22 insertions, 22 deletions
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; }