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, Sep 22, 12:34 PM
Unknown Object (File)
Sun, Sep 22, 11:03 AM
Unknown Object (File)
Wed, Sep 18, 8:51 PM
Unknown Object (File)
Wed, Sep 18, 3:13 PM
Unknown Object (File)
Tue, Sep 17, 3:39 PM
Unknown Object (File)
Tue, Sep 17, 1:01 PM
Unknown Object (File)
Tue, Sep 17, 12:47 AM
Unknown Object (File)
Mon, Sep 16, 2:26 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.