From 771f61449be6d4ff6e03b702f634501687b6bcfb Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Sat, 24 Sep 2022 10:59:08 +0200 Subject: [PATCH] Fix `Unexpected error 9 on netlink descriptor ` The problem is double close of `fd` since the `fdopen` takes ownership of fd passed. --- util/http/http.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/util/http/http.c b/util/http/http.c index d3a8b1c..aee1b02 100644 --- a/util/http/http.c +++ b/util/http/http.c @@ -172,7 +172,7 @@ static void http_process(http_worker_t *worker, FILE *stream) static void http_client(http_worker_t *worker) { worker->client_host = inet_ntoa(worker->client_addr.sin_addr); - LOG_INFO(worker, "Client connected %s.", worker->client_host); + LOG_INFO(worker, "Client connected %s (fd=%d).", worker->client_host, worker->client_fd); struct timeval tv; tv.tv_sec = 3; @@ -186,12 +186,16 @@ static void http_client(http_worker_t *worker) FILE *stream = fdopen(worker->client_fd, "r+"); if (stream) { + worker->client_fd = -1; // ownership taken by stream + http_process(worker, stream); fclose(stream); } - close(worker->client_fd); - worker->client_fd = -1; + if (worker->client_fd >= 0) { + close(worker->client_fd); + worker->client_fd = -1; + } LOG_INFO(worker, "Client disconnected %s.", worker->client_host); worker->client_host = NULL;