Skip to content

Commit 772173f

Browse files
committed
Use FD_CLOEXEC fcntl for WEB-server socket
free() is not safe in fork()ed child when using threads. Don't close WEB-server socket manually, use FD_CLOEXEC fcntl instead.
1 parent 1b835ba commit 772173f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

libhttpd/api.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ int port;
262262
free(new);
263263
return (NULL);
264264
}
265+
if (fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) {
266+
close(sock);
267+
free(new);
268+
return (NULL);
269+
}
265270
# ifdef SO_REUSEADDR
266271
opt = 1;
267272
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int)) < 0) {

src/gateway.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ main_loop(void)
397397
debug(LOG_ERR, "Could not create web server: %s", strerror(errno));
398398
exit(1);
399399
}
400-
register_fd_cleanup_on_fork(webserver->serverSock);
401400

402401
debug(LOG_DEBUG, "Assigning callbacks to web server");
403402
httpdAddCContent(webserver, "/", "wifidog", 0, NULL, http_callback_wifidog);

0 commit comments

Comments
 (0)