summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorauric <auric@japegames.com>2026-02-22 19:13:06 -0600
committerauric <auric@japegames.com>2026-02-22 19:13:06 -0600
commit23527346905a2728c418170a155d0c24b10f5b25 (patch)
tree5edac5323122cf42b9a1ba5de83e58143b01fe4e /src/main.c
parentf0baf8f2f3778d21692d377d32bd4e372cef2aae (diff)
Add log_filter: pluggable per-unit output filter subprocess
Each unit can specify log_filter: <path> pointing to any executable that reads stdin and writes filtered output to stdout. The daemon spawns it once at startup (and on SIGHUP), pipes raw log data through it before ring-buffering and broadcasting to attached clients. filter.c handles spawn (fork/exec with pipes), per-chunk apply (write + poll with 250ms timeout, pass-through on silence/timeout), and stop (SIGTERM + fd cleanup). Filters are stopped and restarted cleanly on SIGHUP alongside log_tail. Bundled filters in filters/: source.py — TF2, GMod: strips server_cvar/stuck/path_goal spam, strips the L MM/DD/YYYY - HH:MM:SS: prefix minecraft.py — vanilla/Paper/Spigot: strips keepAlive, autosave, internal class logs, strips [HH:MM:SS] [thread] prefix terraria.py — vanilla/tModLoader: strips blank lines and mod loading noise during startup Any executable reading stdin/writing stdout works as a custom filter. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index 901ce74..af86375 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4,6 +4,7 @@
#include "client.h"
#include "log.h"
#include "log_tail.h"
+#include "filter.h"
#include <stdio.h>
#include <stdlib.h>
@@ -60,9 +61,12 @@ static void handle_signal(void) {
case SIGHUP:
log_info("SIGHUP received — reloading units");
log_tail_cleanup();
+ filter_stop_all();
/* Reload unit descriptors. Existing runtime state is preserved. */
g.unit_count = 0;
unit_load_all();
+ for (int i = 0; i < g.unit_count; i++)
+ filter_start(&g.units[i]);
log_tail_init();
break;
}
@@ -96,7 +100,10 @@ static void handle_process_output(int fd) {
}
buf[n] = '\0';
- ring_push(u->output, buf, n);
+ int nf = (int)n;
+ filter_apply(u, buf, sizeof(buf), &nf);
+ if (nf <= 0) return;
+ ring_push(u->output, buf, nf);
client_broadcast_output(u->name, buf, 0);
}
@@ -214,6 +221,9 @@ int main(int argc, char *argv[]) {
return 1;
}
+ for (int i = 0; i < g.unit_count; i++)
+ filter_start(&g.units[i]);
+
log_tail_init();
/* Set up listening socket */
@@ -235,6 +245,7 @@ int main(int argc, char *argv[]) {
log_info("Shutting down");
log_tail_cleanup();
+ filter_stop_all();
daemon_cleanup();
log_close();
return 0;