From 1490707c3f88b0586cee93a7568390c442579977 Mon Sep 17 00:00:00 2001 From: fizzy pop-os-claude-2 Date: Wed, 11 Nov 2026 14:00:43 -0600 Subject: [PATCH] android: the control socket no longer kills the app on launch Signed-off-by: fizzy pop-os-claude-2 --- app/control/Server.zig | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/app/control/Server.zig b/app/control/Server.zig index c8a45ad11..079c2ff69 100644 --- a/app/control/Server.zig +++ b/app/control/Server.zig @@ -249,9 +249,12 @@ pub fn start(self: *Server) !void { if (std.fs.path.dirname(self.socket_path)) |dir| { try Io.Dir.cwd().createDirPath(self.io, dir); if (comptime builtin.target.os.tag != .windows) { - const st = try Io.Dir.cwd().statFile(self.io, dir, .{ .follow_symlinks = false }); - if (st.kind != .directory) return error.NotAFolder; - try Io.Dir.cwd().setFilePermissions(self.io, dir, .fromMode(0o700), .{ .follow_symlinks = false }); + // By fd, not by path: std's path chmod without following links is `fchmodat2`, which + // Android's seccomp filter kills the app for. `.iterate` keeps the fd from being O_PATH, + // which `fchmod` refuses. + var folder = try Io.Dir.cwd().openDir(self.io, dir, .{ .follow_symlinks = false, .iterate = true }); + defer folder.close(self.io); + try folder.setPermissions(self.io, .fromMode(0o700)); } } // A socket left by a fizzy that did not quit cleanly, or one a fizzy this one takes over from @@ -901,6 +904,34 @@ test "a request reaches the UI thread and its answer goes back" { try std.testing.expectEqual(@as(std.posix.mode_t, 0o700), folder.permissions.toMode() & 0o777); } +test "a link in the socket folder's place is refused, and its target keeps its mode" { + if (!Io.net.has_unix_sockets or builtin.target.os.tag == .windows) return error.SkipZigTest; + const gpa = std.testing.allocator; + const io = std.testing.io; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const path = try testSocket(gpa, &tmp); + defer gpa.free(path); + const link = std.fs.path.dirname(path).?; + + // A folder shared with others, and a link to it where the socket's folder goes. + var shared = try tmp.dir.createDirPathOpen(io, "shared", .{ .open_options = .{ .iterate = true } }); + defer shared.close(io); + try shared.setPermissions(io, .fromMode(0o755)); + const target = try tmp.dir.realPathFileAlloc(io, "shared", gpa); + defer gpa.free(target); + try Io.Dir.cwd().symLink(io, target, link, .{ .is_directory = true }); + defer Io.Dir.cwd().deleteFile(io, link) catch {}; + + var server: Server = .{ .gpa = gpa, .io = io, .socket_path = path, .wake = noWake }; + if (server.start()) |_| { + server.stop(); + return error.TestUnexpectedResult; + } else |_| {} + const st = try tmp.dir.statFile(io, "shared", .{}); + try std.testing.expectEqual(@as(std.posix.mode_t, 0o755), st.permissions.toMode() & 0o777); +} + /// A socket path for a test, in a folder of its own that `start` makes and `removeTestSocket` /// removes. Short: the tmp dir lives under the build's cache, which a deep checkout (a worker's /// sibling workspace) pushes past what the OS takes (`max_path`). Named by the tmp dir's random