Skip to content

Commit

Permalink
setting error exit code when exec* errors (#65)
Browse files Browse the repository at this point in the history
* setting error exit code when exec* errors

otherwise when exec* would fail, its the error is indicated by errno
however no appropriate exit code would be set and the overall subprocess
would be marked as successful with exit code of 0

* exec* never returns so always exiting without checking return value

* docs: add TODO to switch to abort()
  • Loading branch information
miki725 authored Mar 25, 2024
1 parent c523586 commit 7f2baf3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions nimutils/c/subproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,16 @@ subproc_do_exec(subprocess_t *ctx)
else {
execv(ctx->cmd, ctx->argv);
}
// If we get past the exec, kill the subproc, which will
// tear down the switchboard.
abort();
// If we get past the exec, kill the subproc with non-zero exit code,
// which will tear down the switchboard and print to stderr the
// errono description. For example for nonexisting command will be:
// foo: No such file or directory
fprintf(stderr, "%s: %s\n",ctx->cmd, strerror(errno));
// TODO switch back to abort() once better event handling is implemented
// in switchboard to correctly detect exit code as otherwise waitpid()
// detects program has exited however not all signal handlers have executed
// hence exit code is unknown yet
exit(1);
}

party_t *
Expand Down

0 comments on commit 7f2baf3

Please sign in to comment.