zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: NO_CLOBBER
@ 1998-04-23  9:13 Andrew Main
  1998-04-23 14:22 ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Main @ 1998-04-23  9:13 UTC (permalink / raw)
  To: zsh-workers

-----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-----


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1998-04-23 18:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-23  9:13 PATCH: NO_CLOBBER Andrew Main
1998-04-23 14:22 ` Peter Stephenson
1998-04-23 14:49   ` Bruce Stephens
1998-04-23 15:26     ` Mr M P Searle
1998-04-23 16:44       ` Bart Schaefer
1998-04-23 17:43         ` Mr M P Searle
1998-04-23 18:44   ` Andrew Main

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).