[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Reopen file descriptor on lookup
From: |
Carl Fredrik Hammar |
Subject: |
[PATCH] Reopen file descriptor on lookup |
Date: |
Wed, 26 Aug 2009 14:19:28 +0200 |
* hurd/lookup-retry.c (__hurd_file_name_lookup_retry) <fd/>:
Reopen file descriptor before returning it.
---
Hi,
Another stand-alone patch, but this one is new. It fixes what I think is
a bug in glibc.
The problem is that when opening file descriptors using FS_MAGIC_RETRY's
`fd/*' syntax, the descriptor isn't actually reopened, instead it acts as
a `dup'. That is, it isn't possible to change open mode and the file
cursor is shared between the new and old file descriptor.
This could have been intentional, however reopening seems much more useful.
It is definitely odd that `open ("/dev/fd/4", O_READ)' can result in an
unreadable file descriptor. In addition, this change makes the Hurd
consistent with Linux on this subject.
The behavior can easily be tested from the command line:
echo "Hello world!" > foo
cat /dev/fd/3 3>> foo
Which currently results in ``cat: /dev/fd/3: Bad file descriptor'', but
will result in ``Hello world!'' with my fix (and on Linux).
Regards,
Fredrik
---
hurd/lookup-retry.c | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/hurd/lookup-retry.c b/hurd/lookup-retry.c
index 96968f8..ce9eaf0 100644
--- a/hurd/lookup-retry.c
+++ b/hurd/lookup-retry.c
@@ -221,15 +221,14 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
errno = save;
if (err)
return err;
- if (*end == '\0')
- return 0;
+ /* Do a normal retry on the remaining components,
+ or reopen the descriptor. */
+ if (*end != '\0')
+ file_name = end + 1; /* Skip the slash. */
else
- {
- /* Do a normal retry on the remaining components. */
- startdir = *result;
- file_name = end + 1; /* Skip the slash. */
- break;
- }
+ file_name = end;
+ startdir = *result;
+ break;
}
else
goto bad_magic;
--
1.6.3.3
- [PATCH] Reopen file descriptor on lookup,
Carl Fredrik Hammar <=