summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/client.c b/src/client.c
index 53b8e53..10cba04 100644
--- a/src/client.c
+++ b/src/client.c
@@ -375,8 +375,25 @@ static void cmd_tail(Client *c, const char *unit_name) {
}
data[dpos] = '\0';
- /* Build response — use proto_send_output with history flag */
- proto_send_output(c->fd, unit_name, data, 1);
+ /* Escape the data for JSON */
+ char escaped[PROTO_MAX_MSG];
+ int j = 0;
+ for (int i = 0; data[i] && j < (int)sizeof(escaped) - 2; i++) {
+ switch (data[i]) {
+ case '"': escaped[j++] = '\\'; escaped[j++] = '"'; break;
+ case '\\': escaped[j++] = '\\'; escaped[j++] = '\\'; break;
+ case '\n': escaped[j++] = '\\'; escaped[j++] = 'n'; break;
+ case '\r': escaped[j++] = '\\'; escaped[j++] = 'r'; break;
+ default: escaped[j++] = data[i]; break;
+ }
+ }
+ escaped[j] = '\0';
+
+ /* Send response envelope like other request/response commands */
+ char buf[PROTO_MAX_MSG];
+ snprintf(buf, sizeof(buf),
+ "{\"type\":\"ok\",\"data\":\"%s\"}", escaped);
+ proto_send(c->fd, buf);
}
/* ── cmd_broadcast ───────────────────────────────────────────────────────── */
@@ -531,7 +548,7 @@ static void cmd_action(Client *c, const char *unit_name,
}
if (pid == 0) {
/* Child: exec the script */
- execl("/bin/bash", "bash", script, NULL);
+ execl("/bin/bash", "bash", "-c", script, NULL);
_exit(127);
}