From: Enrico Weigelt <weigelt@metux.de>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] march in /etc/make.conf
Date: Fri, 21 Jul 2006 13:51:25 +0200 [thread overview]
Message-ID: <20060721115125.GF4971@nibiru.local> (raw)
In-Reply-To: <44ACE259.60603@mid.message-center.info>
* Alexander Skwar <listen@alexander.skwar.name> wrote:
Hi,
> Well, depends on how you define "open files are overwritten". On
> Linux, it is like you say. But on Windows and HP-UX, you CANNOT
> replace a file, if it's still opened somewhere. Eg. you cannot
> replace /bin/sh. Instead, a new file will be created and after
> a reboot, the new file will be moved in place (that's how it
> works on HP-UX, on Windows you cannot overwrite opened files.).
>
> What I mean: On Linux, you can replace /bin/sh even if it used.
> You cannot overwrite the used inodes/blocks, that's absolutely
> correct, but that's not what I meant.
ACK.
I'll try to explain the logic behind a little bit more detailed:
On Linux (and probably other Unix'ish kernels), files are not
identified by names, but inode-id's. The name is just an pointer
to the file, just like an DNS-name->IP-addr mapping ;-)
Many such pointers to some file may exist. Only when all pointers
are removed (open fd's also considered as an pointer) the file
gets actually removed. That's why the syscall used for removing
a file is called unlink(): it just removes the given name but
does not actually delete it.
When you intend to replace some file, you've got two choices:
(from the kernel's view)
a) open the existing file, probably truncate it and write new the
data. if someone has opened this file, he will see the changes
you made. If the file has been mmap'ed to some process, it will
see the changes immediately in its address space. therefore files
should be locked (at least the used regions), so an accidental
overwrite (which may cause ugly crashes) can be prevented. AFAIK
on Linux, .TEXT segments are always locked when the get mapped in
(you you get "busy" when trying to write there)
b) create a new file under the old name. either by renaming or
unlink'ing the old file. here you've got no problem w/ other
processes holding the file opened, since you actually have
two different files. the new file only gets accessed when
you (re)open the file and thus let the kernel do an new
name->inode lookup.
BTW: when coding installers for running systems (which in fact
is the case in >90%). Do not use cp (at least GNU coreutils),
since it *overwrites* the existing file (case a). This will
fail on used .TEXT (=executable code) files, since they're locked
and most likely produce problems with other open files.
If writing the file does not run almost immediately you should
first write to some temporary file (on the same filesystem!)
and then do a quick rename (unlink(..) ; rename(..)) so nobody
tries to use unfinished files.
And be very careful you reinstall you (running) installer !
Several years ago, glibc had a critical problem, which screwed up
your system on install over the running system: it first removed
the /lib/ld.so and /lib/libc* symlinks and then recreated them by
separate calling /bin/rm and /bin/ln binaries. If they weren't
linked statically, it killed itself - /bin/ln coulnd'n be executed
since libc was unusable in this moment. Using -s flag to ln instead
of calling rm did the trick.
I have no idea how careful emerge is here ...
cu
--
---------------------------------------------------------------------
Enrico Weigelt == metux IT service - http://www.metux.de/
---------------------------------------------------------------------
Please visit the OpenSource QM Taskforce:
http://wiki.metux.de/public/OpenSource_QM_Taskforce
Patches / Fixes for a lot dozens of packages in dozens of versions:
http://patches.metux.de/
---------------------------------------------------------------------
--
gentoo-user@gentoo.org mailing list
next prev parent reply other threads:[~2006-07-21 11:59 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-05 3:07 [gentoo-user] iptables wiki james
2006-07-05 10:03 ` Daniel
2006-07-05 15:28 ` [gentoo-user] " James
2006-07-05 16:22 ` Richard Fish
2006-07-05 18:30 ` James
2006-07-05 19:55 ` Richard Fish
2006-07-05 16:32 ` Dale
2006-07-05 16:45 ` James
2006-07-05 17:27 ` Dale
2006-07-05 18:36 ` Steve Wilson
2006-07-06 1:59 ` Dale
2006-07-06 7:37 ` Neil Bothwick
2006-07-06 8:22 ` [gentoo-user] march in /etc/make.conf Pawel K
2006-07-06 8:35 ` Dirk Heinrichs
2006-07-06 9:27 ` Alexander Skwar
2006-07-06 9:46 ` Dirk Heinrichs
2006-07-06 9:50 ` Uwe Thiem
2006-07-06 10:13 ` Alexander Skwar
2006-07-21 11:51 ` Enrico Weigelt [this message]
2006-07-06 8:36 ` Janusz Bossy
2006-07-21 11:56 ` Enrico Weigelt
2006-07-06 9:26 ` Alexander Skwar
2006-07-06 10:29 ` Neil Bothwick
2006-07-11 1:03 ` [gentoo-user] Re: iptables wiki Dale
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=20060721115125.GF4971@nibiru.local \
--to=weigelt@metux.de \
--cc=gentoo-user@lists.gentoo.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox