This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[HURD,PATCH] Reopen file descriptor on lookup


Hello,

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/3", 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

  Linux $ cat /dev/fd/3 3>> foo
  Hello world!

  Hurd $ cat /dev/fd/3 3>> foo
  cat: /dev/fd/3: Bad file descriptor
  
The following demonstrates the shared cursor:

  Linux $ cat /dev/fd/3 /dev/fd/3 3< foo
  Hello world!
  Hello world!

  Hurd $ cat /dev/fd/3 /dev/fd/3 3< foo
  Hello world!

Regards,
  Fredrik

2010-02-17  Carl Fredrik Hammar  <hammy.lite@gmail.com>
	* hurd/lookup-retry.c (__hurd_file_name_lookup_retry) <fd/>:
	Reopen file descriptor before returning it.
---
 hurd/lookup-retry.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/hurd/lookup-retry.c b/hurd/lookup-retry.c
index 0a88622..90797aa 100644
--- a/hurd/lookup-retry.c
+++ b/hurd/lookup-retry.c
@@ -222,14 +222,13 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
 		  if (err)
 		    return err;
 		  if (*end == '\0')
-		    return 0;
+		    /* Retry so that descriptor is reopened.  */
+		    file_name = end;
 		  else
-		    {
-		      /* Do a normal retry on the remaining components.  */
-		      startdir = *result;
-		      file_name = end + 1; /* Skip the slash.  */
-		      break;
-		    }
+		    /* Do a normal retry on the remaining components.  */
+		    file_name = end + 1; /* Skip the slash.  */
+		  startdir = *result;
+		  break;
 		}
 	      else
 		goto bad_magic;
-- 
1.6.6.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]