aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred SUmner <jarred@jarredsumner.com> 2022-09-25 10:13:42 -0700
committerGravatar Jarred SUmner <jarred@jarredsumner.com> 2022-09-25 10:13:42 -0700
commit7ce4a4e3d3f5f06a1258eefc49ce1da166e43886 (patch)
tree54742267f23baf8363e455852c4310d8dfafc0fa
parentd2b81fa7c974159307c7dae86a1c9313e1cc2e05 (diff)
downloadbun-7ce4a4e3d3f5f06a1258eefc49ce1da166e43886.tar.gz
bun-7ce4a4e3d3f5f06a1258eefc49ce1da166e43886.tar.zst
bun-7ce4a4e3d3f5f06a1258eefc49ce1da166e43886.zip
Make Linux implementation work
-rw-r--r--src/bun.js/api/bun.zig4
-rw-r--r--src/bun.js/api/bun/spawn.zig31
-rw-r--r--src/linux_c.zig82
3 files changed, 86 insertions, 31 deletions
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig
index 58918b18b..d62b1e9b8 100644
--- a/src/bun.js/api/bun.zig
+++ b/src/bun.js/api/bun.zig
@@ -3921,7 +3921,7 @@ pub const Subprocess = struct {
break :brk @intCast(std.os.fd_t, pid);
}
- const kernel = @import("analytics").GenerateHeader.GeneratePlatform.kernelVersion();
+ const kernel = @import("../../analytics.zig").GenerateHeader.GeneratePlatform.kernelVersion();
// pidfd_nonblock only supported in 5.10+
const flags: u32 = if (kernel.orderWithoutTag(.{ .major = 5, .minor = 10, .patch = 0 }).compare(.gte))
@@ -3935,7 +3935,7 @@ pub const Subprocess = struct {
);
switch (std.os.linux.getErrno(fd)) {
- .SUCCESS => break :brk fd,
+ .SUCCESS => break :brk @intCast(std.os.fd_t, fd),
else => |err| {
globalThis.throwValue(JSC.Node.Syscall.Error.fromCode(err, .open).toJSC(globalThis));
var status: u32 = 0;
diff --git a/src/bun.js/api/bun/spawn.zig b/src/bun.js/api/bun/spawn.zig
index bbc5d4fac..58dac9e9f 100644
--- a/src/bun.js/api/bun/spawn.zig
+++ b/src/bun.js/api/bun/spawn.zig
@@ -2,7 +2,20 @@ const JSC = @import("javascript_core");
const bun = @import("../../../global.zig");
const string = bun.string;
const std = @import("std");
-const system = std.os.system;
+
+fn _getSystem() type {
+ if (comptime bun.Environment.isLinux) {
+ return struct {
+ pub usingnamespace std.os.system;
+ pub usingnamespace bun.C.linux;
+ };
+ }
+
+ return std.os.system;
+}
+
+const system = _getSystem();
+
const Maybe = JSC.Node.Maybe;
const fd_t = std.os.fd_t;
@@ -33,7 +46,13 @@ pub const PosixSpawn = struct {
}
pub fn deinit(self: *Attr) void {
- system.posix_spawnattr_destroy(&self.attr);
+ if (comptime bun.Environment.isMac) {
+ // https://github.com/ziglang/zig/issues/12964
+ system.posix_spawnattr_destroy(&self.attr);
+ } else {
+ _ = system.posix_spawnattr_destroy(&self.attr);
+ }
+
self.* = undefined;
}
@@ -69,7 +88,13 @@ pub const PosixSpawn = struct {
}
pub fn deinit(self: *Actions) void {
- system.posix_spawn_file_actions_destroy(&self.actions);
+ if (comptime bun.Environment.isMac) {
+ // https://github.com/ziglang/zig/issues/12964
+ system.posix_spawn_file_actions_destroy(&self.actions);
+ } else {
+ _ = system.posix_spawn_file_actions_destroy(&self.actions);
+ }
+
self.* = undefined;
}
diff --git a/src/linux_c.zig b/src/linux_c.zig
index 5a3acad9f..04a2a508c 100644
--- a/src/linux_c.zig
+++ b/src/linux_c.zig
@@ -388,33 +388,31 @@ pub const POSIX_SPAWN = struct {
pub const SETSID = 0x80;
};
-pub const posix_spawnattr_t = *opaque {};
-pub const posix_spawn_file_actions_t = *opaque {};
-pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int;
-pub extern "c" fn posix_spawnattr_destroy(attr: *posix_spawnattr_t) void;
-pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: c_short) c_int;
-pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *c_short) c_int;
-pub extern "c" fn posix_spawn_file_actions_init(actions: *posix_spawn_file_actions_t) c_int;
-pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) void;
-pub extern "c" fn posix_spawn_file_actions_addclose(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
-pub extern "c" fn posix_spawn_file_actions_addopen(
- actions: *posix_spawn_file_actions_t,
- filedes: fd_t,
- path: [*:0]const u8,
- oflag: c_int,
- mode: mode_t,
-) c_int;
-pub extern "c" fn posix_spawn_file_actions_adddup2(
- actions: *posix_spawn_file_actions_t,
- filedes: fd_t,
- newfiledes: fd_t,
-) c_int;
-pub extern "c" fn posix_spawn_file_actions_addfchdir_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
+const fd_t = std.os.fd_t;
+const pid_t = std.os.pid_t;
+const mode_t = std.os.mode_t;
+const sigset_t = std.c.sigset_t;
+const sched_param = std.os.sched_param;
-// not available in linux
-// pub extern "c" fn posix_spawn_file_actions_addinherit_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
-
-pub extern "c" fn posix_spawn_file_actions_addchdir_np(actions: *posix_spawn_file_actions_t, path: [*:0]const u8) c_int;
+pub const posix_spawnattr_t = extern struct {
+ __flags: c_short,
+ __pgrp: pid_t,
+ __sd: sigset_t,
+ __ss: sigset_t,
+ __sp: struct_sched_param,
+ __policy: c_int,
+ __pad: [16]c_int,
+};
+pub const struct_sched_param = extern struct {
+ sched_priority: c_int,
+};
+pub const struct___spawn_action = opaque {};
+pub const posix_spawn_file_actions_t = extern struct {
+ __allocated: c_int,
+ __used: c_int,
+ __actions: ?*struct___spawn_action,
+ __pad: [16]c_int,
+};
pub extern "c" fn posix_spawn(
pid: *pid_t,
@@ -432,3 +430,35 @@ pub extern "c" fn posix_spawnp(
argv: [*:null]?[*:0]const u8,
env: [*:null]?[*:0]const u8,
) c_int;
+pub extern fn posix_spawnattr_init(__attr: *posix_spawnattr_t) c_int;
+pub extern fn posix_spawnattr_destroy(__attr: *posix_spawnattr_t) c_int;
+pub extern fn posix_spawnattr_getsigdefault(noalias __attr: [*c]const posix_spawnattr_t, noalias __sigdefault: [*c]sigset_t) c_int;
+pub extern fn posix_spawnattr_setsigdefault(noalias __attr: [*c]posix_spawnattr_t, noalias __sigdefault: [*c]const sigset_t) c_int;
+pub extern fn posix_spawnattr_getsigmask(noalias __attr: [*c]const posix_spawnattr_t, noalias __sigmask: [*c]sigset_t) c_int;
+pub extern fn posix_spawnattr_setsigmask(noalias __attr: [*c]posix_spawnattr_t, noalias __sigmask: [*c]const sigset_t) c_int;
+pub extern fn posix_spawnattr_getflags(noalias __attr: [*c]const posix_spawnattr_t, noalias __flags: [*c]c_short) c_int;
+pub extern fn posix_spawnattr_setflags(_attr: [*c]posix_spawnattr_t, __flags: c_short) c_int;
+pub extern fn posix_spawnattr_getpgroup(noalias __attr: [*c]const posix_spawnattr_t, noalias __pgroup: [*c]pid_t) c_int;
+pub extern fn posix_spawnattr_setpgroup(__attr: [*c]posix_spawnattr_t, __pgroup: pid_t) c_int;
+pub extern fn posix_spawnattr_getschedpolicy(noalias __attr: [*c]const posix_spawnattr_t, noalias __schedpolicy: [*c]c_int) c_int;
+pub extern fn posix_spawnattr_setschedpolicy(__attr: [*c]posix_spawnattr_t, __schedpolicy: c_int) c_int;
+pub extern fn posix_spawnattr_getschedparam(noalias __attr: [*c]const posix_spawnattr_t, noalias __schedparam: [*c]struct_sched_param) c_int;
+pub extern fn posix_spawnattr_setschedparam(noalias __attr: [*c]posix_spawnattr_t, noalias __schedparam: [*c]const struct_sched_param) c_int;
+pub extern fn posix_spawn_file_actions_init(__file_actions: *posix_spawn_file_actions_t) c_int;
+pub extern fn posix_spawn_file_actions_destroy(__file_actions: *posix_spawn_file_actions_t) c_int;
+pub extern fn posix_spawn_file_actions_addopen(noalias __file_actions: *posix_spawn_file_actions_t, __fd: c_int, noalias __path: [*:0]const u8, __oflag: c_int, __mode: mode_t) c_int;
+pub extern fn posix_spawn_file_actions_addclose(__file_actions: *posix_spawn_file_actions_t, __fd: c_int) c_int;
+pub extern fn posix_spawn_file_actions_adddup2(__file_actions: *posix_spawn_file_actions_t, __fd: c_int, __newfd: c_int) c_int;
+pub const POSIX_SPAWN_RESETIDS = @as(c_int, 0x01);
+pub const POSIX_SPAWN_SETPGROUP = @as(c_int, 0x02);
+pub const POSIX_SPAWN_SETSIGDEF = @as(c_int, 0x04);
+pub const POSIX_SPAWN_SETSIGMASK = @as(c_int, 0x08);
+pub const POSIX_SPAWN_SETSCHEDPARAM = @as(c_int, 0x10);
+pub const POSIX_SPAWN_SETSCHEDULER = @as(c_int, 0x20);
+
+pub extern "c" fn posix_spawn_file_actions_addfchdir_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
+
+// not available in linux
+// pub extern "c" fn posix_spawn_file_actions_addinherit_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
+
+pub extern "c" fn posix_spawn_file_actions_addchdir_np(actions: *posix_spawn_file_actions_t, path: [*:0]const u8) c_int;