summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDean Jansa <djansa@redhat.com>2005-11-03 19:25:58 +0000
committerNathan Straz <nstraz@redhat.com>2008-09-23 09:37:45 -0400
commitb1888390ff441e1e3a6bd106448d6c0ad3a1a58b (patch)
tree8881c828d18bbc6512eb81249de3b7f44fb3e80c
parent8b30b78eb2fa41ef7f6f21dc09e3cee96abf8a89 (diff)
downloadqarsh-b1888390ff441e1e3a6bd106448d6c0ad3a1a58b.zip
qarsh-b1888390ff441e1e3a6bd106448d6c0ad3a1a58b.tar.gz
qarsh-b1888390ff441e1e3a6bd106448d6c0ad3a1a58b.tar.xz
Set close on exec flag on our sockets in connect_to_peer()
-rw-r--r--sockutil.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/sockutil.c b/sockutil.c
index 073685e..a571d64 100644
--- a/sockutil.c
+++ b/sockutil.c
@@ -7,6 +7,7 @@
#include <syslog.h>
#include <stdlib.h>
#include <unistd.h>
+#include <fcntl.h>
#include "qarsh_packet.h"
@@ -73,6 +74,7 @@ connect_to_peer(struct sockaddr_in *peer, int port)
{
struct sockaddr_in in_peer;
int sd;
+ int fdflags;
in_peer.sin_family = AF_INET;
in_peer.sin_port = htons(port);
@@ -80,6 +82,17 @@ connect_to_peer(struct sockaddr_in *peer, int port)
sd = socket(PF_INET, SOCK_STREAM, 0);
if (sd == -1) return -1;
+
+ /* Set close-on-exec for these sds */
+ if ((fdflags = fcntl(sd, F_GETFD, 0)) < 0) {
+ return -1;
+ }
+
+ fdflags |= FD_CLOEXEC;
+ if (fcntl(sd, F_SETFD, fdflags) < 0) {
+ return -1;
+ }
+
if (connect(sd, (struct sockaddr *)&in_peer, sizeof in_peer) == -1) {
return -1;
}