Skip to content

std.ChildProcess: fix EBADF when explicitly passing cwd as working directory#15592

Closed
LordMZTE wants to merge 1 commit intoziglang:masterfrom
LordMZTE:exec-cwd
Closed

std.ChildProcess: fix EBADF when explicitly passing cwd as working directory#15592
LordMZTE wants to merge 1 commit intoziglang:masterfrom
LordMZTE:exec-cwd

Conversation

@LordMZTE
Copy link
Copy Markdown
Contributor

@LordMZTE LordMZTE commented May 5, 2023

closes #9688

This fixes a bug where ChildProcess.spawn would try to call fchdir with AT_FDCWD causing an EBADF error to occur when ChildProcess.cwd_dir is set to std.fs.cwd().

@squeek502
Copy link
Copy Markdown
Member

Worth noting that this is not the only place AT.FDCWD can cause problems (e.g. I know os.fstat has the same issue but the fix there is much less clear), and I'm unsure about exactly where this type of thing should be accounted for. For example, this same issue could be fixed by doing

if (dirfd == AT.FDCWD) return;

in std.os.fchdir instead. Note that this alternate fix would also avoid EBADF when doing something like:

test {
    const cwd = fs.cwd();
    try cwd.setAsCwd();
}

whereas the implementation in this PR would still hit EBADF in that case.

@LordMZTE
Copy link
Copy Markdown
Contributor Author

LordMZTE commented May 6, 2023

Right. Let's see if the maintainers would prefer this fix.

Copy link
Copy Markdown
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please do the fix suggested by @squeek502

@LordMZTE
Copy link
Copy Markdown
Contributor Author

Got it, I'll open this as a new PR as this one is getting pretty outdated and contains a redundant commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ChildProcess.exec can't handle std.fs.cwd() as .cwd_dir

3 participants