From 02e7a78628e5373a17b6b19d0c81cc1d12739aa4 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 21 Jan 2020 14:02:33 +0100 Subject: [PATCH] unix: handle uv__open_cloexec return value correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `uv__open_cloexec()` already returns a libuv error code in case of failure, and not `-1` like syscalls do. Fixes: https://github.com/nodejs/help/issues/2099 PR-URL: https://github.com/libuv/libuv/pull/2645 Reviewed-By: Ben Noordhuis Reviewed-By: Saúl Ibarra Corretgé Reviewed-By: Colin Ihrig Reviewed-By: Jameson Nash --- src/unix/linux-core.c | 2 +- src/unix/random-devurandom.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/unix/linux-core.c b/src/unix/linux-core.c index 740e422d..f8d9ff58 100644 --- a/src/unix/linux-core.c +++ b/src/unix/linux-core.c @@ -990,7 +990,7 @@ static uint64_t uv__read_proc_meminfo(const char* what) { rc = 0; fd = uv__open_cloexec("/proc/meminfo", O_RDONLY); - if (fd == -1) + if (fd < 0) return 0; n = read(fd, buf, sizeof(buf) - 1); diff --git a/src/unix/random-devurandom.c b/src/unix/random-devurandom.c index 9aa762e3..05e52a56 100644 --- a/src/unix/random-devurandom.c +++ b/src/unix/random-devurandom.c @@ -37,8 +37,8 @@ int uv__random_readpath(const char* path, void* buf, size_t buflen) { fd = uv__open_cloexec(path, O_RDONLY); - if (fd == -1) - return UV__ERR(errno); + if (fd < 0) + return fd; if (fstat(fd, &s)) { uv__close(fd);