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)
Jan 26 2024, 11:08 PM
Unknown Object (File)
Dec 20 2023, 5:31 AM
Unknown Object (File)
Dec 12 2023, 4:24 PM
Unknown Object (File)
Aug 29 2023, 6:06 AM
Unknown Object (File)
Aug 2 2023, 4:58 AM
Unknown Object (File)
Aug 2 2023, 4:56 AM
Unknown Object (File)
Aug 2 2023, 12:45 AM
Unknown Object (File)
Aug 1 2023, 11:49 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
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.