Bug 247519

Summary: Success status on error in Makefile.xtra may cause loss of valuable data
Product: Base System Reporter: Stefan Eßer <se>
Component: miscAssignee: freebsd-bugs (Nobody) <bugs>
Status: New ---    
Severity: Affects Only Me CC: emaste, jhb
Priority: ---    
Version: Unspecified   
Hardware: Any   
OS: Any   
See Also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=252417
Attachments:
Description Flags
Make error case return error exit status none

Description Stefan Eßer freebsd_committer 2020-06-24 10:17:58 UTC
Created attachment 215904 [details]
Make error case return error exit status

When the condition for e.g. "ERROR: 'buildworld' is not a valid target for ..." is hit, make exits with a status of 0 indicating success.

This is a problem if "etcupdate" is used in such a situation, leading to an empty current directory and deletion of all rc files from /etc.

To repeat:

# cd /usr/src
# env WITH_DIRDEPS_BUILD=yes make buildworld
ERROR: 'buildworld' is not a valid target for amd64.

You can see the targets which are valid for a given machine
by running 'env MACHINE=<machine> make show-valid-targets'
For other information, read: 

# echo $?
0

(Besides WITH_DIRDEPS_BUILD=yes being suggested in the context of WITH_META_MODE=yes and leading to no targets being accepted except for the destroy targets, the above error text stops after "read:" without giving any indication what to read ...)

# env MACHINE=amd64 make show-valid-targets
Other targets:
  destroy
  destroy-arch
  destroy-host
  destroy-stage

The attached diff might not be the best solution, but it does at least prevent the removal of the rc files if etcupdate is invoked in such a situation.
Comment 1 John Baldwin freebsd_committer freebsd_triage 2021-12-08 17:59:00 UTC
From etcupdate's perspective we can at least assume that an empty "new" tree is equivalent to a make error.
Comment 2 Stefan Eßer freebsd_committer 2021-12-08 18:13:13 UTC
(In reply to John Baldwin from comment #1)
Yes, sanity checking the "current" directory before proceeding would be a good idea. 

A number of files are required to exist, e.g. "etc/master.passwd" or "etc/rc",
and if they are missing, etcupdate should exit with an error indication.