Trashed stack when using FreeBSD's Capsicum

Hello! I’m new to Zig and I want to test how easy it is to use C libraries. My first attempt was with FreeBSD’s Capsicum but unfortunately it didn’t end well. Here’s the simple program I wrote:

const std = @import("std");
const capsicum = @cImport({
    @cInclude("sys/capsicum.h");
});

pub fn main() !void {
    _ = capsicum.cap_enter();

    const file = try std.fs.openFileAbsolute("/var/log/debug.log", .{});
    defer file.close();
}

When I run zig build run I get:

unexpected errno: 94
...many times the above...
pid 59514 comm playground has trashed its stack, killing

Error number 94 is ENOTCAPABLE which is expected but the trashed stack is not.

Is there any mistake? Maybe I’m missing something when it comes to error handling.

What is it that cap_enter is returning that you’re ignoring?

Looks like something is recursing. I’m not familiar with capsicum, but looking it up, it seems to remove a bunch of privileges. It could be that the failure to open the file is triggering a signal handler, which tries to print an error message, but that is also failing, triggering the signal handler recursively until the stack overflows.
Stepping through the code in a debugger should clarify this.