-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Use exit codes between 0 and 255 (inclusive) #4511
Conversation
16511c1
to
4859d79
Compare
The only handling of return code in a script in my view would be a check for success or failure, which would mean comparison of the exit code to 0 (SUCCESS) and potentially a print of the non-zero exit code received for diagnostic purposes. https://unix.stackexchange.com/questions/418784/what-is-the-min-and-max-values-of-exit-codes-in-linux Valid exit codes available to POSIX compliant systems is the full range of int as per https://pubs.opengroup.org/onlinepubs/9699919799/functions/_exit.html / https://pubs.opengroup.org/onlinepubs/9699919799/functions/exit.html |
My use case is that I want to differentiate between 3 exit reasons when using the
With this MR, I'd check for exit codes 0, 11, and anything else, respectively.
Agreed. Most users use
"Typically" indicates inconsistent behavior, which is generally a good idea to avoid. |
Shells express exit codes in the range of 0-255. Anything outside of that range is brought into that range by modding it 256. For example: -1 becomes 255 -2 becomes 254 -3 becomes 253 This need to convert exit codes in shell scripts to use dependency check is unexpected and confusing. For that reason, returning exit codes outside of 0-255 is unusual and generally discouraged. Therefore, use exit codes in the 0-255 range. With this change, exit code 1 was used for both help and CVSS score failure. Therefore, the CVSS score failure exit code was changed to 15. See: https://tldp.org/LDP/abs/html/exit-status.html
@jeremylong what do you think. Looks reasonable to me, but think we should postpone integrating for an 8.x release as it will break existing returncode handling in scripted runs. |
I agree with the PR - but it would be a breaking change. This will get merged, but we might have a release or two happen before we move to 8.0.0. |
Fixes Issue
Shells express exit codes in the range of 0-255. Anything outside of that range is brought into that range by modding it 256.
For example:
-1 becomes 255
-2 becomes 254
-3 becomes 253
This need to convert exit codes in shell scripts to use dependency check is unexpected and confusing.
For that reason, returning exit codes outside of 0-255 is unusual and generally discouraged.
See: https://tldp.org/LDP/abs/html/exit-status.html
Description of Change
Therefore, use exit codes in the 0-255 range by changing all negative exit codes to positive ones (ex, -1 becomes 1).
With this change, exit code 1 was used for both help and CVSS score failure. Therefore, the CVSS score failure exit code was changed to 15.
Have test cases been added to cover the new functionality?
no