LinuxSA Mailing list archives

Index: [thread] [date] [subject] [author]
  From: Daryl Tester <dt@picknowl.com.au>
  To  : Jake Hawkes <jake@infinitylimited.net>
  Date: Fri, 28 Apr 2000 09:20:37 +0930

Re: Protecting files against power failure

Jake Hawkes wrote:

>> (although, of course, this shouldn't
>> affect the shell's file descriptor - care to hazard a guess why?).

> this feels like a class :) Bueler... Bueler....

:-)  And in this case, even the teacher can be wrong ...

> um, because the file descriptors are passed by value, not reference?

Nyet; they're duplicated with dup() or dup2().  And having just
read up on it (because I'm a little rusty), it says ...

       The  old  and new descriptors may be used interchangeably.
       They share locks, file position pointers  and  flags;  for
       example,  if  the file position is modified by using lseek
       on one of the descriptors, the position  is  also  changed
       for the other.

The embarassing bit being that they "share file position pointers".
And sure enough, if you are warped enough to do the following 
(note the magic 3<&6 in python's command line) ...

[dt@nipnyep dt]$ python 3<&6
Python 1.5.2 (#1, Sep 17 1999, 20:15:36)  [GCC egcs-2.91.66 19990314/Linux (egcs- on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import posix
>>> f = posix.fdopen(3, 'r')
>>> f.seek(0)
>>> ^D

and then cat <&6 once back at the shell prompt, there listed are all
your evil deeds.

> "I'm only smart enough to know how stupid I am", Joe Strummer.

If only I were so smart ("I am so smart, I am so smart, S M R T, I mean
S M A R T!" - our favourite D'oh-ster).

And hopefully, this will protect everyone's files against power failure. :-)


Regards,
  Daryl Tester

-- 
LinuxSA WWW: http://www.linuxsa.org.au/  IRC: #linuxsa on irc.linux.org.au
To unsubscribe from the LinuxSA list:
  mail linuxsa-request@linuxsa.org.au with "unsubscribe" as the subject


Index: [thread] [date] [subject] [author]
Return to the LinuxSA Mailing List Information Page