zig icon indicating copy to clipboard operation
zig copied to clipboard

Add 0 to SIG enum

Open psznm opened this issue 1 month ago • 9 comments

Closes #26011

I checked for manpages of kill on linux, freebsd, macos, openbsd, illumos, netbsd, openbsd. They all stated 0 can be used. I did not find manpages for others, but I assume it is all the same, so i added 0 to all of the enums.

psznm avatar Nov 22 '25 18:11 psznm

I like the idea of the fix, but the name INVAL for signal 0 isn't great. My other ideas aren't better though: ZERO seems equally wrong, NONE might work? (E.g., kill(pid, SIG.NONE)

I wonder if Zig should make the SIG enums non-exhaustive? If some kernel adds support for new signals (which is unlikely but is entirely its prerogative?), then users should be able to pass other integers.

Zig core team folks might have better ideas or stronger opinions. This patch does unblock the kill-0 case, so I think it is an improvement over the status quo.

rootbeer avatar Nov 22 '25 20:11 rootbeer

I like the idea of the fix, but the name INVAL for signal 0 isn't great. My other ideas aren't better though: ZERO seems equally wrong, NONE might work? (E.g., kill(pid, SIG.NONE)

I wonder if Zig should make the SIG enums non-exhaustive? If some kernel adds support for new signals (which is unlikely but is entirely its prerogative?), then users should be able to pass other integers.

Zig core team folks might have better ideas or stronger opinions. This patch does unblock the kill-0 case, so I think it is an improvement over the status quo.

I thought of making it NONE at first, but then I noticed one of the SIG implementations already had 0 named INVAL so that is what I went with. When you think about it, it makes sense. It is not a signal at all, so signal 0 is "invalid". But yes, in the case of kill, NONE makes more sense.

psznm avatar Nov 22 '25 21:11 psznm

i would propose ZERO, STATUS, or making it non-exhaustive

nektro avatar Nov 22 '25 21:11 nektro

I thought of making it NONE at first, but then I noticed one of the SIG implementations already had 0 named INVAL so that is what I went with.

Ah, looks like this is set on the Serenity SIG enum, and it probably was inherited from their header file: https://github.com/SerenityOS/serenity/blob/d0e77ec377b0a2b8f70e19050bb90586bae2ef8a/Kernel/API/POSIX/signal_numbers.h#L9 So there is some precedent for this name, but I'm not sure where they got it from (that header is part of Serenity's POSIX compatibility, but I don't think SIGINVAL is a POSIX thing ...). Overall, I don't find this case too compelling (but I can see why you're deferring to the existing name)....

rootbeer avatar Nov 23 '25 01:11 rootbeer

Oh, one useful suggestion I have is to add a simple test case for this so it doesn't get elided in the future (just ensure that you can send signal 0 to the current pid and get a non-error result?). You can probably put it in lib/std/posix/test.zig?

rootbeer avatar Nov 23 '25 01:11 rootbeer

Oh, one useful suggestion I have is to add a simple test case for this so it doesn't get elided in the future (just ensure that you can send signal 0 to the current pid and get a non-error result?). You can probably put it in lib/std/posix/test.zig?

I have added the test.

I am pretty confident about it, but I am struggling to make the tests run in a way that I can see that it is passing. Figured I could used -Dtest-filter, but I didn't figure out how, as no matter what I put there, it seems the test output runs way too much and always is the same (and I couldn't see my new test neither passing or failing)

psznm avatar Nov 23 '25 10:11 psznm

I am pretty confident about it, but I am struggling to make the tests run in a way that I can see that it is passing. Figured I could used -Dtest-filter, but I didn't figure out how, as no matter what I put there, it seems the test output runs way too much and always is the same (and I couldn't see my new test neither passing or failing)

The posix tests get run in a bunch of configurations, so you should see this tests execute a couple times. I recommend putting a compile time or run-time error in the test, and making sure you can trigger that. Just to be sure you're running the right target (which I believe should be zig build test-std). It may take a while on the first run, but subsequent runs are quick if little has changed.

Looking at the test more closely, its not clear to me why PermissionDenied error is being ignored. I think sending a signal to the current pid should always be allowed? (In which case this could just be a try posix.kill...?)

rootbeer avatar Nov 24 '25 08:11 rootbeer

Looking at the test more closely, its not clear to me why PermissionDenied error is being ignored. I think sending a signal to the current pid should always be allowed? (In which case this could just be a try posix.kill...?)

I will be changing this later to try current process and also non existent process. One of my unit tests detected that error checking of kill is not actually working, see #26034, so I am not sure if I should add failing test in this PR...?

psznm avatar Nov 24 '25 12:11 psznm

@rootbeer @squeek502 I made the test standalone and also added test case for missing process. I have also sucessfully ran the tests - I had some issues with using zig binary built from wrong version.

psznm avatar Nov 24 '25 17:11 psznm

https://codeberg.org/ziglang/zig/pulls/30015

alexrp avatar Dec 07 '25 10:12 alexrp