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)
Apr 22 2024, 5:42 AM
Unknown Object (File)
Jan 13 2024, 11:01 AM
Unknown Object (File)
Dec 23 2023, 1:32 AM
Unknown Object (File)
Dec 21 2023, 9:25 PM
Unknown Object (File)
Dec 10 2023, 8:42 PM
Unknown Object (File)
Nov 30 2023, 1:13 PM
Unknown Object (File)
Nov 27 2023, 8:11 AM
Unknown Object (File)
Nov 22 2023, 5:37 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.