First of all, the cp(1) command is actually a 32-bit application ...

# uname -a
SunOS opensolaris 5.11 snv_101b i86pc i386 i86pc Solaris
# which cp
/usr/gnu/bin/cp
# file /usr/gnu/bin/cp
/usr/gnu/bin/cp:        ELF 32-bit LSB executable 80386 Version 1 [FPU], 
dynamically linked, stripped
# ldd /usr/gnu/bin/cp
        libgen.so.1 =>   /lib/libgen.so.1
        libc.so.1 =>     /lib/libc.so.1
        libm.so.2 =>     /lib/libm.so.2
#

As the Solaris 10 cp(1) manpage states "If target_file exists, cp 
overwrites its contents".  This is also true for the GNU cp which you 
get by default with OpenSolaris.

You get the Bus Error because cp(1) is linked with libc and thus 
overwrites the very code it is using. You should also be concerned about 
anything else linked with libc and already running. Basically, you don't 
want to be overwriting this file.

You could rename the old file so that anyone who has it open sees the 
old version, but this makes copying the new version hard (because cp(1) 
needs libc). There's also a window in which other programmes won't see a 
complete libc.

My solution leverages UNIX atomic rename and delete-on-last-close 
semantics. All you need to do is copy the new version of the file into 
the same filesystem (I'd suggest the same directory), and then rename it 
with the mv(1) command ...

# cd /lib
# ls -l libc.so.1
-rwxr-xr-x 1 root bin 1699252 2008-11-20 07:43 libc.so.1
# cp $NEWDIR/libc.so.1 libc.so.1.new
# chown root:bin libc.so.1.new
# chmod 755 libc.so.1.new
# mv libc.so.1.new libc.so.1
#

Of course, you also need to do the same in /lib/64 with a 64-bit version 
of your new libc.

The mv(1) will atomically rename the new version and unlink the old one. 
This means there is never an instant in which an incomplete version of 
libc exists. The old version will still exist (without a name) for 
anyone who already had it open, and this will be deleted when the last 
of these closes the file.

Given all the other neat new (and nonstandard) features in the GNU 
version of cp(1), it's a shame it doesn't have an option to cover this 
case automatically!

Phil


C. Bergström wrote:
> How do I replace the system libc?
>
> After I build it.. doing
>
> # Note.. cp libc and all other tools are 64bit..
>
> cp ./libs.so.1 /lib/amd64
>
> and
>
> LD_PRELOAD=./libc.so.1 cp libc.so.1 /lib/amd64/
>
> both result in
>
> Bus Error (core dumped)
>
> I haven't looked at the core, but I suspect there's a proper way to do 
> this.. I'll try mv next, but since they share so much of the same code I 
> doubt it will help.. (gnu move maybe.. ?) special utility on start-up.. 
> some trick with mount?
>
> Thanks
>
> ./C
> _______________________________________________
> opensolaris-discuss mailing list
> [email protected]
>   

_______________________________________________
opensolaris-discuss mailing list
[email protected]

Reply via email to