diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-21 14:38:16 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-21 14:44:48 -0300 |
| commit | d5c37d9122240fe95d308fbe15874e14dd786c5a (patch) | |
| tree | 3ed108d2af5bd7a5cb07491b16e855e5243b5d63 /9ns/src/ns.zig | |
| parent | fe9772b178575fcab93de09fc61c2f13db7db1a8 (diff) | |
| download | cloud9-d5c37d9122240fe95d308fbe15874e14dd786c5a.tar.gz cloud9-d5c37d9122240fe95d308fbe15874e14dd786c5a.zip | |
Build with Zig 0.17
Diffstat (limited to '9ns/src/ns.zig')
| -rw-r--r-- | 9ns/src/ns.zig | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/9ns/src/ns.zig b/9ns/src/ns.zig index db41eda..f7549ef 100644 --- a/9ns/src/ns.zig +++ b/9ns/src/ns.zig @@ -135,7 +135,7 @@ pub fn pathCandidates(gpa: Allocator, envp: [*:null]const ?[*:0]const u8, name: list.deinit(gpa); } if (std.mem.indexOfScalar(u8, name, '/') != null) { - try list.append(gpa, try gpa.dupeZ(u8, name)); + try list.append(gpa, try gpa.dupeSentinel(u8, name, 0)); return list.toOwnedSlice(gpa); } const path = getenv(envp, "PATH") orelse default_path; @@ -162,7 +162,7 @@ pub fn findInPath(gpa: Allocator, envp: [*:null]const ?[*:0]const u8, name: []co if (linux.errno(rc) != .SUCCESS) continue; if (stx.mode & linux.S.IFMT != linux.S.IFREG) continue; if (stx.mode & 0o111 == 0) continue; - return gpa.dupeZ(u8, c); + return gpa.dupeSentinel(u8, c, 0); } return error.FileNotFound; } @@ -208,7 +208,7 @@ fn freeEnvp(gpa: Allocator, envp: [:null]?[*:0]const u8) void { fn buildArgv(gpa: Allocator, argv: []const []const u8) ![:null]?[*:0]const u8 { const out = try gpa.allocSentinel(?[*:0]const u8, argv.len, null); - for (argv, 0..) |a, i| out[i] = (try gpa.dupeZ(u8, a)).ptr; + for (argv, 0..) |a, i| out[i] = (try gpa.dupeSentinel(u8, a, 0)).ptr; return out; } @@ -246,7 +246,7 @@ pub fn ensureMountpoint(gpa: Allocator, path: [:0]const u8) !void { while (true) { base = std.fs.path.dirname(base) orelse "/"; var base_buf: [path_max]u8 = undefined; - const base_z = std.fmt.bufPrintZ(&base_buf, "{s}", .{base}) catch { + const base_z = std.fmt.bufPrintSentinel(&base_buf, "{s}", .{base}, 0) catch { std.debug.print("9ns: mountpoint {s}: path too long\n", .{path}); return error.Mountpoint; }; @@ -278,7 +278,7 @@ pub fn ensureMountpoint(gpa: Allocator, path: [:0]const u8) !void { std.debug.print("9ns: mkdir {s}: E{t}; refusing to shadow {s} (pass --mount an existing directory)\n", .{ path, mk, base }); return error.Mountpoint; } - const base_z = try gpa.dupeZ(u8, base); + const base_z = try gpa.dupeSentinel(u8, base, 0); defer gpa.free(base_z); try shadowDirectory(gpa, base_z); switch (mkdirComponents(path, base.len, missing)) { @@ -311,7 +311,7 @@ fn mkdirComponents(path: []const u8, base_len: usize, missing: []const u8) E { var it = std.mem.tokenizeScalar(u8, missing, '/'); while (it.next()) |comp| { end += 1 + comp.len; - const prefix = std.fmt.bufPrintZ(&buf, "{s}", .{path[0..end]}) catch return .NAMETOOLONG; + const prefix = std.fmt.bufPrintSentinel(&buf, "{s}", .{path[0..end]}, 0) catch return .NAMETOOLONG; switch (linux.errno(linux.mkdirat(linux.AT.FDCWD, prefix, 0o755))) { .SUCCESS, .EXIST => {}, else => |e| return e, @@ -326,7 +326,7 @@ const FileType = enum { dir, symlink, other }; /// such as /proc/self/root) to the same inode. fn isSameDirectory(a: []const u8, b: [*:0]const u8) bool { var a_buf: [path_max]u8 = undefined; - const a_z = std.fmt.bufPrintZ(&a_buf, "{s}", .{a}) catch return false; + const a_z = std.fmt.bufPrintSentinel(&a_buf, "{s}", .{a}, 0) catch return false; var sa: linux.Statx = undefined; var sb: linux.Statx = undefined; if (linux.errno(linux.statx(linux.AT.FDCWD, a_z, 0, .{ .INO = true }, &sa)) != .SUCCESS) return false; @@ -384,7 +384,7 @@ fn listDir(gpa: Allocator, fd: i32, dirpath: []const u8) ![]Entry { linux.DT.UNKNOWN => fileType(fd, name_ptr, true) orelse .other, else => .other, }; - try list.append(gpa, .{ .name = try gpa.dupeZ(u8, name), .kind = kind }); + try list.append(gpa, .{ .name = try gpa.dupeSentinel(u8, name, 0), .kind = kind }); } } return list.toOwnedSlice(gpa); @@ -423,11 +423,11 @@ fn shadowDirectory(gpa: Allocator, parent: [:0]const u8) !void { var dst_buf: [path_max]u8 = undefined; var link_buf: [path_max]u8 = undefined; for (entries) |e| { - const src = std.fmt.bufPrintZ(&src_buf, "/proc/self/fd/{d}/{s}", .{ pfd, e.name }) catch { + const src = std.fmt.bufPrintSentinel(&src_buf, "/proc/self/fd/{d}/{s}", .{ pfd, e.name }, 0) catch { std.debug.print("9ns: shadow {s}/{s}: name too long (skipped)\n", .{ parent, e.name }); continue; }; - const dst = std.fmt.bufPrintZ(&dst_buf, "{s}/{s}", .{ parent, e.name }) catch { + const dst = std.fmt.bufPrintSentinel(&dst_buf, "{s}/{s}", .{ parent, e.name }, 0) catch { std.debug.print("9ns: shadow {s}/{s}: name too long (skipped)\n", .{ parent, e.name }); continue; }; @@ -509,7 +509,7 @@ pub fn spawn(gpa: Allocator, s: Spawn) !Child { return error.EmptyProgramName; } - const mountpoint = try gpa.dupeZ(u8, s.mountpoint); + const mountpoint = try gpa.dupeSentinel(u8, s.mountpoint, 0); defer gpa.free(mountpoint); const fuse_opts_prefix = try std.fmt.allocPrintSentinel(gpa, "rootmode=40000,user_id={d},group_id={d},max_read={d}", .{ s.uid, s.gid, s.max_read }, 0); defer gpa.free(fuse_opts_prefix); @@ -742,7 +742,7 @@ fn childMain(c: *const ChildArgs) noreturn { } const fd: i32 = @intCast(rc_open); var opts_buf: [256]u8 = undefined; - const opts = std.fmt.bufPrintZ(&opts_buf, "fd={d},{s}", .{ fd, c.fuse_opts_prefix }) catch unreachable; + const opts = std.fmt.bufPrintSentinel(&opts_buf, "fd={d},{s}", .{ fd, c.fuse_opts_prefix }, 0) catch unreachable; const rc = linux.mount("9ns", c.mountpoint, "fuse", linux.MS.NOSUID | linux.MS.NODEV, @intFromPtr(opts.ptr)); if (linux.errno(rc) != .SUCCESS) childFail(c, setup_failure_status, "mount fuse", linux.errno(rc), true); fuse_fd = fd; @@ -860,7 +860,7 @@ fn armWatchdog() void { .it_interval = .{ .sec = 0, .nsec = 0 }, .it_value = .{ .sec = exit_grace_seconds, .nsec = 0 }, }; - _ = linux.setitimer(@intFromEnum(linux.ITIMER.REAL), &t, null); + _ = linux.setitimer(@backingInt(linux.ITIMER.REAL), &t, null); } fn onAlarm(_: linux.SIG) callconv(.c) void { @@ -888,14 +888,14 @@ fn onChld(_: linux.SIG) callconv(.c) void { const srv = server_pid.load(.seq_cst); if (srv > 0) { var sst: u32 = 0; - const src = linux.waitpid(srv, &sst, linux.W.NOHANG); + const src = linux.waitpid(srv, @ptrCast(&sst), linux.W.NOHANG); if (linux.errno(src) == .SUCCESS and src != 0) server_pid.store(0, .seq_cst); } const p = child_pid_ptr orelse return; const pid = @atomicLoad(i32, p, .seq_cst); if (pid <= 0) return; var st: u32 = 0; - const rc = linux.waitpid(pid, &st, linux.W.NOHANG); + const rc = linux.waitpid(pid, @ptrCast(&st), linux.W.NOHANG); if (linux.errno(rc) != .SUCCESS or rc == 0) return; reaped_status.store(st, .release); reaped.store(true, .release); @@ -960,7 +960,7 @@ fn takeReaped() ?u32 { /// waitpid status → exit code (`128+sig` when killed by a signal). pub fn decodeStatus(st: u32) u8 { if (linux.W.IFEXITED(st)) return linux.W.EXITSTATUS(st); - if (linux.W.IFSIGNALED(st)) return 128 +% @as(u8, @truncate(@intFromEnum(linux.W.TERMSIG(st)))); + if (linux.W.IFSIGNALED(st)) return 128 +% @as(u8, @truncate(@backingInt(linux.W.TERMSIG(st)))); return 1; } @@ -969,7 +969,7 @@ pub fn waitChild(pid: i32) !u8 { while (true) { if (takeReaped()) |st| return decodeStatus(st); var st: u32 = 0; - const rc = linux.waitpid(pid, &st, 0); + const rc = linux.waitpid(pid, @ptrCast(&st), 0); switch (linux.errno(rc)) { .SUCCESS => return decodeStatus(st), .INTR => continue, @@ -989,7 +989,7 @@ pub fn waitChild(pid: i32) !u8 { pub fn reapIfExited(pid: i32) ?u8 { if (takeReaped()) |st| return decodeStatus(st); var st: u32 = 0; - const rc = linux.waitpid(pid, &st, linux.W.NOHANG); + const rc = linux.waitpid(pid, @ptrCast(&st), linux.W.NOHANG); switch (linux.errno(rc)) { .SUCCESS => return if (rc == 0) null else decodeStatus(st), .CHILD => return if (takeReaped()) |s| decodeStatus(s) else null, @@ -1000,7 +1000,7 @@ pub fn reapIfExited(pid: i32) ?u8 { /// Reap any child (used for the `--spawn` server at exit). Non-blocking. pub fn reapAny(pid: i32) void { var st: u32 = 0; - _ = linux.waitpid(pid, &st, linux.W.NOHANG); + _ = linux.waitpid(pid, @ptrCast(&st), linux.W.NOHANG); } // --------------------------------------------------------------------------- |
