zsh-workers
 help / color / mirror / code / Atom feed
From: Andrew Main <zefram@tao.co.uk>
To: zsh-workers@math.gatech.edu
Subject: PATCH: NO_CLOBBER
Date: Thu, 23 Apr 1998 10:13:04 +0100	[thread overview]
Message-ID: <199804230913.KAA05486@diamond.tao.co.uk> (raw)

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


             reply	other threads:[~1998-04-23 13:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-04-23  9:13 Andrew Main [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199804230913.KAA05486@diamond.tao.co.uk \
    --to=zefram@tao.co.uk \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).