From a40a5e897d508091814a3aab19f0fa673ea52fce Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 29 Mar 2019 15:29:49 +0100 Subject: [PATCH] unix: suppress EINTR/EINPROGRESS in uv_fs_close() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close() is interruptible, meaning that a signal delivered when the close() system call is executing, can result in a return value of -1 with errno set to EINTR or EINPROGRESS. A survey of supported Unices suggests the file descriptor is in fact closed and so there is nothing to do except ignore the error. Libuv already handled it correctly for internal file descriptors throug uv__close() and uv__close_nocheckstdio() but uv_fs_close() did not until now. PR-URL: https://github.com/libuv/libuv/pull/2236 Reviewed-By: Colin Ihrig Reviewed-By: Santiago Gimeno Reviewed-By: Jameson Nash Reviewed-By: Saúl Ibarra Corretgé --- src/unix/fs.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/unix/fs.c b/src/unix/fs.c index da5d603c..c6d2259a 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -142,6 +142,18 @@ extern char *mkdtemp(char *template); /* See issue #740 on AIX < 7 */ while (0) +static int uv__fs_close(int fd) { + int rc; + + rc = close(fd); + if (rc == -1) + if (errno == EINTR || errno == EINPROGRESS) + rc = 0; /* The close is in progress, not an error. */ + + return rc; +} + + static ssize_t uv__fs_fsync(uv_fs_t* req) { #if defined(__APPLE__) /* Apple's fdatasync and fsync explicitly do NOT flush the drive write cache @@ -1289,7 +1301,7 @@ static void uv__fs_work(struct uv__work* w) { X(ACCESS, access(req->path, req->flags)); X(CHMOD, chmod(req->path, req->mode)); X(CHOWN, chown(req->path, req->uid, req->gid)); - X(CLOSE, close(req->file)); + X(CLOSE, uv__fs_close(req->file)); X(COPYFILE, uv__fs_copyfile(req)); X(FCHMOD, fchmod(req->file, req->mode)); X(FCHOWN, fchown(req->file, req->uid, req->gid));