Skip to content

Commit 00c48ad

Browse files
committed
os/exec: document interaction of Dir, PWD, os.Getwd and C
Fixes #68000 Change-Id: Ie70a8ecc9573b2a4cf57119bda57e0af5e16c42f Reviewed-on: https://go-review.googlesource.com/c/go/+/609395 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent f84dea3 commit 00c48ad

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/os/exec/exec.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,27 @@ type Cmd struct {
166166
// value in the slice for each duplicate key is used.
167167
// As a special case on Windows, SYSTEMROOT is always added if
168168
// missing and not explicitly set to the empty string.
169+
//
170+
// See also the Dir field, which may set PWD in the environment.
169171
Env []string
170172

171173
// Dir specifies the working directory of the command.
172174
// If Dir is the empty string, Run runs the command in the
173175
// calling process's current directory.
176+
//
177+
// On Unix systems, the value of Dir also determines the
178+
// child process's PWD environment variable if not otherwise
179+
// specified. A Unix process represents its working directory
180+
// not by name but as an implicit reference to a node in the
181+
// file tree. So, if the child process obtains its working
182+
// directory by calling a function such as C's getcwd, which
183+
// computes the canonical name by walking up the file tree, it
184+
// will not recover the original value of Dir if that value
185+
// was an alias involving symbolic links. However, if the
186+
// child process calls Go's [os.Getwd] or GNU C's
187+
// get_current_dir_name, and the value of PWD is an alias for
188+
// the current directory, those functions will return the
189+
// value of PWD, which matches the value of Dir.
174190
Dir string
175191

176192
// Stdin specifies the process's standard input.

0 commit comments

Comments
 (0)