On Sat, May 13, 2006 at 11:18:32PM +0100, Jeremy Henty wrote:
> On Sat, May 13, 2006 at 10:23:48PM +0300, Tapio Aura Kelloniemi wrote:
> 
> > Well, perhaps I'm misunderstunding something, but I have assumed
> > that when a shared library is loaded into memory when a process is
> > started (or via dlopen) the disk file it comes from is no more read.
> 
> My understanding is that the shared library is mmap-ed into the
> process.  This means that the process *thinks* it is just reading
> memory, but in fact the kernel is reading the file behind the scenes.
> I think it is possible that the file could be read a long time after
> the mmap system call finishes.

Yes, mmapped files may be read after map completes.

> I suspect a similar thing happens if you delete a shared library - if
> any processes have mmap-ed that library then the kernel will preserve
> the library and those processes will not notice that the library isn't
> linked to the file system.  If you reinstall the library you will
> create a new file (even though it has the same path as the old
> library).  New processes will open the path and get the new library,
> but old processes will continue to access the old library.

Depends on how the new file is installed. According to what I have learned,
the following should work:
rm -f /usr/lib/libxxx.so && cp /usr/src/libxxx/libxxx.so /usr/lib

And this should crash all processes using libxxx:
cat /usr/src/libxxx/libxxx.so > /usr/lib/libxxx.so

IIRC, cp has a parameter which forces it to first unlink the target file
before writing to it. Perhaps install always works that way. Again, the safest
way to upgrade a shared library is to first copy into a temporary file on the
same filesystem with the old library and then rename the new one. This way a
process will never try to load an incomplete library object.

-- 
Tapio
-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Reply via email to