From 178fee62215a93f9944ac3a762e2376e62f54b46 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Thu, 21 Aug 2014 18:06:18 +0400 Subject: [PATCH] [FIX] preventing sockets inheritance on exec Change-Id: Ie63d09ff5ffcead950d9f26711fdfa19791d330a Signed-off-by: Vyacheslav Cherkashin --- daemon/daemon.c | 4 ++-- daemon/main.c | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/daemon/daemon.c b/daemon/daemon.c index 3d91341..edbb8aa 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -615,7 +615,7 @@ static int targetServerHandler(void) } manager.target[index].socket = - accept(manager.target_server_socket, NULL, NULL); + accept4(manager.target_server_socket, NULL, NULL, SOCK_CLOEXEC); if (manager.target[index].socket >= 0) { /* accept succeed */ @@ -790,7 +790,7 @@ static int hostServerHandler(void) if (hostserverorder > 1) // control and data socket connected already return 1; // ignore - csocket = accept(manager.host_server_socket, NULL, NULL); + csocket = accept4(manager.host_server_socket, NULL, NULL, SOCK_CLOEXEC); if (csocket >= 0) { // accept succeed diff --git a/daemon/main.c b/daemon/main.c index 571765f..42d6aec 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -148,7 +148,9 @@ static int makeTargetServerSocket() // remove existed unix domain socket file unlink(UDS_NAME); - if ((manager.target_server_socket = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) + manager.target_server_socket = socket(AF_UNIX, + SOCK_STREAM | SOCK_CLOEXEC, 0); + if (manager.target_server_socket < 0) { LOGE("Target server socket creation failed\n"); return -1; @@ -194,7 +196,10 @@ static int makeHostServerSocket() if(manager.host_server_socket != -1) return -1; // should be never happened - if ((manager.host_server_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) + manager.host_server_socket = socket(PF_INET, + SOCK_STREAM | SOCK_CLOEXEC, + IPPROTO_TCP); + if (manager.host_server_socket < 0) { LOGE("Host server socket creation failed\n"); return -1; -- 2.7.4