]> granicus.if.org Git - libnl/commitdiff
socket: Set SOCK_CLOEXEC if available
authorThomas Graf <tgraf@suug.ch>
Wed, 15 Jun 2011 15:37:28 +0000 (17:37 +0200)
committerThomas Graf <tgraf@suug.ch>
Wed, 15 Jun 2011 15:37:28 +0000 (17:37 +0200)
Reported by Марк Коренберг <socketpair@gmail.com>

lib/nl.c

index f5f94e30e5e5a9dcee5d3049a3e032d345f96d7a..fc7037464b8a82b71b6a1dd74e2eefd5b353eabf 100644 (file)
--- a/lib/nl.c
+++ b/lib/nl.c
  * 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;