Commit a39b3d0

Eric Bower  ·  2026-07-30 11:54:23 -0400 EDT
parent 0b44313
fix: revert umask and chdir
2 files changed,  +0, -41
+0, -14
......@@ -182,20 +182,6 @@ pub fn daemonize(sesh_name: []const u8, cmd: Cmd, keep_fds_open: []i32) !PtyInfo
182182 // becomes the session leader and detaches process from its controlling terminal
183183 _ = try lib_posix.setsid();
184184
185- // If the daemon was launched from a mounted filesystem (e.g., a USB drive
186- // at /mnt/usb), keeping that directory as the working directory pins the
187- // mount which means it can't be unmounted while the daemon holds it.
188- // chdir("/") moves to the root filesystem, which is never unmounted.
189- const dir_path_c = try lib_posix.toPosixPath("/");
190- try lib_posix.chdirZ(&dir_path_c);
191-
192- // The parent may have had a restrictive umask (e.g., 0077) that would
193- // prevent the daemon from creating files with the intended permissions.
194- // Setting umask(0) lets the daemon explicitly control permissions via
195- // open()/creat() mode arguments, rather than inheriting an unpredictable
196- // mask.
197- _ = std.c.umask(0); // requires libc on linux
198-
199185 // Redirect stdin/stdout/stderr to /dev/null. The daemon
200186 // communicates via its unix socket, not stdio. Without
201187 // this, any pipe on FDs 0-2 (e.g. from bats' `run`
+0, -27
......@@ -1260,33 +1260,6 @@ const unexpected_error_tracing = builtin.mode == .Debug and switch (builtin.zig_
12601260 else => false,
12611261 };
12621262
1263-const ChangeCurDirError = error{
1264- AccessDenied,
1265- FileSystem,
1266- SymLinkLoop,
1267- NameTooLong,
1268- FileNotFound,
1269- SystemResources,
1270- NotDir,
1271- BadPathName,
1272-} || UnexpectedError;
1273-
1274-pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void {
1275- switch (errno(system.chdir(dir_path))) {
1276- .SUCCESS => return,
1277- .ACCES => return error.AccessDenied,
1278- .FAULT => unreachable,
1279- .IO => return error.FileSystem,
1280- .LOOP => return error.SymLinkLoop,
1281- .NAMETOOLONG => return error.NameTooLong,
1282- .NOENT => return error.FileNotFound,
1283- .NOMEM => return error.SystemResources,
1284- .NOTDIR => return error.NotDir,
1285- .ILSEQ => |err| return unexpectedErrno(err),
1286- else => |err| return unexpectedErrno(err),
1287- }
1288-}
1289-
12901263 /// Used to convert a slice to a null terminated slice on the stack.
12911264 pub fn toPosixPath(file_path: []const u8) error{NameTooLong}![PATH_MAX - 1:0]u8 {
12921265 if (std.debug.runtime_safety) assert(mem.indexOfScalar(u8, file_path, 0) == null);