diff options
| -rw-r--r-- | src/builtins_json.zig | 4 | ||||
| -rw-r--r-- | src/config.zig | 5 | ||||
| -rw-r--r-- | src/fs.zig | 3 | ||||
| -rw-r--r-- | src/ninep/ctl.zig | 15 | ||||
| -rw-r--r-- | test/daemon.py | 19 | ||||
| -rw-r--r-- | test/fs.py | 40 | ||||
| -rw-r--r-- | test/kitty.zig | 4 |
7 files changed, 63 insertions, 27 deletions
diff --git a/src/builtins_json.zig b/src/builtins_json.zig index 4440130d..3598a3e2 100644 --- a/src/builtins_json.zig +++ b/src/builtins_json.zig @@ -66,7 +66,9 @@ pub fn write(w: *std.Io.Writer) !void { } test "docs/typ/builtins-<platform>.json is what the registry says now" { - // a terminal build checks its file, a window build its own + // a terminal build checks its file, a window build its own; both are + // Linux builds' lists (Tty9p is Linux's) + if (comptime @import("builtin").os.tag != .linux) return error.SkipZigTest; const file = switch (pardes.platform) { .tty => "builtins-tty.json", .gui => "builtins-gui.json", diff --git a/src/config.zig b/src/config.zig index 66b11c72..f0023193 100644 --- a/src/config.zig +++ b/src/config.zig @@ -2277,7 +2277,10 @@ const doc_typ = struct { for (std.enums.values(Builtin)) |b| if (leader_path.get(b)) |p| if (std.mem.eql(u8, p, path[0..n])) return true; for (leader_args) |la| if (std.mem.eql(u8, la.path, path[0..n])) return true; - return false; + // A word this build leaves out (Tty9p off Linux) keeps its leader in the other's. + var buf: [96]u8 = undefined; + const needle = std.fmt.bufPrint(&buf, "\"leader\": \"{s}\"", .{k}) catch return false; + return std.mem.indexOf(u8, other_build, needle) != null; } toks.reset(); while (toks.next()) |t| if (!bound(chord(t) orelse return false)) return false; @@ -708,7 +708,8 @@ pub fn deniedAbove(dir: []const u8) bool { } test "a directory under one that may not be searched or written is denied, one merely missing is not" { - try std.testing.expect(deniedAbove("/proc/1/root/x/y")); + // The refusing directory is Linux's /proc/1/root. + if (comptime @import("builtin").os.tag == .linux) try std.testing.expect(deniedAbove("/proc/1/root/x/y")); try std.testing.expect(!deniedAbove("/tmp/pardes-surely-missing-dir/a/b")); } diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 9cb96667..3176ebc8 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -4676,8 +4676,8 @@ test "pager answers its +Pager on the open that asked, whatever another client e try testing.expectEqualStrings("/tmp/+Pager", second_pane.file.?.path); try testing.expect(p.paneBySerial(paged) != null); _ = call(p, .{ .tag = 14, .op = .release, .node = pager, .handle = resolved, .opened = true }); - // One that may not be written is refused, permission denied. - try testing.expectEqual(E.PERM, wr(p, pager, "/proc/1\n").errno()); + // One that may not be written is refused, permission denied (Linux's /proc/1). + if (comptime @import("builtin").os.tag == .linux) try testing.expectEqual(E.PERM, wr(p, pager, "/proc/1\n").errno()); // One directory a write, absolute, and there. try testing.expectEqual(E.INVAL, wr(p, pager, "/a\n/b\n").errno()); // One directory an open: one refused is not followed by another, as a @@ -4786,8 +4786,11 @@ test "a command pane an exec open was answered is leased to it while it stays op test "a Save whose directory is missing because one above refuses says permission denied, not no such directory" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); - p.saveFailed(0, "/proc/1/root/x/f.txt", error.FileNotFound); - try testing.expect(th.logHas(p, "Save /proc/1/root/x/f.txt: permission denied")); + // The refusing directory is Linux's /proc/1/root. + if (comptime @import("builtin").os.tag == .linux) { + p.saveFailed(0, "/proc/1/root/x/f.txt", error.FileNotFound); + try testing.expect(th.logHas(p, "Save /proc/1/root/x/f.txt: permission denied")); + } p.saveFailed(0, "/tmp/pardes-surely-missing-dir/f.txt", error.FileNotFound); try testing.expect(th.logHas(p, "no such directory")); } @@ -5036,8 +5039,10 @@ test "DumpDir refuses a relative directory and one that may not be written, up f defer p.deinit(); const root_ctl = @backingInt(tree.TopFile.ctl); try testing.expectEqual(E.INVAL, wr(p, root_ctl, "DumpDir dumps\n").errno()); - try testing.expectEqual(E.INVAL, wr(p, root_ctl, "DumpDir /proc/1/root/dumps\n").errno()); try testing.expectEqual(Status.ok, wr(p, root_ctl, "DumpDir /tmp/pardes-dumps-test\n").reply.status); + // The refusing directory is Linux's /proc/1/root. + if (comptime @import("builtin").os.tag != .linux) return; + try testing.expectEqual(E.INVAL, wr(p, root_ctl, "DumpDir /proc/1/root/dumps\n").errno()); p.fs.late_failure_len = 0; p.dumpFailed("/proc/1/root/x/pardes.dump.zon", error.FileNotFound); try testing.expect(std.mem.endsWith(u8, p.fs.late_failure[0..p.fs.late_failure_len], ": permission denied")); diff --git a/test/daemon.py b/test/daemon.py index bf3d237c..f4f46286 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -94,10 +94,21 @@ def run(client, serial, line): client.close(fid) +# FreeBSD has no /proc: ps and procstat answer instead. +procfs = os.path.isdir('/proc/self') + + +def ps(*args): + return subprocess.run(['ps', *args], capture_output=True).stdout + + def processes(root): """The pids whose environment is this run's (its runtime directory).""" found = [] mark = f'XDG_RUNTIME_DIR={root}'.encode() + if not procfs: # ps -e prints each environment before its command + return [int(row.split()[0]) for row in ps('-axeww', '-o', 'pid=', '-o', 'command=').splitlines() + if mark in row.split()] for entry in os.listdir('/proc'): if not entry.isdigit(): continue @@ -111,6 +122,8 @@ def processes(root): def cmdline(pid): + if not procfs: + return ps('-ww', '-o', 'args=', '-p', str(pid)).split() try: return open(f'/proc/{pid}/cmdline', 'rb').read().split(b'\0') except OSError: @@ -122,6 +135,8 @@ def alive(pid): os.kill(pid, 0) except ProcessLookupError: return False + if not procfs: + return not ps('-o', 'state=', '-p', str(pid)).startswith(b'Z') try: state = open(f'/proc/{pid}/stat').read().rsplit(')', 1)[1].split()[0] except OSError: @@ -130,6 +145,8 @@ def alive(pid): def fds(pid): + if not procfs: + return len(subprocess.run(['procstat', '-f', str(pid)], capture_output=True).stdout.splitlines()) - 1 try: return len(os.listdir(f'/proc/{pid}/fd')) except OSError: @@ -146,7 +163,7 @@ def main(binary, cycles): root = Path(tempfile.mkdtemp(prefix='rt-', dir=scratch)) env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), - TERM='xterm-256color', SHELL='/bin/bash', PARDES_NOTIME='1') + TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1') (root / 'config' / 'pardes').mkdir(parents=True) (root / 'config' / 'pardes' / 'init').write_text('Shell bash\nMessageLinger 0\n') daemon_sock = root / 'pardes-daemon.sock' @@ -520,7 +520,7 @@ def run_file(binary): client.remove(f'/pane/{pager[0]}') # systemd's tools page through their own variable: set too, its # secure mode off, the path unquoted where it needs none. - systemd_pager = run(client, term, b'printenv SYSTEMD_PAGER SYSTEMD_PAGERSECURE\n') + systemd_pager = run(client, term, b'printenv SYSTEMD_PAGER; printenv SYSTEMD_PAGERSECURE\n') assert systemd_pager.startswith(b'exit 0\n') and systemd_pager.rstrip().endswith(b' -\n0'), systemd_pager if shutil.which('journalctl'): assert run(client, term, b'journalctl -n 3 --no-hostname\n').startswith(b'exit ') @@ -551,8 +551,9 @@ def run_file(binary): time.sleep(.05) locked.chmod(0o600) try: - client.write(f'/pane/{term}/pty/ctl', b'exec\n') - raise AssertionError('pty/ctl exec of a shell that cannot start was taken') + if os.geteuid() != 0: # root enters any directory + client.write(f'/pane/{term}/pty/ctl', b'exec\n') + raise AssertionError('pty/ctl exec of a shell that cannot start was taken') except OSError as refused: assert 'shell' in str(refused), refused finally: @@ -1663,15 +1664,17 @@ def test(binary, quic=False): client.remove(f'/pane/{dashed}') # A name under a directory that may not be searched is refused, # permission denied, exit 1, no pane: its Save could never be. - (root / 'noperm').mkdir() - (root / 'noperm').chmod(0) - before = serials() - try: - denied = subprocess.run([binary, 'noperm/a/b/c'], cwd=root, env=env, capture_output=True, timeout=10) - finally: - (root / 'noperm').chmod(0o755) - assert denied.returncode == 1 and b'permission denied' in denied.stderr, denied - assert serials() == before + # (Root searches any directory.) + if os.geteuid() != 0: + (root / 'noperm').mkdir() + (root / 'noperm').chmod(0) + before = serials() + try: + denied = subprocess.run([binary, 'noperm/a/b/c'], cwd=root, env=env, capture_output=True, timeout=10) + finally: + (root / 'noperm').chmod(0o755) + assert denied.returncode == 1 and b'permission denied' in denied.stderr, denied + assert serials() == before # --wait waits on the pane its look answered, on the look's own # open: a name /index shows escaped (a backslash is `\\` there) # is still the pane waited on, not one already gone. @@ -1824,16 +1827,17 @@ def test(binary, quic=False): stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10) assert fed.returncode == 0 and serials() == before, (fed, serials()) # A new name in a directory there but not writable: refused now, - # not a pane that only fails at Save. + # not a pane that only fails at Save. (Root writes anywhere.) shut = root / 'shut-dir' shut.mkdir() shut.chmod(0o500) try: - refused = subprocess.run([binary, 'shut-dir/new.txt'], cwd=root, env=env, - stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10) - assert refused.returncode == 1, refused - assert b'may not be read or written' in refused.stderr, refused.stderr - assert serials() == before, (serials(), before) + if os.geteuid() != 0: + refused = subprocess.run([binary, 'shut-dir/new.txt'], cwd=root, env=env, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10) + assert refused.returncode == 1, refused + assert b'may not be read or written' in refused.stderr, refused.stderr + assert serials() == before, (serials(), before) finally: shut.chmod(0o755) for word, said in (('@p999:1', b'pardes: @p999:1: this session has no such pane'), diff --git a/test/kitty.zig b/test/kitty.zig index de4dd605..07e89cf9 100644 --- a/test/kitty.zig +++ b/test/kitty.zig @@ -299,6 +299,8 @@ test "kitty: file, temporary-file and shared-memory media load, and the terminal const fd = shm.shm_open(name, @bitCast(std.c.O{ .ACCMODE = .RDWR, .CREAT = true, .TRUNC = true }), 0o600); if (fd < 0) return error.ShmOpenFailed; defer _ = shm.shm_unlink(name); + // Sized first: FreeBSD's write does not grow a shared memory object. + if (ftruncate(fd, rgb_raw.len) != 0) return error.WriteFailed; if (std.c.write(fd, &rgb_raw, rgb_raw.len) != rgb_raw.len) return error.WriteFailed; _ = std.c.close(fd); r.feed(0, try std.fmt.allocPrint(arena, "\x1b_Ga=t,t=s,i=43,f=24,s=4,v=2,S={d};{s}\x1b\\", .{ rgb_raw.len, try b64(arena, name) })); @@ -847,6 +849,8 @@ test "kitty: a FIFO named by t=f, t=t or t=s never blocks pardes" { .{ .medium = 's', .fifo = shm_path, .name = shm_path["/dev/shm".len..] }, }; for (cases) |c| { + // Shared memory is a directory only on Linux (/dev/shm). + if (c.medium == 's' and comptime @import("builtin").os.tag != .linux) continue; _ = std.c.unlink(c.fifo); if (mkfifo(c.fifo, 0o600) != 0) return error.MkfifoFailed; defer _ = std.c.unlink(c.fifo); |
