From ac30d362067ae19c442296150d7db940ecae7914 Mon Sep 17 00:00:00 2001 From: Roland Kovacs Date: Mon, 20 Jan 2025 22:34:49 +0100 Subject: [PATCH] os/os2: Properly update CWD on Linux when using _process_start() The `dir_fd` argument to `execveat()` is not for setting the current working directory. It is used to resolve relative executable paths, hence explicit `chdir/fchdir` call is required to set CWD. --- core/os/os2/process_linux.odin | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/os/os2/process_linux.odin b/core/os/os2/process_linux.odin index 936fbfc40..c2979b282 100644 --- a/core/os/os2/process_linux.odin +++ b/core/os/os2/process_linux.odin @@ -547,6 +547,10 @@ _process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) { if _, errno = linux.dup2(stderr_fd, STDERR); errno != .NONE { write_errno_to_parent_and_abort(child_pipe_fds[WRITE], errno) } + if dir_fd != linux.AT_FDCWD { + errno = linux.fchdir(dir_fd) + assert(errno == nil) + } errno = linux.execveat(dir_fd, exe_path, &cargs[0], env) assert(errno != nil)