diff mbox series

[2/6] network_thread: set listener/ctrl children as CLOEXEC

Message ID 20220527044700.3666830-3-dominique.martinet@atmark-techno.com
State Accepted
Headers show
Series Avoid leaking fd to child processes: use CLOEXEC | expand

Commit Message

Dominique MARTINET May 27, 2022, 4:46 a.m. UTC
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
 core/network_thread.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Stefano Babic June 5, 2022, 2:13 p.m. UTC | #1
On 27.05.22 06:46, Dominique Martinet wrote:
> Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
> ---
>   core/network_thread.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/core/network_thread.c b/core/network_thread.c
> index 88042f1238cb..0e031885d208 100644
> --- a/core/network_thread.c
> +++ b/core/network_thread.c
> @@ -261,6 +261,9 @@ int listener_create(const char *path, int type)
>   			WARN("chmod cannot be set on socket, error %s", strerror(errno));
>   	}
>   
> +	if (fcntl(listenfd, F_SETFD, FD_CLOEXEC) < 0)
> +		WARN("Could not set %d as cloexec: %s", listenfd, strerror(errno));
> +
>   	if (type == SOCK_STREAM)
>   		if (listen(listenfd, LISTENQ) < 0) {
>   			close(listenfd);
> @@ -483,6 +486,9 @@ void *network_thread (void *data)
>   				continue;
>   			}
>   		}
> +		if (fcntl(ctrlconnfd, F_SETFD, FD_CLOEXEC) < 0)
> +			WARN("Could not set %d as cloexec: %s", ctrlconnfd, strerror(errno));
> +
>   		nread = read(ctrlconnfd, (void *)&msg, sizeof(msg));
>   
>   		if (nread != sizeof(msg)) {

Reviewed-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/core/network_thread.c b/core/network_thread.c
index 88042f1238cb..0e031885d208 100644
--- a/core/network_thread.c
+++ b/core/network_thread.c
@@ -261,6 +261,9 @@  int listener_create(const char *path, int type)
 			WARN("chmod cannot be set on socket, error %s", strerror(errno));
 	}
 
+	if (fcntl(listenfd, F_SETFD, FD_CLOEXEC) < 0)
+		WARN("Could not set %d as cloexec: %s", listenfd, strerror(errno));
+
 	if (type == SOCK_STREAM)
 		if (listen(listenfd, LISTENQ) < 0) {
 			close(listenfd);
@@ -483,6 +486,9 @@  void *network_thread (void *data)
 				continue;
 			}
 		}
+		if (fcntl(ctrlconnfd, F_SETFD, FD_CLOEXEC) < 0)
+			WARN("Could not set %d as cloexec: %s", ctrlconnfd, strerror(errno));
+
 		nread = read(ctrlconnfd, (void *)&msg, sizeof(msg));
 
 		if (nread != sizeof(msg)) {