aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-09-12 03:37:09 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-09-12 03:37:09 -0700
commita8e4722bd1cd1ee71615678b4f0a3d2a6297c3f1 (patch)
tree1498a2fb1b17b92a8ec2e76be7262f7f17fe5c5c
parent6dcdd2026a157e0ec622559c603b86ddd3103dbf (diff)
downloadbun-a8e4722bd1cd1ee71615678b4f0a3d2a6297c3f1.tar.gz
bun-a8e4722bd1cd1ee71615678b4f0a3d2a6297c3f1.tar.zst
bun-a8e4722bd1cd1ee71615678b4f0a3d2a6297c3f1.zip
Check that the pid matchesjarred/fix-issue-with-tsconfig-run
-rw-r--r--src/bun.js/api/bun/subprocess.zig69
-rw-r--r--src/install/install.zig10
2 files changed, 59 insertions, 20 deletions
diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig
index 50bd846ac..f44c5fb26 100644
--- a/src/bun.js/api/bun/subprocess.zig
+++ b/src/bun.js/api/bun/subprocess.zig
@@ -1462,25 +1462,54 @@ pub const Subprocess = struct {
const kernel = @import("../../../analytics.zig").GenerateHeader.GeneratePlatform.kernelVersion();
// pidfd_nonblock only supported in 5.10+
- const pidfd_flags: u32 = if (!is_sync and kernel.orderWithoutTag(.{ .major = 5, .minor = 10, .patch = 0 }).compare(.gte))
+ var pidfd_flags: u32 = if (!is_sync and kernel.orderWithoutTag(.{ .major = 5, .minor = 10, .patch = 0 }).compare(.gte))
std.os.O.NONBLOCK
else
0;
-
- const fd = std.os.linux.pidfd_open(
+ var fd: std.os.linux.fd_t = std.os.linux.pidfd_open(
pid,
pidfd_flags,
);
- switch (std.os.linux.getErrno(fd)) {
- .SUCCESS => break :brk @as(std.os.fd_t, @intCast(fd)),
- else => |err| {
- globalThis.throwValue(bun.sys.Error.fromCode(err, .open).toJSC(globalThis));
- var status: u32 = 0;
- // ensure we don't leak the child process on error
- _ = std.os.linux.waitpid(pid, &status, 0);
- return .zero;
- },
+ while (true) {
+ switch (std.os.linux.getErrno(fd)) {
+ .SUCCESS => break :brk @as(std.os.fd_t, @intCast(fd)),
+ .INTR => continue,
+ else => |err| {
+ if (err == .INVAL) {
+ if (pidfd_flags != 0) {
+ fd = std.os.linux.pidfd_open(
+ pid,
+ 0,
+ );
+ pidfd_flags = 0;
+ continue;
+ }
+ }
+
+ const error_instance = brk2: {
+ if (err == .NOSYS) {
+ break :brk2 globalThis.createErrorInstance(
+ \\"pidfd_open(2)" system call is not supported by your Linux kernel
+ \\To fix this error, either:
+ \\- Upgrade your Linux kernel to a newer version (current: {})
+ \\- Ensure the seccomp filter allows \"pidfd_open\"
+ ,
+ .{
+ kernel.fmt(""),
+ },
+ );
+ }
+
+ break :brk2 bun.sys.Error.fromCode(err, .open).toJSC(globalThis);
+ };
+ globalThis.throwValue(error_instance);
+ var status: u32 = 0;
+ // ensure we don't leak the child process on error
+ _ = std.os.linux.waitpid(pid, &status, 0);
+ return .zero;
+ },
+ }
}
};
@@ -1682,14 +1711,16 @@ pub const Subprocess = struct {
this.waitpid_err = err;
},
.result => |result| {
- if (std.os.W.IFEXITED(result.status)) {
- this.exit_code = @as(u8, @truncate(std.os.W.EXITSTATUS(result.status)));
- }
+ if (result.pid == pid) {
+ if (std.os.W.IFEXITED(result.status)) {
+ this.exit_code = @as(u8, @truncate(std.os.W.EXITSTATUS(result.status)));
+ }
- if (std.os.W.IFSIGNALED(result.status)) {
- this.signal_code = @as(SignalCode, @enumFromInt(@as(u8, @truncate(std.os.W.TERMSIG(result.status)))));
- } else if (std.os.W.IFSTOPPED(result.status)) {
- this.signal_code = @as(SignalCode, @enumFromInt(@as(u8, @truncate(std.os.W.STOPSIG(result.status)))));
+ if (std.os.W.IFSIGNALED(result.status)) {
+ this.signal_code = @as(SignalCode, @enumFromInt(@as(u8, @truncate(std.os.W.TERMSIG(result.status)))));
+ } else if (std.os.W.IFSTOPPED(result.status)) {
+ this.signal_code = @as(SignalCode, @enumFromInt(@as(u8, @truncate(std.os.W.STOPSIG(result.status)))));
+ }
}
if (!this.hasExited()) {
diff --git a/src/install/install.zig b/src/install/install.zig
index bf6422cc7..30bedef0a 100644
--- a/src/install/install.zig
+++ b/src/install/install.zig
@@ -1246,7 +1246,15 @@ const PackageInstall = struct {
std.os.mkdirat(destination_dir_.dir.fd, entry.path, 0o755) catch {};
},
.file => {
- try std.os.linkat(entry.dir.dir.fd, entry.basename, destination_dir_.dir.fd, entry.path, 0);
+ std.os.linkat(entry.dir.dir.fd, entry.basename, destination_dir_.dir.fd, entry.path, 0) catch |err| {
+ if (err != error.PathAlreadyExists) {
+ return err;
+ }
+
+ std.os.unlinkat(destination_dir_.dir.fd, entry.path, 0) catch {};
+ try std.os.linkat(entry.dir.dir.fd, entry.basename, destination_dir_.dir.fd, entry.path, 0);
+ };
+
real_file_count += 1;
},
else => {},