From 91f7a75beef27ef3b6c7b7a810d07880859f061f Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 28 Jun 2025 13:34:46 +0200 Subject: [PATCH] api: ensure socket is non-blocking Also, remember to refactor the client socket handling to prevent blocking PID 1. Signed-off-by: Joachim Wiberg --- src/api.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/api.c b/src/api.c index 69b2f228..02987c17 100644 --- a/src/api.c +++ b/src/api.c @@ -349,6 +349,12 @@ static void api_cb(uev_t *w, void *arg, int events) goto error; } + /* + * TODO: refactor to use accept4() and a new uev handler for the + * client socket instead of risking blocking PID 1 if the client + * is misbehaving. + */ +// sd = accept4(w->fd, NULL, NULL, SOCK_NONBLOCK); sd = accept(w->fd, NULL, NULL); if (sd < 0) { err(1, "Failed serving API request"); @@ -613,7 +619,7 @@ int api_init(uev_ctx_t *ctx) int sd; dbg("Setting up external API socket ..."); - sd = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0); + sd = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); if (-1 == sd) { err(1, "Failed starting external API socket"); return 1;