diff mbox series

[1/2] prepare_ipc: set client fd as CLOEXEC

Message ID 20230915091608.3207005-1-dominique.martinet@atmark-techno.com
State Accepted
Delegated to: Stefano Babic
Headers show
Series [1/2] prepare_ipc: set client fd as CLOEXEC | expand

Commit Message

Dominique Martinet Sept. 15, 2023, 9:16 a.m. UTC
This fd was seen leaking in scripts. Use CLOEXEC to avoid
interferences from buggy scripts.

Note SOCK_CLOEXEC is not POSIX, but BSDs seem to define it:
https://man.openbsd.org/socket.2
https://man.freebsd.org/cgi/man.cgi?query=socket&sektion=2

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
Cc: Christian Storm <christian.storm@siemens.com>
---
Added Christian in Ccs for BSD sanity check, but I think it's OK.

If you want to stick to posix, happy to resend this as a patch that does
fcntl on the socket after its creation to set CLOEXEC instead.

 ipc/network_ipc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/ipc/network_ipc.c b/ipc/network_ipc.c
index 6c8c03ae4617..63552c6df29a 100644
--- a/ipc/network_ipc.c
+++ b/ipc/network_ipc.c
@@ -43,7 +43,7 @@  static int prepare_ipc(void) {
 	int connfd;
 	struct sockaddr_un servaddr;
 
-	connfd = socket(AF_LOCAL, SOCK_STREAM, 0);
+	connfd = socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
 	if (connfd < 0)
 		return -1;