From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5117 invoked from network); 23 Apr 1998 13:29:33 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 23 Apr 1998 13:29:32 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id JAA04951; Thu, 23 Apr 1998 09:24:49 -0400 (EDT) Resent-Date: Thu, 23 Apr 1998 09:24:49 -0400 (EDT) Date: Thu, 23 Apr 1998 10:13:04 +0100 From: Andrew Main Message-Id: <199804230913.KAA05486@diamond.tao.co.uk> To: zsh-workers@math.gatech.edu Subject: PATCH: NO_CLOBBER X-Patch: 269 Resent-Message-ID: <"QAkwi1.0.ID1.X4qFr"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/3859 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu -----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-----