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)
Thu, Nov 27, 9:39 PM
Unknown Object (File)
Wed, Nov 26, 2:50 AM
Unknown Object (File)
Tue, Nov 25, 11:32 PM
Unknown Object (File)
Fri, Nov 21, 8:43 PM
Unknown Object (File)
Nov 18 2025, 3:19 AM
Unknown Object (File)
Nov 4 2025, 3:45 AM
Unknown Object (File)
Oct 29 2025, 4:33 PM
Unknown Object (File)
Oct 29 2025, 4:31 PM
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
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 45972
Build 42860: arc lint + arc unit

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.