Page MenuHomeFreeBSD

freebsd-update(8): Lock working directory while in use
AbandonedPublic

Authored by john.grafton_runbox.com on Jan 11 2023, 5:00 PM.
Tags
None
Referenced Files
Unknown Object (File)
Nov 23 2024, 12:29 PM
Unknown Object (File)
Nov 21 2024, 12:19 PM
Unknown Object (File)
Nov 19 2024, 3:51 PM
Unknown Object (File)
Nov 7 2024, 5:51 AM
Unknown Object (File)
Nov 5 2024, 2:55 PM
Unknown Object (File)
Nov 5 2024, 3:43 AM
Unknown Object (File)
Oct 16 2024, 10:03 PM
Unknown Object (File)
Oct 16 2024, 4:55 PM

Details

Reviewers
None
Summary

Running multiple instances of freebsd-update at the same time on the
same working directory often results in a failed update or worse. This is
especially problematic for users who use freebsd-update in cron to check
for updates. If freebsd-update is run automatically while another instance
is already in progress, the resulting failure can be difficult to diagnose.

This update prevents the collision by locking the working directory and
failing to start an update if the working directory is already locked.

PR: 266270

Test Plan

Execute two instances of freebsd-update fetch at the same time. This should result in the second instances failing with a locked working directory error.

Instance 1

# freebsd-update fetch
Looking up update.FreeBSD.org mirrors... 2 mirrors found.
Fetching metadata signature for 13.1-RELEASE from update1.freebsd.org... done.
Fetching metadata index... done.
Inspecting system... done.
Preparing to download files... done.
...

Instance 2

# freebsd-update fetch
another freebsd-update(8) instance is running in /var/db/freebsd-update
specify a different work directory with -d

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 49055
Build 45944: arc lint + arc unit

Event Timeline

This is a very large diff because I essentially split the command line and config parsing code from the actual update functions (fetch, install, update, etc). The reason I split them is to be able to execute the commands shell script with lockf(1) to lock the working directory. I avoided making any changes to the update functions themselves other than cron. I didn't want to lock the working directory during the cron splay time so I pulled just its sleep into the parsing script.

This is a sizable change to freebsd-update that I don't believe is necessary. Closing.