* [hurd,commited] hurd: Fix readlink() hanging on fifo
@ 2022-09-14 16:58 Samuel Thibault
2022-09-14 17:04 ` Andreas Schwab
0 siblings, 1 reply; 3+ messages in thread
From: Samuel Thibault @ 2022-09-14 16:58 UTC (permalink / raw)
To: libc-alpha; +Cc: Samuel Thibault, commit-hurd
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.
---
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)
{
--
2.35.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [hurd,commited] hurd: Fix readlink() hanging on fifo
2022-09-14 16:58 [hurd,commited] hurd: Fix readlink() hanging on fifo Samuel Thibault
@ 2022-09-14 17:04 ` Andreas Schwab
2022-09-15 19:56 ` Samuel Thibault
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Schwab @ 2022-09-14 17:04 UTC (permalink / raw)
To: Samuel Thibault; +Cc: libc-alpha, commit-hurd
On Sep 14 2022, Samuel Thibault wrote:
> 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);
How do you know that file_name still points at the same thing?
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [hurd,commited] hurd: Fix readlink() hanging on fifo
2022-09-14 17:04 ` Andreas Schwab
@ 2022-09-15 19:56 ` Samuel Thibault
0 siblings, 0 replies; 3+ messages in thread
From: Samuel Thibault @ 2022-09-15 19:56 UTC (permalink / raw)
To: Andreas Schwab; +Cc: libc-alpha, commit-hurd
Andreas Schwab, le mer. 14 sept. 2022 19:04:52 +0200, a ecrit:
> On Sep 14 2022, Samuel Thibault wrote:
> > 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);
>
> How do you know that file_name still points at the same thing?
Righ, better make that atomic. I have pushed it so.
Thanks,
Samuel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-15 19:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-14 16:58 [hurd,commited] hurd: Fix readlink() hanging on fifo Samuel Thibault
2022-09-14 17:04 ` Andreas Schwab
2022-09-15 19:56 ` Samuel Thibault
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).