Skip to content

fix(signal): return -1 and set errno when kill() fails - #144

Open
Arshia001 wants to merge 1 commit into
mainfrom
fix/kill-errno
Open

Arshia001 wants to merge 1 commit into
mainfrom
fix/kill-errno

Conversation

@Arshia001

Copy link
Copy Markdown

Summary

kill() returned the raw WASI errno from __wasi_proc_signal instead of following POSIX: a failed call came back as a positive number (e.g. 71 for ESRCH) and errno was left untouched. Callers that check kill(...) == -1 (or < 0) treated every failure as success.

Now a non-zero result sets errno and returns -1, the same way setitimer() already handles __wasi_proc_raise_interval.

Impact

Until now this was masked because the runtime's proc_signal always returned success. wasmerio/wasmer#7045 makes it report ESRCH for a positive PID that doesn't exist, so kill(pid, 0) liveness checks can finally work — but only once libc reports the failure the POSIX way.

Verification

A small program calling kill(getpid(), 0), kill(0x7fffffff, 0) and kill(0, 0), run on the wasmer#7045 runtime:

kill(self, 0) kill(missing, 0) kill(0, 0)
current libc 0 71, errno = 0 0
this PR 0 -1, errno = ESRCH 0

raise() has a similar shape (it returns the raw result of __wasi_thread_signal), but POSIX only requires a non-zero return there; left as is.

Implemented by Claude Code (AI agent) on behalf of @Arshia001.

🤖 Generated with Claude Code

kill() returned the raw WASI errno from __wasi_proc_signal, so a failed
call came back as a positive number with errno untouched. Callers that
follow POSIX and check for -1 treated every failure as success; for
example kill(pid, 0) on a pid that no longer exists returned 71 (ESRCH)
instead of -1 with errno = ESRCH.

Map a non-zero result to errno and -1, as setitimer() already does.

Committed by Claude Code (AI agent) on behalf of Arshia Ghafoori.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant