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

* Re: PATCH: NO_CLOBBER
  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 18:44   ` Andrew Main
  0 siblings, 2 replies; 7+ messages in thread
From: Peter Stephenson @ 1998-04-23 14:22 UTC (permalink / raw)
  To: Zsh hackers list

Andrew Main wrote:
> Looks like someone got too clever, and decided that NO_CLOBBER shouldn't
> stop you opening a FIFO.

hmm, it wasn't me, but now:
  /etc/zshrc: file exists: /dev/null [243]
am I just going to have to live with this?  Seems quite a lot to live with.
Particularly since I can't alter this, and the system manager on this
machine complains with every incompatibility he has to work around.
I earnestly hope some workaround at least for /dev/null can be found.

-- 
Peter Stephenson <pws@ifh.de>       Tel: +39 50 844536
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy


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

* Re: PATCH: NO_CLOBBER
  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 18:44   ` Andrew Main
  1 sibling, 1 reply; 7+ messages in thread
From: Bruce Stephens @ 1998-04-23 14:49 UTC (permalink / raw)
  To: Zsh hackers list

Peter Stephenson <pws@ifh.de> writes:

> I earnestly hope some workaround at least for /dev/null can be found.

Yes!  /dev/null is important; I think it's vital that >/dev/null and
>&/dev/null work, even if it has to be done using an explicit check
hack.


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

* Re: PATCH: NO_CLOBBER
  1998-04-23 14:49   ` Bruce Stephens
@ 1998-04-23 15:26     ` Mr M P Searle
  1998-04-23 16:44       ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Mr M P Searle @ 1998-04-23 15:26 UTC (permalink / raw)
  To: Bruce Stephens; +Cc: zsh-workers

> Peter Stephenson <pws@ifh.de> writes:
> 
> > I earnestly hope some workaround at least for /dev/null can be found.
> 
> Yes!  /dev/null is important; I think it's vital that >/dev/null and
> >&/dev/null work, even if it has to be done using an explicit check
> hack.
> 

IMO a list that can be changed would be better than just checking for
/dev/null. An example on my system is the sound devices /dev/audio,
/dev/dsp*, but these are system dependent (although used from scripts). 
(devices should be protected though unless specifically given, for 
disks etc.)

In fact, maybe that's YAOption? I don't have NO_CLOBBER turned on,
it's too annoying. But I would if it could be restricted to some
places (/, /dev, maybe /usr).


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

* Re: PATCH: NO_CLOBBER
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 1998-04-23 16:44 UTC (permalink / raw)
  To: Zsh hackers list

On Apr 23,  4:22pm, Peter Stephenson wrote:
} Subject: Re: PATCH: NO_CLOBBER
}
} Andrew Main wrote:
} > Looks like someone got too clever, and decided that NO_CLOBBER shouldn't
} > stop you opening a FIFO.
} 
} hmm, it wasn't me, but now:
}   /etc/zshrc: file exists: /dev/null [243]
} am I just going to have to live with this?  Seems quite a lot to live with.

Device special files are not FIFOs, so even if the ksh incompatibility needs
to be rectified (which doesn't seem essential to me), the code needs to work
right for devices.  The old code with errno saved/restored would be better.

On Apr 23,  4:26pm, Mr M P Searle wrote:
} Subject: Re: PATCH: NO_CLOBBER
}
} IMO a list that can be changed would be better than just checking for
} /dev/null. An example on my system is the sound devices /dev/audio,

No, a list is not acceptable either.  New devices can appear, even on a
running system; having to recompile or reconfigure zsh every time one
does, is just plain wrong.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: PATCH: NO_CLOBBER
  1998-04-23 16:44       ` Bart Schaefer
@ 1998-04-23 17:43         ` Mr M P Searle
  0 siblings, 0 replies; 7+ messages in thread
From: Mr M P Searle @ 1998-04-23 17:43 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

> On Apr 23,  4:22pm, Peter Stephenson wrote:
> } Subject: Re: PATCH: NO_CLOBBER
> }
> } Andrew Main wrote:
> } > Looks like someone got too clever, and decided that NO_CLOBBER shouldn't
> } > stop you opening a FIFO.
> } 
> } hmm, it wasn't me, but now:
> }   /etc/zshrc: file exists: /dev/null [243]
> } am I just going to have to live with this?  Seems quite a lot to live with.
> 
> Device special files are not FIFOs, so even if the ksh incompatibility needs
> to be rectified (which doesn't seem essential to me), the code needs to work
> right for devices.  The old code with errno saved/restored would be better.
> 
> On Apr 23,  4:26pm, Mr M P Searle wrote:
> } Subject: Re: PATCH: NO_CLOBBER
> }
> } IMO a list that can be changed would be better than just checking for
> } /dev/null. An example on my system is the sound devices /dev/audio,
> 
> No, a list is not acceptable either.  New devices can appear, even on a
> running system; having to recompile or reconfigure zsh every time one
> does, is just plain wrong.

I meant a list of all such devices possible on a system - including those
not installed. Of course this list could be overridden or added to from
config files, but without any reconfiguration all devices could be
checked for. There wouldn't usually be other devices except when the OS
was upgraded, where the zsh port also would be. 

> 
> -- 
> Bart Schaefer                                 Brass Lantern Enterprises
> http://www.well.com/user/barts              http://www.brasslantern.com
> 


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

* Re: PATCH: NO_CLOBBER
  1998-04-23 14:22 ` Peter Stephenson
  1998-04-23 14:49   ` Bruce Stephens
@ 1998-04-23 18:44   ` Andrew Main
  1 sibling, 0 replies; 7+ messages in thread
From: Andrew Main @ 1998-04-23 18:44 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

Peter Stephenson wrote:
>  /etc/zshrc: file exists: /dev/null [243]

Ah, sorry, it appears that I misremebered POSIX, and it's actually ksh
that's got it wrong.  POSIX.2 clase 3.7.2: "Output redirection using the >
format shall fail if the noclobber option is set ... and the file named
... exists and is a regular file.".  So don't use that patch; I'll send
a better one tomorrow.

-zefram


^ 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).