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)
Sun, Oct 13, 12:56 PM
Unknown Object (File)
Sep 28 2024, 6:40 PM
Unknown Object (File)
Sep 25 2024, 1:01 PM
Unknown Object (File)
Sep 24 2024, 5:19 PM
Unknown Object (File)
Sep 22 2024, 12:34 PM
Unknown Object (File)
Sep 22 2024, 11:03 AM
Unknown Object (File)
Sep 18 2024, 8:51 PM
Unknown Object (File)
Sep 18 2024, 3:13 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.