Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/exec: document subtleties around Cmd.Dir, PWD, os.Getwd and C's getcwd #68000

Closed
adonovan opened this issue Jun 14, 2024 · 2 comments
Closed
Assignees
Labels
Documentation Issues describing a change to documentation. gabywins NeedsFix The path to resolution is known, but the work has not been done.

Comments

@adonovan
Copy link
Member

The interaction of exec.Cmd and os.Getwd is rather subtle: the working directory of a POSIX process is represented by a file descriptor, not a string, so C's getcwd will always return a real (symlink-free) path. By contrast, Go's os.Getwd will return the value of $PWD if it is an alias for the real path. (It does not do this for ancestors or other directories: it won't return $PWD/foo if that is an alias for getcwd, for example.) exec.Cmd sets the PWD variable implicitly in order to make os.Getwd, and similar functions such as GNU C's get_current_dir_name, work this way--but it only does so in certain circumstances.

We should document the subtleties of this issue so that users of os/exec and os.Getwd don't get confused (as I did in #67757).

@adonovan adonovan added the Documentation Issues describing a change to documentation. label Jun 14, 2024
@adonovan adonovan changed the title os/exec: document subtleties around PWD, os.Getwd and C's getcwd os/exec: document subtleties around Cmd.Dir, PWD, os.Getwd and C's getcwd Jun 14, 2024
@gabyhelp
Copy link

Similar Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@joedian joedian added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 25, 2024
@rsc rsc added the gabywins label Jun 28, 2024
@adonovan adonovan self-assigned this Aug 28, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/609395 mentions this issue: os/exec: document interaction of Dir, PWD, os.Getwd and C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues describing a change to documentation. gabywins NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants