diff options
author | Austin Foxley <austinf@cetoncorp.com> | 2009-10-17 14:25:01 -0700 |
---|---|---|
committer | Austin Foxley <austinf@cetoncorp.com> | 2009-10-17 14:25:01 -0700 |
commit | 9a737ab7a40984cfdfffd014562a220a3736a10f (patch) | |
tree | 51fe4682638ffec59b2bd41d67df82ec60d6b48d /libc/inet | |
parent | cfbc0081078b5a41895a2ad689627bf94eeacb43 (diff) |
use *_not_cancel variants to avoid accidental cancellations with nptl
Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
Diffstat (limited to 'libc/inet')
-rw-r--r-- | libc/inet/hostid.c | 15 | ||||
-rw-r--r-- | libc/inet/if_index.c | 17 |
2 files changed, 17 insertions, 15 deletions
diff --git a/libc/inet/hostid.c b/libc/inet/hostid.c index 99346d7f8..c6d6204ae 100644 --- a/libc/inet/hostid.c +++ b/libc/inet/hostid.c @@ -14,6 +14,7 @@ #include <netdb.h> #include <fcntl.h> #include <unistd.h> +#include <not-cancel.h> #define HOSTID "/etc/hostid" @@ -26,11 +27,11 @@ int sethostid(long int new_id) if (geteuid() || getuid()) return __set_errno(EPERM); - fd = open(HOSTID, O_CREAT|O_WRONLY, 0644); + fd = open_not_cancel(HOSTID, O_CREAT|O_WRONLY, 0644); if (fd < 0) return fd; - ret = write(fd, &new_id, sizeof(new_id)) == sizeof(new_id) ? 0 : -1; - close(fd); + ret = write_not_cancel(fd, &new_id, sizeof(new_id)) == sizeof(new_id) ? 0 : -1; + close_not_cancel_no_status (fd); return ret; } #endif @@ -44,13 +45,13 @@ long int gethostid(void) * It is not an error if we cannot read this file. It is not even an * error if we cannot read all the bytes, we just carry on trying... */ - fd = open(HOSTID, O_RDONLY); - if (fd >= 0 && read(fd, &id, sizeof(id))) + fd = open_not_cancel_2(HOSTID, O_RDONLY); + if (fd >= 0 && read_not_cancel(fd, &id, sizeof(id))) { - close (fd); + close_not_cancel_no_status (fd); return id; } - if (fd >= 0) close (fd); + if (fd >= 0) close_not_cancel_no_status (fd); /* Try some methods of returning a unique 32 bit id. Clearly IP * numbers, if on the internet, will have a unique address. If they diff --git a/libc/inet/if_index.c b/libc/inet/if_index.c index 750a4649e..8efcd2a76 100644 --- a/libc/inet/if_index.c +++ b/libc/inet/if_index.c @@ -32,6 +32,7 @@ #include <sys/socket.h> #include <sys/ioctl.h> #include <libc-internal.h> +#include <not-cancel.h> #include "netlinkaccess.h" @@ -55,13 +56,13 @@ if_nametoindex(const char* ifname) { /* close never fails here, fd is just a unconnected socket. *int saved_errno = errno; */ - close(fd); + close_not_cancel_no_status(fd); /*if (saved_errno == EINVAL) * __set_errno(ENOSYS); */ return 0; } - close(fd); + close_not_cancel_no_status(fd); return ifr.ifr_ifindex; #endif } @@ -112,7 +113,7 @@ if_nameindex (void) if (ioctl (fd, SIOCGIFCONF, &ifc) < 0) { - close (fd); + close_not_cancel_no_status (fd); return NULL; } } @@ -123,7 +124,7 @@ if_nameindex (void) idx = malloc ((nifs + 1) * sizeof (struct if_nameindex)); if (idx == NULL) { - close(fd); + close_not_cancel_no_status (fd); __set_errno(ENOBUFS); return NULL; } @@ -141,7 +142,7 @@ if_nameindex (void) for (j = 0; j < i; ++j) free (idx[j].if_name); free(idx); - close(fd); + close_not_cancel_no_status (fd); if (saved_errno == EINVAL) saved_errno = ENOSYS; else if (saved_errno == ENOMEM) @@ -155,7 +156,7 @@ if_nameindex (void) idx[i].if_index = 0; idx[i].if_name = NULL; - close(fd); + close_not_cancel_no_status (fd); return idx; #endif } @@ -298,14 +299,14 @@ if_indextoname (unsigned int ifindex, char *ifname) if (ioctl (fd, SIOCGIFNAME, &ifr) < 0) { int serrno = errno; - close (fd); + close_not_cancel_no_status (fd); if (serrno == ENODEV) /* POSIX requires ENXIO. */ serrno = ENXIO; __set_errno (serrno); return NULL; } - close (fd); + close_not_cancel_no_status (fd); return strncpy (ifname, ifr.ifr_name, IFNAMSIZ); # else |