From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1792) id B045F3850222; Wed, 14 Sep 2022 17:01:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B045F3850222 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663174871; bh=YwlE/Ae98/UjxWVTnLfLLbaxT5krNUlQ7pTJE2eplZ4=; h=From:To:Subject:Date:From; b=Zz2RlxM6FIJSpJ+ccfK/A7324DkOT/CJijgDti6nMjiNWJoK/bFqbzhFDnFvitmxh /IzX1H9lr8Bj/K6W92toi7PX32XebVk2JuJuTjzuEGv6r9hCsJRZReyUpTGETH8Xbj o8JXtyku8xcpSHjN0zqvSwXejravHoCuOdCC75f4= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Samuel Thibault To: glibc-cvs@sourceware.org Subject: [glibc] hurd: Fix readlink() hanging on fifo X-Act-Checkin: glibc X-Git-Author: Samuel Thibault X-Git-Refname: refs/heads/master X-Git-Oldrev: 05967faf0e3df6aad07f0b05e138e86f82363deb X-Git-Newrev: 9e5c991106cb04b489272de0ef6a7a6bcef50477 Message-Id: <20220914170111.B045F3850222@sourceware.org> Date: Wed, 14 Sep 2022 17:01:11 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9e5c991106cb04b489272de0ef6a7a6bcef50477 commit 9e5c991106cb04b489272de0ef6a7a6bcef50477 Author: Samuel Thibault Date: Wed Sep 14 18:52:52 2022 +0200 hurd: Fix readlink() hanging on fifo readlink() opens the target with O_READ to be able to read the symlink content. When the target is actually a fifo, that would hang waiting for a writer (caught in the coreutils testsuite). We thus have to first lookup the target without O_READ to perform io_stat and lookout for fifos, and only after checking the symlink type, we can re-lookup with O_READ. Diff: --- sysdeps/mach/hurd/readlink.c | 5 ++++- sysdeps/mach/hurd/readlinkat.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sysdeps/mach/hurd/readlink.c b/sysdeps/mach/hurd/readlink.c index 770462714f..2d75ef7725 100644 --- a/sysdeps/mach/hurd/readlink.c +++ b/sysdeps/mach/hurd/readlink.c @@ -31,7 +31,7 @@ __readlink (const char *file_name, char *buf, size_t len) file_t file; struct stat64 st; - file = __file_name_lookup (file_name, O_READ | O_NOLINK, 0); + file = __file_name_lookup (file_name, O_NOLINK, 0); if (file == MACH_PORT_NULL) return -1; @@ -41,6 +41,9 @@ __readlink (const char *file_name, char *buf, size_t len) { char *rbuf = buf; + __mach_port_deallocate (__mach_task_self (), file); + file = __file_name_lookup (file_name, O_READ | O_NOLINK, 0); + err = __io_read (file, &rbuf, &len, 0, len); if (!err && rbuf != buf) { diff --git a/sysdeps/mach/hurd/readlinkat.c b/sysdeps/mach/hurd/readlinkat.c index 059aad9f58..113b92b732 100644 --- a/sysdeps/mach/hurd/readlinkat.c +++ b/sysdeps/mach/hurd/readlinkat.c @@ -32,7 +32,7 @@ readlinkat (int fd, const char *file_name, char *buf, size_t len) file_t file; struct stat64 st; - file = __file_name_lookup_at (fd, 0, file_name, O_READ | O_NOLINK, 0); + file = __file_name_lookup_at (fd, 0, file_name, O_NOLINK, 0); if (file == MACH_PORT_NULL) return -1; @@ -42,6 +42,9 @@ readlinkat (int fd, const char *file_name, char *buf, size_t len) { char *rbuf = buf; + __mach_port_deallocate (__mach_task_self (), file); + file = __file_name_lookup_at (fd, 0, file_name, O_READ | O_NOLINK, 0); + err = __io_read (file, &rbuf, &len, 0, len); if (!err && rbuf != buf) {