Am 20.03.2025 um 21:50 schrieb James K. Lowden:
On Mar 13, 2025, at 8:04 AM, Simon Sobisch <simonsobi...@gnu.org> wrote:
exit() allows us to "pass to the operating system" directly; but it doesn't directly say
"success" or "fail".
Obviously the statements
STOP RUN WITH NORMAL STATUS 41
and
STOP RUN ERROR 41
Should have a different result for the operating system.
Or, obviously not.
For OSes I'm familiar with, there is no *definition* of success/failure.
There's just convention: 0 is success and nonzero failure. Even that is
honored in the breach, see diff(1).
IMO unless the OS defines success/failure outside the value of the exit status
value (above, 41), the COBOL compiler cannot supply meaning to STOP RUN NORMAL
or ERROR. It has no meaning in COBOL because it has no meaning outside COBOL.
By that reasoning, the two statements above both return 41 because there is no
way to say more. It is for the caller to decide what to do.
I do not think -41 is an option; the compiler should not make arbitrary changes
to the user's data.
It is temping to raise(SIG_TERM) for error, but again the 41 is lost.
STOP RUN WITH ERROR "Don't do that, Jon!"
When no numeric value is supplied, IMO:
• STOP RUN WITH NORMAL STATUS becomes exit(EXIT_SUCCESS)
• STOP RUN WITH ERROR becomes exit(EXIT_FAILURE)
That satisfies the Principle of Least Astonishment. BTW those values are
defined by C, not POSIX.
--jkl
I agree that this could be a reasonable approach:
* STOP RUN WITH NORMAL STATUS becomes exit(EXIT_SUCCESS)
* STOP RUN WITH ERROR becomes exit(EXIT_FAILURE)
* Any text given goes to an internal DISPLAY (_possibly_ WITH ERROR
doing a DISPLAY UPON SYSERR)
If I'd not now that "some heavy business applications" actually pass the
error using specific values (one for deadlock, another for general db
issues, one for logic issues, ...) I'd say "screw the numbers - just
DISPLAY them".
But a combined option would be possible as well:
* output a text of "STOP ... WITH ERROR" is then noted by still doing
exit(number_given_if_none_then_EXIT_FAILURE), but always after an
internal DISPLAY "STOP WITH ERROR[ nr][: message]" UPON SYSERR"
* output a text of "STOP ... WITH NORMAL STATUS" is then noted by
still doing exit(number_given_if_none_then_EXIT_SUCCESS),
and (possibly only in case of a text or number given) an internal
DISPLAY "STOP WITH NORMAL STATUS[ nr][: message]" UPON SYSOUT"
Opinions?
Simon