mirror of
https://github.com/troglobit/finit.git
synced 2026-11-07 16:01:08 +00:00
api: ensure socket is non-blocking
Also, remember to refactor the client socket handling to prevent blocking PID 1. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 file changed
+7
-1
@@ -349,6 +349,12 @@ static void api_cb(uev_t *w, void *arg, int events)
|
|||||||
goto error;
|
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);
|
sd = accept(w->fd, NULL, NULL);
|
||||||
if (sd < 0) {
|
if (sd < 0) {
|
||||||
err(1, "Failed serving API request");
|
err(1, "Failed serving API request");
|
||||||
@@ -613,7 +619,7 @@ int api_init(uev_ctx_t *ctx)
|
|||||||
int sd;
|
int sd;
|
||||||
|
|
||||||
dbg("Setting up external API socket ...");
|
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) {
|
if (-1 == sd) {
|
||||||
err(1, "Failed starting external API socket");
|
err(1, "Failed starting external API socket");
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in new issue
Block a user