On Mon, 25 Apr 2016 10:18:56 -0600, "Todd C. Miller" wrote:

> On Mon, 25 Apr 2016 18:04:58 +0200, Mark Kettenis wrote:
> 
> > Wait!  Does that mean there is a moment where there is not a valid
> > libc.so installed?  That would be wrong wouldn't it?
> > 
> > Doesn't the install command guarantee atomicity?
> 
> Seems like it would be safer to just install as /usr/lib/$_tmplib
> and then rename to /usr/lib/$_lib.  Trying to recover from a failed
> copy to /usr/lib/$_lib is potentially nasty (yes, I am aware that
> mv is statically linked).

A better approach is to use install(1)'s -S option (safe mode) which
will copy the file to a temp for you and rename it to the target
name if the copy is successful.  That way install(1) does the
cleanup.  This is how we install libraries via bsd.lib.mk too.

So instead of:

cp -p /usr/lib/$_lib /usr/lib/$_tmplib
install -o root -g bin -m 0444 $_lib /usr/lib/$_lib &&
        rm -f /usr/lib/$_tmplib ||
        mv /usr/lib/$_tmplib /usr/lib/$_lib

All you need is:

install -c -S -o root -g bin -m 0444 $_lib /usr/lib/$_lib

 - todd

Reply via email to