Debian Developers - Redirections and noclobber

This is Interesting: Free IT Magazines  
Home > Archive > Debian Developers > October 2004 > Redirections and noclobber





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Redirections and noclobber
Frank Küster

2004-10-06, 5:57 pm

Hi,

in bug #275140, I was made aware of a problem with the handling of
tempfiles in tetex's maintainer scripts, and it seems to be a general
problem. Basically, we do

tempfile=3D`mktemp`
echo something > $tempfile

and this will fail if the noclobber option is set in the executing
shell, because after mktemp the $tempfile exists.=20

It is easy to fix this:

echo something >| $tempfile

but both I and the bug submitter were puzzled that we didn't find any
previous discussions about the topic. Obviously, noclobber is only
rarely used (otherwise we would have gotten bugreports earlier), but I
see no reason, neither in Policy nor in "common sense", why root
shouldn't use it. On the other hand, this usage of mktemp has been
the result of discussions on debian-tetex-maint@l.d.o, and I'm quite
sure to have seen it elsewhere.

Is there anything I've missed? Do you think this needs to be clarified
in Policy or the Developer's Reference?

TIA, Frank
--=20
Frank K=FCster
Inst. f. Biochemie der Univ. Z=FCrich
Debian Developer
Bill Allombert

2004-10-06, 5:57 pm

On Wed, Oct 06, 2004 at 05:02:00PM +0200, Frank Küster wrote:
> Hi,
>
> in bug #275140, I was made aware of a problem with the handling of
> tempfiles in tetex's maintainer scripts, and it seems to be a general
> problem. Basically, we do
>
> tempfile=`mktemp`
> echo something > $tempfile
>
> and this will fail if the noclobber option is set in the executing
> shell, because after mktemp the $tempfile exists.
>
> It is easy to fix this:
>
> echo something >| $tempfile
>
> but both I and the bug submitter were puzzled that we didn't find any
> previous discussions about the topic. Obviously, noclobber is only
> rarely used (otherwise we would have gotten bugreports earlier), but I
> see no reason, neither in Policy nor in "common sense", why root
> shouldn't use it. On the other hand, this usage of mktemp has been
> the result of discussions on debian-tetex-maint@l.d.o, and I'm quite
> sure to have seen it elsewhere.


In my opinion, noclobber should only be set for interactive shell, or
explicitely in a shell-script. The same for most others shell options.

Now, does POSIX sh support >| ?

Cheers,
--
Bill. <ballombe@debian.org>

Imagine a large red swirl here.


--
To UNSUBSCRIBE, email to debian-devel-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
David Weinehall

2004-10-06, 5:57 pm

On Wed, Oct 06, 2004 at 06:19:35PM +0200, Bill Allombert wrote:
> On Wed, Oct 06, 2004 at 05:02:00PM +0200, Frank Küster wrote:
>
> In my opinion, noclobber should only be set for interactive shell, or
> explicitely in a shell-script. The same for most others shell options.
>
> Now, does POSIX sh support >| ?


Yes.


Regards: David Weinehall
--
/) David Weinehall <tao@acc.umu.se> /) Northern lights wander (\
// Maintainer of the v2.0 kernel // Dance across the winter sky //
\) http://www.acc.umu.se/~tao/ (/ Full colour fire (/


--
To UNSUBSCRIBE, email to debian-devel-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Frank Küster

2004-10-07, 2:57 am

Bill Allombert <allomber@math.u-bordeaux.fr> wrote:

> On Wed, Oct 06, 2004 at 05:02:00PM +0200, Frank K=FCster wrote:
>
> In my opinion, noclobber should only be set for interactive shell, or
> explicitely in a shell-script. The same for most others shell options.


But if I start apt-get upgrade or whatever from my interactive shell
with noclobber set, all childs will inherit it. That's how the problem
came up.

Regards, Frank
--=20
Frank K=FCster
Inst. f. Biochemie der Univ. Z=FCrich
Debian Developer
Bill Allombert

2004-10-07, 2:57 am

On Thu, Oct 07, 2004 at 10:18:09AM +0200, Frank Küster wrote:
> Bill Allombert <allomber@math.u-bordeaux.fr> wrote:
>
>
> But if I start apt-get upgrade or whatever from my interactive shell
> with noclobber set, all childs will inherit it. That's how the problem
> came up.


How ? noclobber is not part of the environment so is not carried out
by fork() and shells launched by dpkg should not be interative.

bash-2.05a$ set -C
bash-2.05a$ echo a >bar
bash-2.05a$ echo b >bar
bash: bar: cannot overwrite existing file
bash-2.05a$ ./test.sh
b
bash-2.05a$ cat test.sh
#! /bin/sh
echo a >foo
echo b >foo
cat foo

So I am really interested to know what happens here.

Cheers,
--
Bill. <ballombe@debian.org>

Imagine a large red swirl here.


--
To UNSUBSCRIBE, email to debian-devel-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Frank Küster

2004-10-08, 7:50 am

Hi Nils, hi all=20

(remember to take -devel out if applicable, I'm getting the mail through
the bug address),

Bill Allombert <allomber@math.u-bordeaux.fr> wrote:

> On Thu, Oct 07, 2004 at 10:18:09AM +0200, Frank K=FCster wrote:
>
> How ? noclobber is not part of the environment so is not carried out
> by fork() and shells launched by dpkg should not be interative.
>
> bash-2.05a$ set -C
> bash-2.05a$ echo a >bar
> bash-2.05a$ echo b >bar
> bash: bar: cannot overwrite existing file
> bash-2.05a$ ./test.sh
> b
> bash-2.05a$ cat test.sh
> #! /bin/sh
> echo a >foo
> echo b >foo
> cat foo
>
> So I am really interested to know what happens here.=20


Nils wrote in his bug report:=20

,----
| The postinst script:
| /var/lib/dpkg/info/tetex-base.postinst
| fails if you set bash's "noclobber" (say in your .bashrc via set -o noclo=
bber).
| (yes, I set noclobber in root's .bashrc -- I'm careful)
`----

Therefore I assumed that the "set -o" options get inherited as the
environment does. Which is wrong, according to Bill's test which I can
reproduce here. This is also correct according to POSIX
(http://www.opengroup.org/onlinepubs...chap02.html#ta=
g_02_12)

Nils, is it possible that your ~/.bashrc is read somehow by
noninteractive shells? I am not very used to the details of bash
invocation; according to the manpage it seems that non-interactive
non-login shells only source $BASH_ENV; I am not sure about
/etc/profile, however.

Regards, Frank

--=20
Frank K=FCster
Inst. f. Biochemie der Univ. Z=FCrich
Debian Developer
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com