Page MenuHomeFreeBSD

etcupdate: Always extract to a temporary tree.
ClosedPublic

Authored by jhb on Apr 19 2021, 9:20 PM.

Details

Summary

etcupdate has had a somewhat nasty race condition since its creation
in that its state machine can get very confused if it is interrupted
while building the tree to compare against. This is exacerbated by
the fact that etcupdate doesn't emit any output while building the
tree which can take several seconds (especially in recent years with
the addition of the tree-wide buildconfig/installconfig passes).

To mitigate this, always install a new tree into a temporary directory
created via mktemp as was previously done only for dry-runs via -n.
The existing trees are only rotated and the new tree installed as
/var/db/etcupdate/current after the update command has completed.

MFC after: 2 weeks

Diff Detail

Repository
rG FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

jhb requested review of this revision.Apr 19 2021, 9:20 PM

I think this looks good...
However, one thought did occur to me: do we need a t"rap X rm -rf $newdir" for some value of X so the tree is removed when etcupdate is interrupted?

This revision is now accepted and ready to land.Apr 19 2021, 9:29 PM

Ah yes, please! This has been a pet peeve for a while...

In D29843#669799, @imp wrote:

I think this looks good...
However, one thought did occur to me: do we need a t"rap X rm -rf $newdir" for some value of X so the tree is removed when etcupdate is interrupted?

The callers of the various routines cleanup explicitly when it fails. There is a followup change to trap for SIGINT which fixes Ctrl-C to trigger the cleanups.

This revision was automatically updated to reflect the committed changes.