Page MenuHomeFreeBSD

freebsd-update: recreate /var/db/freebsd-update if missing
Needs ReviewPublic

Authored by emaste on Oct 1 2023, 11:34 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 19, 2:18 PM
Unknown Object (File)
Tue, Nov 19, 12:22 PM
Unknown Object (File)
Oct 1 2024, 2:30 PM
Unknown Object (File)
Oct 1 2024, 2:02 PM
Unknown Object (File)
Sep 21 2024, 9:09 AM
Unknown Object (File)
Sep 20 2024, 2:27 AM
Unknown Object (File)
Sep 9 2024, 12:07 AM
Unknown Object (File)
Sep 7 2024, 10:05 PM
Subscribers

Details

Summary
Users may want to delete the contents of /var/db/freebsd-update
(PR 273601), and it is possible that they remove /var/db/freebsd-update
by accident.  Recreate it if missing.

PR:             263290

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

emaste created this revision.
usr.sbin/freebsd-update/freebsd-update.sh
611

I like the idea but I'm not sure this is the right place to do it. This is just setting defaults; I don't think we need to (re)create /var/db/freebsd-update if the user specified a different directory?

usr.sbin/freebsd-update/freebsd-update.sh
611

AFAICT config_WorkDir returns false if the directory is already set, so this will only create the directory if the user hasn't specified a different one. I put it here to avoid repeating /var/db/freebsd-update elsewhere

usr.sbin/freebsd-update/freebsd-update.sh
611

If we consider a scenario where a user sets -d /var/db/freebsd-update (out of habit maybe) but did not realize that the directory is gone, then the directory will not be created even though it would otherwise default to the same place.

That seems counterintuitive or wrong to me.

It might make more sense to do it in config_WorkDir(), with the drawback that if parse_cmd() fails, a directory might get created without freebsd-update having supposedly started to work.

Another option is to do it between get_params (line 3524 in your version) and before for COMMAND in ..., in some initialization routine.

Side-question: why is usage() exiting with code 0? It will be reflected as a success condition...
(I believe historical practice was to output usage screens to stderr and exit with code 1 in such situations)

usr.sbin/freebsd-update/freebsd-update.sh
611

@emaste Right, I forgot how the config_* functions worked. I guess this is ok, but I still feel a bit weird having it in the "collect together configuration options" code. Would you consider adding having

# Create the work directory, if set to the default value
default_workdir_create () {
    if [ "$WORKDIR" = "/var/db/freebsd-update" ] && ! [ -d /var/db/freebsd-update ]; then
        echo "Creating default working directory /var/db/freebsd-update"
        install -u root -g wheel -m 700 -d /var/db/freebsd-update
    fi
}

and calling that from each of the _check_params functions? It's a somewhat bigger change but I think it's more in line with how the code organization.