Page MenuHomeFreeBSD

newvers.sh: Don't use return to exit.
ClosedPublic

Authored by jhb on Jun 14 2022, 4:10 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Mar 23, 2:55 PM
Unknown Object (File)
Mon, Mar 23, 6:13 AM
Unknown Object (File)
Sun, Mar 22, 6:21 AM
Unknown Object (File)
Thu, Mar 19, 11:26 PM
Unknown Object (File)
Sat, Mar 14, 3:26 PM
Unknown Object (File)
Sat, Mar 14, 1:44 PM
Unknown Object (File)
Sat, Mar 14, 10:53 AM
Unknown Object (File)
Sat, Mar 14, 12:18 AM
Subscribers
None

Details

Summary

Commit acfb506b3d00 replaced an exit 0 when using -V with a return
instead. FreeBSD's sh treats a return outside of a function like
exit, but this is a non-portable extension. Other Bourne shells only
permit return to be used within a function and continue execution
(possibly with a warning).

To fix, don't reuse VARS_ONLY (which is intended to be set by other
scripts before sourcing newvers.sh directly) and instead use a new
variable (VARS_ONLY_EXIT) to restore the use of exit for the
non-sourced case.

Obtained from: CheriBSD
Sponsored by: DARPA

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Jun 14 2022, 4:10 PM
jhb created this revision.
emaste added inline comments.
sys/conf/newvers.sh
138

could we just make this exit 0?

This revision is now accepted and ready to land.Jun 14 2022, 4:15 PM
sys/conf/newvers.sh
138

No. The intended use case is something like:

#/bin/sh

...
VARS_ONLY=1
. /path/to/sys/conf/newvers.sh
...

If you called exit 0 here you would exit that outer script rather than returning to the next line in the outer script.

This revision was automatically updated to reflect the committed changes.