Carl R. Witty writes:
> In ghc 2.08 running on Linux, if you try to do an openFile for writing
> on a dangling symlink (a symlink that does not point at an existing
> file), the openFile hangs in a tight loop.  strace reveals the
> following system calls:
> 
> open("Parser.hs", O_WRONLY|O_NOCTTY)    = -1 ENOENT (No such file or directory)
> open("Parser.hs", O_WRONLY|O_CREAT|O_EXCL|O_NOCTTY, 0666) = -1 EEXIST (File exists)
> 
> repeated over and over again forever.
> 

Hi,

thanks for the report - the C wrapper for openFile didn't make a
distinction between a race condition and a dangling symlink. Patch
appended.

--Sigbjorn

*** ghc/lib/cbits/openFile.lc.~3~       Sat Aug 23 13:55:54 1997
--- ghc/lib/cbits/openFile.lc   Sun Nov 16 18:20:04 1997
***************
*** 67,73 ****
                ghc_errtype = ERR_NOSUCHTHING;
                ghc_errstr = "file does not exist";
                return NULL;
!           }
            /* Now try to create it */
            while ((fd = open(file, oflags | O_CREAT | O_EXCL, 0666)) < 0) {
                if (errno == EEXIST) {
--- 67,81 ----
                ghc_errtype = ERR_NOSUCHTHING;
                ghc_errstr = "file does not exist";
                return NULL;
!           } else {
!               /* If it is a dangling symlink, break off now, too. */
!               struct stat st;
!               if ( lstat(file,&st) == 0) {
!                  ghc_errtype = ERR_NOSUCHTHING;
!                  ghc_errstr = "dangling symlink";
!                  return NULL;
!               }
!             }
            /* Now try to create it */
            while ((fd = open(file, oflags | O_CREAT | O_EXCL, 0666)) < 0) {
                if (errno == EEXIST) {

Reply via email to