From 9a737ab7a40984cfdfffd014562a220a3736a10f Mon Sep 17 00:00:00 2001 From: Austin Foxley Date: Sat, 17 Oct 2009 14:25:01 -0700 Subject: use *_not_cancel variants to avoid accidental cancellations with nptl Signed-off-by: Austin Foxley --- libc/inet/hostid.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'libc/inet/hostid.c') 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 #include #include +#include #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 -- cgit v1.2.3