From 0716b10ac8dc167f96969c964974d4094035fed0 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 9 Jul 2013 00:40:17 -0400 Subject: [PATCH] fix missing SOCK_CLOEXEC in various functions that use sockets internally --- src/network/getifaddrs.c | 2 +- src/network/if_indextoname.c | 2 +- src/network/if_nameindex.c | 2 +- src/network/if_nametoindex.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/network/getifaddrs.c b/src/network/getifaddrs.c index a4c31782..a14ac1b3 100644 --- a/src/network/getifaddrs.c +++ b/src/network/getifaddrs.c @@ -127,7 +127,7 @@ int getifaddrs(struct ifaddrs **ifap) } if_freenameindex(ii); - int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); + int sock = socket(PF_INET, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_IP); if(sock == -1) goto err2; struct ifreq reqs[32]; /* arbitrary chosen boundary */ struct ifconf conf = {.ifc_len = sizeof reqs, .ifc_req = reqs}; diff --git a/src/network/if_indextoname.c b/src/network/if_indextoname.c index f18f17a6..6ee7f13c 100644 --- a/src/network/if_indextoname.c +++ b/src/network/if_indextoname.c @@ -10,7 +10,7 @@ char *if_indextoname(unsigned index, char *name) struct ifreq ifr; int fd, r; - if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) return 0; + if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0; ifr.ifr_ifindex = index; r = ioctl(fd, SIOCGIFNAME, &ifr); __syscall(SYS_close, fd); diff --git a/src/network/if_nameindex.c b/src/network/if_nameindex.c index cdb956cb..ad0a7662 100644 --- a/src/network/if_nameindex.c +++ b/src/network/if_nameindex.c @@ -47,7 +47,7 @@ struct if_nameindex *if_nameindex() { size_t n; void *p = 0; - int s = socket(AF_UNIX, SOCK_DGRAM, 0); + int s = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); if (s>=0) { for (n=0; (p=do_nameindex(s, n)) == (void *)-1; n++); __syscall(SYS_close, s); diff --git a/src/network/if_nametoindex.c b/src/network/if_nametoindex.c index 419931f9..fb4a1474 100644 --- a/src/network/if_nametoindex.c +++ b/src/network/if_nametoindex.c @@ -10,7 +10,7 @@ unsigned if_nametoindex(const char *name) struct ifreq ifr; int fd, r; - if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) return -1; + if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return -1; strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); r = ioctl(fd, SIOCGIFINDEX, &ifr); __syscall(SYS_close, fd); -- 2.25.1