Skip to content

Conversation

@TimWhiting
Copy link
Collaborator

@TimWhiting TimWhiting commented Aug 30, 2025

Fix exit status on unix for system call. The returned integer is not directly interpretable as an exit status.

Fixes: #797

Unfortunately, unix does this to require the user to check for other abnormal termination (due to signal / stopped process).

Not sure how you want to report that?

  • Add a tagged C union in kklib, and convert it to a Koka Error type in std/os/process?
  • Assignable parameters in kklib, ditto for std/os/proccess?
  • Something else?

My opinion is to do the simple fix now (below), with the plan of re-addressing this when we get to real process integration with libuv.

@daanx

@timbertson
Copy link
Contributor

timbertson commented Aug 30, 2025

I'm surprised stopped is a different branch, isn't that just another signal?

FWIW in my WIP libuv process branch, I went with an ADT for Exit-status(int) and Exit-signal(int). I don't expect most people would need to inspect this directly, they just want to check for success or not.

Edit: Ah, looks like stopped would not happen here, according to the docs:

WIFSTOPPED(wstatus)
returns true if the child process was stopped by delivery
of a signal; this is possible only if the call was done
using WUNTRACED or when the child is being traced (see
ptrace(2)).

kklib/src/os.c Outdated
if (WIFEXITED(status)) {
exitcode = WEXITSTATUS(status);
} else if (WIFSIGNALED(status)) { // TODO: Return differently in this branch
exitcode = WTERMSIG(status);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW haskell returns the negative of this value to distinguish it from an exit status, based on my various failed runs which return -11 (SIGSEGV) 🤦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

run-system returns invalid codes

2 participants