Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/std/c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2662,6 +2662,8 @@ pub const SIG = switch (native_os) {
pub const IOT: SIG = .ABRT;
pub const POLL: SIG = .EMT;

/// Invalid signal. Used in kill to perform checking without sending signal.
INVAL = 0,
/// hangup
HUP = 1,
/// interrupt
Expand Down Expand Up @@ -2756,6 +2758,7 @@ pub const SIG = switch (native_os) {
pub const RTMIN = 65;
pub const RTMAX = 126;

INVAL = 0,
HUP = 1,
INT = 2,
QUIT = 3,
Expand Down Expand Up @@ -2821,6 +2824,7 @@ pub const SIG = switch (native_os) {

pub const POLL: SIG = .IO;

INVAL = 0,
HUP = 1,
INT = 2,
QUIT = 3,
Expand Down Expand Up @@ -2895,6 +2899,7 @@ pub const SIG = switch (native_os) {

pub const IOT: SIG = .ABRT;

INVAL = 0,
HUP = 1,
INT = 2,
QUIT = 3,
Expand Down Expand Up @@ -2941,6 +2946,7 @@ pub const SIG = switch (native_os) {

pub const IOT: SIG = .ABRT;

INVAL = 0,
HUP = 1,
INT = 2,
QUIT = 3,
Expand Down Expand Up @@ -2989,6 +2995,7 @@ pub const SIG = switch (native_os) {

pub const IOT: SIG = .ABRT;

INVAL = 0,
HUP = 1,
INT = 2,
QUIT = 3,
Expand Down Expand Up @@ -3035,6 +3042,7 @@ pub const SIG = switch (native_os) {

pub const IOT: SIG = .ABRT;

INVAL = 0,
HUP = 1,
INT = 2,
QUIT = 3,
Expand Down
6 changes: 6 additions & 0 deletions lib/std/os/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3741,6 +3741,8 @@ pub const SIG = if (is_mips) enum(u32) {
pub const IOT: SIG = .ABRT;
pub const POLL: SIG = .IO;

INVAL = 0,

// /arch/mips/include/uapi/asm/signal.h#L25
HUP = 1,
INT = 2,
Expand Down Expand Up @@ -3787,6 +3789,8 @@ pub const SIG = if (is_mips) enum(u32) {
pub const PWR: SIG = .LOST;
pub const POLL: SIG = .IO;

/// Perform error checking without sending signal.
INVAL = 0,
HUP = 1,
INT = 2,
QUIT = 3,
Expand Down Expand Up @@ -3830,6 +3834,8 @@ pub const SIG = if (is_mips) enum(u32) {
pub const POLL: SIG = .IO;
pub const IOT: SIG = .ABRT;

/// Perform error checking without sending signal.
INVAL = 0,
HUP = 1,
INT = 2,
QUIT = 3,
Expand Down
9 changes: 9 additions & 0 deletions lib/std/posix/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -980,3 +980,12 @@ const CommonOpenFlags = packed struct {
return result;
}
};

test "kill 0 can be used to perform checks of sending signal" {
if (native_os == .wasi) return error.SkipZigTest;
if (native_os == .windows) return error.SkipZigTest;
posix.kill(posix.getpid(), .INVAL) catch |err| switch (err) {
posix.KillError.PermissionDenied => return,
else => return err,
};
}
Copy link
Member

@squeek502 squeek502 Nov 24, 2025

Choose a reason for hiding this comment

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

This should probably be moved into a standalone test. See https://github.com/ziglang/zig/tree/master/test/standalone/posix for a potential standalone test that it'd make sense to move it to.

(note: for the purposes of locally testing a standalone test, you can just do e.g. cd test/standalone/posix and zig build test)

Copy link
Contributor

Choose a reason for hiding this comment

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

Given its not really sending a signal (just testing if the existence/permissions are fine), I think its okay to keep here in the normal unit tests. But it is a bit of a grey area. (For everyone else: signals and signal handling can interfere with the Zig unit test framework, so some Posix test cases are over in test/standalone/posix/ if they need to be isolated.)

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see now that this is part of the POSIX spec:

If sig is 0 (the null signal), error checking is performed but no signal is actually sent. The null signal can be used to check the validity of pid.

https://pubs.opengroup.org/onlinepubs/9799919799/functions/kill.html

It still kinda seems like it might be better in a standalone test, though, just to ensure that if the system doesn't properly implement that part of the spec it doesn't have a chance of messing with the unit test runner.