Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: NO_CLOBBER



-----BEGIN PGP SIGNED MESSAGE-----

Looks like someone got too clever, and decided that NO_CLOBBER shouldn't
stop you opening a FIFO.  Sounds sort of reasonable, but it is more
complicated than necessary and incompatible with ksh (and POSIX).
NO_CLOBBER should mean that a successful write redirection guarantees
that you've created a regular file, and anything you write to it isn't
going anywhere else.

The bug that was observed yesterday was caused by the second open()
attempt overwriting the correct errno.  This was introduced in 3.1.0 in
an attempt to fix a race condition in the 3.0 code.  By correcting the
overall behaviour, this bug disappears.

 *** Src/exec.c	1997/07/04 19:12:03	1.68
 --- Src/exec.c	1998/04/22 20:57:40
 ***************
 *** 1006,1025 ****
   static int
   clobber_open(struct redir *f)
   {
 !     struct stat buf;
 !     int fd;
   
 !     if (isset(CLOBBER) || IS_CLOBBER_REDIR(f->type))
 ! 	return open(unmeta(f->name), O_WRONLY | O_CREAT | O_TRUNC, 0666);
 !     if ((fd = open(unmeta(f->name), O_WRONLY | O_CREAT | O_EXCL, 0666)) >= 0)
 ! 	return fd;
 !     if ((fd = open(unmeta(f->name), O_WRONLY)) < 0)
 ! 	return fd;
 !     if (!fstat(fd, &buf) && !S_ISREG(buf.st_mode))
 ! 	return fd;
 !     close(fd);
 !     errno = EEXIST;
 !     return -1;
   }
   
   /* size of buffer for tee and cat processes */
 --- 1006,1015 ----
   static int
   clobber_open(struct redir *f)
   {
 !     int oflags = O_WRONLY | O_CREAT |
 ! 	((unset(CLOBBER) && !IS_CLOBBER_REDIR(f->type)) ? O_EXCL : O_TRUNC);
   
 !     return open(unmeta(f->name), oflags, 0666);
   }
   
   /* size of buffer for tee and cat processes */

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 5.0i for non-commercial use
Charset: ascii

iQEVAwUBNT5b85mk9GeOHh7BAQELTAf/RuTLGSP89Eofwb5zVBeJkEHWpebmVLeG
T8x2r4fAF67H0/3QGJrWkzv8yRiAurJ8jgFxap/G0zh3KWeRJsOxkfDvHdZryCZc
EIhDdD3lGP5AzT57RKIYWkpG2FU2oRzYXjH6JjSjTmRLpXRvqv5Io/Z9l5P9WCXv
jV4Wu6G88/8OXE0LwD4F+FkW/hBt/wF1J/1HjGYBLEgwn20sf4sRCUukh9v7Xjzg
kdq0NYJ5N2/4msuR3h+qRpzHCXHZ1mG0nCV3Jy0zW11/2BI7yFIhHeqT2nnsRMLZ
IKeMPdwxpaU9PRaP2Cr4sWhvj+WqKjZ+MD8bYtK9KN8/QhCkQHAdqw==
=mrVi
-----END PGP SIGNATURE-----



Messages sorted by: Reverse Date, Date, Thread, Author