summaryrefslogtreecommitdiff
path: root/src/linux
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 17:35:06 -0300
committerGabriel Schneider <[email protected]>2026-10-30 17:35:06 -0300
commit6d8da8721141284cf33bb901168b26135893eb86 (patch)
tree791d63401d4e85fbca1d597a8ce0326e70efd545 /src/linux
parentefd43a3a2cf03bb741366331158b368abf9ac583 (diff)
parentbf6810a8f9d6cc82050e7d9c0cfb06358301b574 (diff)
downloadpardes-6d8da8721141284cf33bb901168b26135893eb86.tar.gz
pardes-6d8da8721141284cf33bb901168b26135893eb86.zip
Merge latest upstream into the macOS branch for Zig 0.17
Retain the macOS branch history and local Acme selection color while adopting upstream's current core and platform changes. Pin Zig and ZLS to 0.17.0, and fetch the existing zstbi compatibility commit through upstream after its original fork was removed.
Diffstat (limited to 'src/linux')
-rw-r--r--src/linux/v9fs.zig50
1 files changed, 25 insertions, 25 deletions
diff --git a/src/linux/v9fs.zig b/src/linux/v9fs.zig
index 4e18660d..47be298b 100644
--- a/src/linux/v9fs.zig
+++ b/src/linux/v9fs.zig
@@ -5,23 +5,13 @@ const builtin = @import("builtin");
extern "c" fn unshare(flags: c_int) c_int;
extern "c" fn mount(source: ?[*:0]const u8, target: [*:0]const u8, filesystemtype: ?[*:0]const u8, flags: c_ulong, data: ?*const anyopaque) c_int;
-extern "c" fn getuid() c_uint;
-extern "c" fn geteuid() c_uint;
extern "c" fn setgroups(size: usize, list: ?[*]const c_uint) c_int;
extern "c" fn initgroups(user: [*:0]const u8, group: c_uint) c_int;
-extern "c" fn setresgid(real: c_uint, effective: c_uint, saved: c_uint) c_int;
-extern "c" fn setresuid(real: c_uint, effective: c_uint, saved: c_uint) c_int;
extern "c" fn execv(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int;
extern "c" fn execvp(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int;
-extern "c" fn readlink(path: [*:0]const u8, buf: [*]u8, size: usize) isize;
extern "c" fn mkdtemp(template: [*:0]u8) ?[*:0]u8;
-extern "c" fn rmdir(path: [*:0]const u8) c_int;
extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int;
extern "c" fn unsetenv(name: [*:0]const u8) c_int;
-extern "c" fn fork() c_int;
-extern "c" fn waitpid(pid: c_int, status: *c_int, flags: c_int) c_int;
-extern "c" fn kill(pid: c_int, sig: c_int) c_int;
-extern "c" fn _exit(status: c_int) noreturn;
pub const executable = "pardes-v9fs";
@@ -51,7 +41,7 @@ fn quote(writer: *std.Io.Writer, value: []const u8) !void {
}
fn selfPath(buf: []u8) ![:0]u8 {
- const n = readlink("/proc/self/exe", buf.ptr, buf.len - 1);
+ const n = std.c.readlink("/proc/self/exe", buf.ptr, buf.len - 1);
if (n < 0 or n >= buf.len - 1) return error.ExecutablePathUnavailable;
const len: usize = @intCast(n);
buf[len] = 0;
@@ -64,11 +54,11 @@ pub fn helperPath(buf: []u8) ![:0]u8 {
const path = if (std.c.getenv("PARDES_V9FS_HELPER")) |env| blk: {
const override = std.mem.span(env);
if (!std.fs.path.isAbsolute(override)) return error.AbsoluteHelperPathRequired;
- break :blk try std.fmt.bufPrintZ(buf, "{s}", .{override});
+ break :blk try std.fmt.bufPrintSentinel(buf, "{s}", .{override}, 0);
} else blk: {
var own: [4096]u8 = undefined;
const parent = std.fs.path.dirname(try selfPath(&own)) orelse return error.ExecutablePathUnavailable;
- break :blk try std.fmt.bufPrintZ(buf, "{s}/{s}", .{ parent, executable });
+ break :blk try std.fmt.bufPrintSentinel(buf, "{s}/{s}", .{ parent, executable }, 0);
};
if (std.c.access(path.ptr, 1) != 0) return error.V9fsHelperNotFound;
return path;
@@ -85,22 +75,22 @@ fn usage() void {
, .{});
}
-var sudo_pid: std.atomic.Value(c_int) = .init(-1);
+var sudo_pid: std.atomic.Value(std.c.pid_t) = .init(-1);
fn forwardSignal(sig: std.posix.SIG) callconv(.c) void {
const pid = sudo_pid.load(.monotonic);
- if (pid > 0) _ = kill(pid, @intCast(@intFromEnum(sig)));
+ if (pid > 0) _ = std.c.kill(pid, sig);
}
fn launch(arena: std.mem.Allocator, args: []const [:0]const u8) !u8 {
if (args.len < 5 or !std.mem.eql(u8, args[3], "--")) return error.InvalidArguments;
- if (geteuid() == 0 or getuid() != geteuid()) return error.UnprivilegedLaunchRequired;
+ if (std.c.geteuid() == 0 or std.c.getuid() != std.c.geteuid()) return error.UnprivilegedLaunchRequired;
if (!std.fs.path.isAbsolute(args[2]) or !std.fs.path.isAbsolute(args[4])) return error.AbsolutePathRequired;
var own: [4096]u8 = undefined;
const helper = try selfPath(&own);
var target = "/tmp/pardes-v9fs-XXXXXX".*;
if (mkdtemp(&target) == null) return error.MountDirectoryFailed;
- defer _ = rmdir(&target);
+ defer _ = std.c.rmdir(&target);
try check(setenv("PARDES_MOUNT", &target, 1), "export mount path");
inline for (.{ "PATH", "HOME", "USER", "LOGNAME", "SHELL" }) |name| {
const saved = "PARDES_V9FS_" ++ name;
@@ -108,24 +98,34 @@ fn launch(arena: std.mem.Allocator, args: []const [:0]const u8) !u8 {
try check(setenv(saved, value, 1), "preserve shell environment");
} else _ = unsetenv(saved);
}
- const uid = try std.fmt.allocPrintSentinel(arena, "{d}", .{getuid()}, 0);
+ const uid = try std.fmt.allocPrintSentinel(arena, "{d}", .{std.c.getuid()}, 0);
const gid = try std.fmt.allocPrintSentinel(arena, "{d}", .{std.c.getgid()}, 0);
const prefix = [_]?[*:0]const u8{ "sudo", "-E", "--", helper.ptr, args[2].ptr, &target, uid.ptr, gid.ptr, "--" };
const argv = try arena.allocSentinel(?[*:0]const u8, prefix.len + args.len - 4, null);
@memcpy(argv[0..prefix.len], &prefix);
for (args[4..], prefix.len..) |arg, i| argv[i] = arg.ptr;
std.debug.print("Mounting Pardes at {s}\n", .{target});
- const pid = fork();
+ const pid = std.c.fork();
if (pid < 0) return error.ForkFailed;
if (pid == 0) {
+ // host_io's resetChildSignals, here in its own module: every signal
+ // back to its default and none blocked before the exec.
+ const default: std.posix.Sigaction = .{ .handler = .{ .handler = std.posix.SIG.DFL }, .mask = std.posix.sigemptyset(), .flags = 0 };
+ var sig: u8 = 1;
+ while (sig < 65) : (sig += 1) {
+ if (sig == @backingInt(std.posix.SIG.KILL) or sig == @backingInt(std.posix.SIG.STOP)) continue;
+ _ = std.c.sigaction(@fromBackingInt(@intCast(sig)), &default, null);
+ }
+ const none = std.posix.sigemptyset();
+ std.posix.sigprocmask(std.posix.SIG.SETMASK, &none, null);
_ = execvp("sudo", argv.ptr);
- _exit(127);
+ std.c._exit(127);
}
sudo_pid.store(pid, .monotonic);
const action: std.posix.Sigaction = .{ .handler = .{ .handler = forwardSignal }, .mask = std.posix.sigemptyset(), .flags = 0 };
for ([_]std.posix.SIG{ .HUP, .INT, .TERM }) |sig| std.posix.sigaction(sig, &action, null);
var status: c_int = 0;
- while (waitpid(pid, &status, 0) < 0) {
+ while (std.c.waitpid(pid, &status, 0) < 0) {
if (std.posix.errno(-1) != .INTR) return error.WaitFailed;
}
sudo_pid.store(-1, .monotonic);
@@ -166,8 +166,8 @@ pub fn main(init: std.process.Init) !void {
}
const uid = try userId(args[3]);
const gid = try userId(args[4]);
- if (getuid() != geteuid()) return error.SetuidInstallationUnsupported;
- if (geteuid() != 0) {
+ if (std.c.getuid() != std.c.geteuid()) return error.SetuidInstallationUnsupported;
+ if (std.c.geteuid() != 0) {
std.debug.print("v9fs: native 9P mounts need CAP_SYS_ADMIN in the initial user namespace; use --launch to ask sudo in this terminal.\n", .{});
return error.MountPrivilegeRequired;
}
@@ -184,8 +184,8 @@ pub fn main(init: std.process.Init) !void {
try check(setgroups(0, null), "clear supplementary groups");
const account = std.c.getpwuid(uid) orelse return error.UserAccountNotFound;
try check(initgroups(account.name orelse return error.UserAccountNotFound, gid), "restore user groups");
- try check(setresgid(gid, gid, gid), "drop group privileges");
- try check(setresuid(uid, uid, uid), "drop user privileges");
+ try check(std.c.setresgid(gid, gid, gid), "drop group privileges");
+ try check(std.c.setresuid(uid, uid, uid), "drop user privileges");
// sudo can replace identity variables and PATH even with -E. Restore
// those values only after dropping privileges.
inline for (.{ "PATH", "HOME", "USER", "LOGNAME", "SHELL" }) |name| {