My function isn't running at all

This function used to be perfectly functional, however has completely stopped functioning whatsoever.

pub fn main() !void {
    const stdout = std.io.getStdOut().writer();
    const stdin = std.io.getStdIn().reader();
    var sa: std.posix.Sigaction = .{
        .handler = .{ .sigaction = usrSigHandler },
        .mask = std.posix.empty_sigset,
        .flags = std.posix.SA.RESTART,
    };
    std.posix.sigaction(std.posix.SIG.USR1, &sa, null);
    std.posix.sigaction(std.posix.SIG.USR2, &sa, null);
    //Trying to see if it was an issue with the sigaction
    usrSigHandler(12, &std.posix.siginfo_t{ // random-ass values
            .signo = 12,
            .code = 0,
            .errno = 0,
            .fields = .{
                .common = .{ 
                    .first =  .{   
                        .piduid = .{ 
                            .pid = 69,
                            .uid = 420
                        }
                    },
                    .second = .{ 
                        .sigchld = .{ 
                            .status = 0,
                            .stime = 1,
                            .utime = 1
                        }
                    }
                }
            }
            },
            [Random pointer here]
    );
    while (true) {
        ...
    }
}

fn usrSigHandler(sig: i32, info: *const std.posix.siginfo_t, _: ?*anyopaque) callconv(.C) void {
    //this shit aint running at all
    std.debug.print("Signal {d} recieved\n", .{sig});
    ...

The following code works on linux:

const std = @import("std");

fn usrHandler(sig: i32, info: *const std.posix.siginfo_t, _: ?*anyopaque) callconv(.C) void {
    const pid = info.fields.common.first.piduid.pid;
    std.debug.print("sig={d} pid={d}\n", .{ sig, pid });
}

pub fn main() !void {
    var sa: std.posix.Sigaction = .{
        .handler = .{ .sigaction = usrHandler },
        .mask = std.posix.empty_sigset,
        .flags = std.posix.SA.RESTART | std.posix.SA.SIGINFO,
    };
    try std.posix.sigaction(std.posix.SIG.USR1, &sa, null);
    try std.posix.sigaction(std.posix.SIG.USR2, &sa, null);

    const pid = std.os.linux.getpid();
    std.debug.print("my pid={d}\n", .{pid});

    while (true) {}
}

Flag std.posix.SA.SIGINFO was required to fill the extra function parameters.

To send a signal use kill -USR1 <my pid> replacing <my pid> with the displayed value.

1 Like