summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2011-06-15 17:37:28 +0200
committerThomas Graf <tgraf@suug.ch>2011-06-15 17:37:28 +0200
commitca0fc75580512ccb5931fe1e05092c6c52a4e99c (patch)
tree478d2e234fda395134f8c88d5767cefeeae5380c
parentc881908ac7a485512b74bcd583c5890f2ad2af19 (diff)
downloadlibnl-ca0fc75580512ccb5931fe1e05092c6c52a4e99c.tar.gz
socket: Set SOCK_CLOEXEC if available
Reported by Марк Коренберг <socketpair@gmail.com>
-rw-r--r--lib/nl.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/nl.c b/lib/nl.c
index f5f94e3..fc70374 100644
--- a/lib/nl.c
+++ b/lib/nl.c
@@ -101,14 +101,20 @@
* Creates a netlink socket using the specified protocol, binds the socket
* and issues a connection attempt.
*
+ * @note SOCK_CLOEXEC is set on the socket if available.
+ *
* @return 0 on success or a negative error code.
*/
int nl_connect(struct nl_sock *sk, int protocol)
{
- int err;
+ int err, flags = 0;
socklen_t addrlen;
- sk->s_fd = socket(AF_NETLINK, SOCK_RAW, protocol);
+#ifdef SOCK_CLOEXEC
+ flags |= SOCK_CLOEXEC;
+#endif
+
+ sk->s_fd = socket(AF_NETLINK, SOCK_RAW | flags, protocol);
if (sk->s_fd < 0) {
err = -nl_syserr2nlerr(errno);
goto errout;