[Bug 271287] etcupdate silently installs empty files / unhandled error in install_new()

From: <bugzilla-noreply_at_freebsd.org>
Date: Sat, 06 May 2023 20:23:31 UTC

            Bug ID: 271287
           Summary: etcupdate silently installs empty files / unhandled
                    error in install_new()
           Product: Base System
           Version: 13.2-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: 000.fbsd@quip.cz

I described it in mailinglist with more verbose details

In some corner cases etcupdate installs 80+ empty files in to /etc/ which makes
the system unbootable. All files that should be just automatically updated were
installed empty. Vital files like /etc/login.conf, scripts in /etc/rc.d/ and so

etcupdate contains function install_new() which uses "cp -Rp" to copy files to
/etc/ but it does not check if copy failed or not and silently continue. This
leads to unbootable system in some corner cases. The function clearly does not
do what it should according to comment above the function. It always returns 0.

# Install the "new" version of a file.  Returns true if it succeeds
# and false otherwise.
# $1 - pathname of the file to install (relative to DESTDIR)

    if ! install_dirs $NEWTREE "$DESTDIR" $1; then
        return 1
    log "cp -Rp ${NEWTREE}$1 ${DESTDIR}$1"
    if [ -z "$dryrun" ]; then
        cp -Rp ${NEWTREE}$1 ${DESTDIR}$1 >&3 2>&1
    post_install_file $1
    return 0

In my case the problem of failing cp -Rp was caused by running etcupdate on
upgraded system from 12.3 to 13.2 without reboot so every call of cp -Rp failed
with "Function not implemented", but it is not user visible error. etcupdate
shows nothing wrong. Those messages are logged in to /var/db/etcupdate/log but
if you run "etcupdate" and because it shows success then "etcupdate resolve"
and "etcupdate status" then the log file does not contain anything useful
because it is overwritten by each new run of etcupdate.
I propose appending to log file instead of overwriting it. Or use some kind of
rotation of at least 5 history files. It was really hard to find what / where
is going wrong after the system cannot boot.

You are receiving this mail because:
You are the assignee for the bug.