aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec
AgeCommit message (Collapse)Author
2026-01-12os/exec: move platform-specific LookPath docs to a common commentDamien Neil
We have four different LookPath variations (unix, windows, plan9, wasm), each with slightly different doc comments. Unify the documentation and move it to a single, common LookPath. Change-Id: I56bae57e80887a73ef0f6933258ee0a48dbccdcf Reviewed-on: https://go-review.googlesource.com/c/go/+/734320 Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-01-12os/exec_test: fix test on Plan 9Ori Bernstein
Error strings vary across OSes when trying to execute a file that does not exist. Since matching them is not the point of the test, ignore them. Fixes #76965 Change-Id: I6d220bc2d0289070f3441adb48983c13b2a3e597 Reviewed-on: https://go-review.googlesource.com/c/go/+/732940 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Richard Miller <millerresearch@gmail.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2026-01-06os/exec: avoid atomic.Bool for Cmd.startCalledAlan Donovan
An atomic.Bool isn't necessary here since, unless otherwise specified, the methods of an object are not concurrency-safe w.r.t. each other. Using an atomic causes the copylocks vet check to warn about copying of Cmd, which is not wrong, because one shouldn't be copying opaque complex structs from other packages, but it is a nuisance in the absence of any safe way to copy a Cmd. If and when we add a Clone method to Cmd (see #77075) then it would be appropriate to revert this change so that we get the benefit of the static check (though ideally we would make a more explicit tool-readable declaration of the "do not copy" attribute than merely happening to use an atomic.Bool). For #77075 Change-Id: I982d4e86623ca165a3e76bbf648fd44041d5f6bb Reviewed-on: https://go-review.googlesource.com/c/go/+/734200 Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-12-22os/exec: second call to Cmd.Start is always an errorAlan Donovan
Previously it would return an error only if the first call resulted in process creation, contra the intent of the comment at exec.Cmd: // A Cmd cannot be reused after calling its [Cmd.Start], [Cmd.Run], // [Cmd.Output], or [Cmd.CombinedOutput] methods. Also, clear the Cmd.goroutines slice in case of failure to start a process, so that the closures can be GC'd and their pipe fds finalized and closed. Fixes #76746 Change-Id: Ic63a4dced0aa52c2d4be7d44f6dcfc84ee22282c Reviewed-on: https://go-review.googlesource.com/c/go/+/728642 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
2025-11-12os/exec: include Cmd.Start in the list of methods that run CmdSean Liao
Fixes #76265 Change-Id: I451271c5662dd3bcdeec07b55761b15f64c00dcd Reviewed-on: https://go-review.googlesource.com/c/go/+/719860 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
2025-10-17all: remove unnecessary loop variable copies in testsTobias Klauser
Copying the loop variable is no longer necessary since Go 1.22. Change-Id: Iebb21dac44a20ec200567f1d786f105a4ee4999d Reviewed-on: https://go-review.googlesource.com/c/go/+/711640 Reviewed-by: Florian Lehner <lehner.florian86@gmail.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-13all: replace calls to errors.As with errors.AsTypeJulien Cretel
This change replaces most occurrences (in code as well as in comments) of errors.As with errors.AsType. It leaves the errors package and vendored code untouched. Change-Id: I3bde73f318a0b408bdb8f5a251494af15a13118a GitHub-Last-Rev: 8aaaa36a5a12d2a6a90c6d51680464e1a3115139 GitHub-Pull-Request: golang/go#75698 Reviewed-on: https://go-review.googlesource.com/c/go/+/708495 Auto-Submit: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-09-15all: replace strings.Split with strings.SplitSeq1911860538
In Go 1.25+, strings.SplitSeq offers better performance. Here are the benchmark results comparing strings.Split and strings.SplitSeq in a for-loop, with the benchmark code located in src/strings/iter_test.go: goos: darwin goarch: amd64 pkg: cmd/go/internal/auth cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ ParseGitAuth/standard-8 281.4n ± 1% 218.0n ± 11% -22.54% (p=0.000 n=10) ParseGitAuth/with_url-8 549.1n ± 1% 480.5n ± 13% -12.48% (p=0.002 n=10) ParseGitAuth/minimal-8 235.4n ± 1% 197.3n ± 7% -16.20% (p=0.000 n=10) ParseGitAuth/complex-8 797.6n ± 2% 805.2n ± 4% ~ (p=0.481 n=10) ParseGitAuth/empty-8 87.48n ± 3% 63.25n ± 6% -27.71% (p=0.000 n=10) ParseGitAuth/malformed-8 228.8n ± 1% 171.2n ± 3% -25.17% (p=0.000 n=10) geomean 288.9n 237.7n -17.72% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ ParseGitAuth/standard-8 192.00 ± 0% 96.00 ± 0% -50.00% (p=0.000 n=10) ParseGitAuth/with_url-8 400.0 ± 0% 288.0 ± 0% -28.00% (p=0.000 n=10) ParseGitAuth/minimal-8 144.00 ± 0% 80.00 ± 0% -44.44% (p=0.000 n=10) ParseGitAuth/complex-8 528.0 ± 0% 400.0 ± 0% -24.24% (p=0.000 n=10) ParseGitAuth/empty-8 32.00 ± 0% 16.00 ± 0% -50.00% (p=0.000 n=10) ParseGitAuth/malformed-8 176.00 ± 0% 80.00 ± 0% -54.55% (p=0.000 n=10) geomean 179.0 102.1 -42.96% │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ ParseGitAuth/standard-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10) ParseGitAuth/with_url-8 4.000 ± 0% 3.000 ± 0% -25.00% (p=0.000 n=10) ParseGitAuth/minimal-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10) ParseGitAuth/complex-8 4.000 ± 0% 3.000 ± 0% -25.00% (p=0.000 n=10) ParseGitAuth/empty-8 2.000 ± 0% 1.000 ± 0% -50.00% (p=0.000 n=10) ParseGitAuth/malformed-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10) geomean 3.086 2.040 -33.91% Updates #69315. Change-Id: Id0219edea45d9658d527b863162ebe917e7821d9 GitHub-Last-Rev: 392b315e122f2c9ef8703ca2dbce8f82ec198556 GitHub-Pull-Request: golang/go#75259 Reviewed-on: https://go-review.googlesource.com/c/go/+/701015 Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com>
2025-09-15internal/syscall/unix: add KernelVersionGEKir Kolyshkin
There are a few places in the code which checks that the running kernel is greater than or equal to x.y. The check takes a few lines and the checking code is somewhat distracting. Let's abstract this check into a simple function, KernelVersionGE, and convert the users accordingly. Add a test case (I'm not sure it has much value, can be dropped). Change-Id: I8ec91dcc7452363361f95e46794701c0ae57d956 Reviewed-on: https://go-review.googlesource.com/c/go/+/700796 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Mark Freeman <markfreeman@google.com>
2025-08-13os/exec: fix incorrect expansion of ".." in LookPath on plan9Richard Miller
The correction in CL 685755 is incomplete for plan9, where path search is performed even on file strings containing "/". By applying filepath.Clean to the argument of validateLookPath, we can check for bogus file strings containing ".." where the later call to filepath.Join would transform a path like "badfile/dir/.." to "badfile" even where "dir" isn't a directory or doesn't exist. For #74466 Fixes #74892 Change-Id: I3f8b73a1de6bc7d8001b1ca8e74b78722408548e Reviewed-on: https://go-review.googlesource.com/c/go/+/693935 Reviewed-by: David du Colombier <0intro@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-07-29os/exec: fix incorrect expansion of "", "." and ".." in LookPathOlivier Mengué
Fix incorrect expansion of "" and "." when $PATH contains an executable file or, on Windows, a parent directory of a %PATH% element contains an file with the same name as the %PATH% element but with one of the %PATHEXT% extension (ex: C:\utils\bin is in PATH, and C:\utils\bin.exe exists). Fix incorrect expansion of ".." when $PATH contains an element which is an the concatenation of the path to an executable file (or on Windows a path that can be expanded to an executable by appending a %PATHEXT% extension), a path separator and a name. "", "." and ".." are now rejected early with ErrNotFound. Fixes CVE-2025-47906 Fixes #74466 Change-Id: Ie50cc0a660fce8fbdc952a7f2e05c36062dcb50e Reviewed-on: https://go-review.googlesource.com/c/go/+/685755 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2025-06-12all: replace a few user-visible mentions of golang.org and godoc.orgAlberto Donizetti
This change replaces a few user-visible mentions of golang.org and godoc.org with go.dev and pkg.go.dev, respectively. Non-user-visible mentions (e.g. in test scripts) were left untouched. Change-Id: I5d828edcd618b6c55243d0dfcadc6fa1ce9422ce Reviewed-on: https://go-review.googlesource.com/c/go/+/681255 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-05-19runtime: pass through -asan/-msan/-race to testprog testsMichael Pratt
The tests using testprog / testprogcgo are currently not covered on the asan/msan/race builders because they don't build testprog with the sanitizer flag. Explicitly pass the flag if the test itself is built with the sanitizer. There were a few tests that explicitly passed -race (even on non-race builders). These tests will now only run on race builders. For #71395. Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-asan-clang15,gotip-linux-amd64-msan-clang15,gotip-linux-amd64-race Change-Id: I6a6a636ce8271246316a80d426c0e4e2f6ab99c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/643897 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Michael Pratt <mpratt@google.com>
2025-03-20all: use exec.Command.String in test logsqmuntal
There is no need to manually construct a human-friendly string for a exec.Command. The String method does that for us. Change-Id: Iff1033478000bade9cbdc079f6143a7690374258 Reviewed-on: https://go-review.googlesource.com/c/go/+/659475 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-02-20syscall: don't send child signal when testing pidfdIan Lance Taylor
Avoid a spurious SIGCHLD the first time we start a process. Fixes #71828 Change-Id: I744100d21bf6aaaaafc99bc5eec9f9f807a50682 Reviewed-on: https://go-review.googlesource.com/c/go/+/650835 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-27os/exec: edit comment to remove invalid linkAdam Bender
Update comment to remove link formatting that doesn't turn into a link, because the target field is not a top-level member of the package. Re-word comment slightly. Change-Id: I43ebd8fb105b772a4362c0c763e6464321a92747 Reviewed-on: https://go-review.googlesource.com/c/go/+/631856 Reviewed-by: Veronica Silina <veronicasilina@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-30net,os: use os.LookupEnv instead of syscall.GetenvMateusz Poliwczak
The os package already has a function for retrieving an environment variable with a ok boolean, we don't need to use syscall directly. Change-Id: Ife873e7245261ec765b628e31a0e7a7bc4dff934 GitHub-Last-Rev: bc5f30bf56c87a94e0f17dd67a15aa4b2d7e3fd4 GitHub-Pull-Request: golang/go#69700 Reviewed-on: https://go-review.googlesource.com/c/go/+/616342 Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-09-04all: use t.Chdir in testsKir Kolyshkin
Change-Id: I5bc514bedeb1155e6db52e37736fd6101774aea0 Reviewed-on: https://go-review.googlesource.com/c/go/+/529896 Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@golang.org>
2024-09-03math,os,os/*: use testenv.ExecutableKir Kolyshkin
As some callers don't have a testing context, modify testenv.Executable to accept nil (similar to how testenv.GOROOT works). Change-Id: I39112a7869933785a26b5cb6520055b3cc42b847 Reviewed-on: https://go-review.googlesource.com/c/go/+/609835 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-08-29os/exec: document interaction of Dir, PWD, os.Getwd and CAlan Donovan
Fixes #68000 Change-Id: Ie70a8ecc9573b2a4cf57119bda57e0af5e16c42f Reviewed-on: https://go-review.googlesource.com/c/go/+/609395 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-07-25os,path/filepath,testing: use slices to clean up testsapocelipes
Replace reflect.DeepEqual with slices.Equal which is much faster. Change-Id: I299db6f998738174983731f08c1021346b87dfaa GitHub-Last-Rev: 44ca9015d6af4e0fbe8d23c93b3f2da08a2d7728 GitHub-Pull-Request: golang/go#67613 Reviewed-on: https://go-review.googlesource.com/c/go/+/587938 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-07-07os/exec: only use cachedLookExtensions if Cmd.Path is unmodifiedDmitri Shuralyov
Caching the invocation of lookExtensions on an absolute path in Command and reusing the cached result in Start is only viable if Cmd.Path isn't set to a different value after Command returns. For #66586. Fixes #68314. Change-Id: I57007850aca2011b11344180c00faded737617b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/596875 Reviewed-by: qiu laidongfeng2 <2645477756@qq.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-06-07os/exec: on Windows look for extensions in Run if not already doneqiulaidongfeng
CL 512155 fixed #36768, but introduced #62596. CL 527820 fixed #62596, but meant that the code failed to look up file extensions on Windows for a relative path. This CL fixes that problem by recording whether it has already looked up file extensions. This does mean that if Path is set manually then we do not update it with file extensions, as doing that would be racy. Fixes #66586 Change-Id: I9a0305d1e466c5e07bfbe442566ea12f5255a96e GitHub-Last-Rev: dc3169f2350f61acac5ef7842b7514013abacbe1 GitHub-Pull-Request: golang/go#67035 Reviewed-on: https://go-review.googlesource.com/c/go/+/581695 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-03-26all: fix a large number of commentscui fliter
Partial typo corrections, following https://go.dev/wiki/Spelling Change-Id: I2357906ff2ea04305c6357418e4e9556e20375d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/573776 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-03-04os/exec: remove unnecessary fmt.Sprintf callguoguangwu
Change-Id: Ic0ac97a15dadd756d727fd8abe23359b0347af19 GitHub-Last-Rev: a96a3f5fe7fbfb41f38acadab3c03c4a76c89b78 GitHub-Pull-Request: golang/go#66052 Reviewed-on: https://go-review.googlesource.com/c/go/+/568317 Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Jorropo <jorropo.pgm@gmail.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-02-26std: fix more nilness findingsAlan Donovan
(found with x/tools/go/analysis/passes/nilness) Change-Id: I1bdc7811efbecea95608e634f894cb6c656e3a5b Reviewed-on: https://go-review.googlesource.com/c/go/+/564221 Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-26os: add available godoc linkcui fliter
Change-Id: I430c9a7c4936d7a8c8c787aa63de9a796d20fdf3 Reviewed-on: https://go-review.googlesource.com/c/go/+/539597 Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-09-18os/exec: adjust function name in fatal messageTobias Klauser
CL 481620 changed the test to use LookPath. Change-Id: Ie7b3110775b586701b6df6aeee38f26402227eb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/529095 Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Bypass: Bryan Mills <bcmills@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-09-13os/exec: avoid calling LookPath in cmd.Start for resolved pathsBryan C. Mills
This reapplies CL 512155, which was previously reverted in CL 527337. The race that prompted the revert should be fixed by CL 527820, which will be submitted before this one. For #36768. Updates #62596. Change-Id: I3c3cd92470254072901b6ef91c0ac52c8071e0a2 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-race,gotip-windows-amd64-race,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/528038 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2023-09-13os/exec: fix edge cases in Windows PATH resolutionBryan C. Mills
- Ignore empty entries in PATH, like PowerShell does. - If we resolve a path using an explicit relative entry in PATH, treat it the same as we do for the implicit "." search path, by allowing a later (absolute) PATH entry that resolves to the same executable to return the absolute version of its path. - If the requested path does not end with an extension matching PATHEXT, return ErrNotFound (indicating that we potentially searched for multiple alternatives and did not find one) instead of ErrNotExist (which would imply that we know the exact intended path but couldn't find it). Fixes #61493. Change-Id: I5b539d8616e3403825749d8eccf46725fa808a17 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-race,gotip-windows-amd64-race,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/528037 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-09-13os/exec: avoid writing to Cmd.Path in Cmd.Start on WindowsBryan C. Mills
Fixes #62596. Change-Id: I9003318ac1c4e3036f32383e62e9ba08c383d5c2 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-race,gotip-windows-amd64-race,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/527820 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-13os/exec: simplify Windows-specific testsBryan C. Mills
- Use the test binary itself for printing paths instead of building a separate binary and running it through additional subprocesses. - Factor out a common chdir helper. - Use t.Setenv where appropriate. - Reduce indirection in test helpers. - Set NoDefaultCurrentDirectoryInExePath consistently in the environment. Also add a test case demonstrating an interesting behavior for relative paths that may interact with #62596. Fixes #62594. For #62596. Change-Id: I19b9325034edf78cd0ca747594476cd7432bb451 Reviewed-on: https://go-review.googlesource.com/c/go/+/528035 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-12Revert "os/exec: avoid calling LookPath in cmd.Start for resolved paths"Ian Lance Taylor
This reverts CL 512155. Reason for revert: CL 512155 introduced a race in that it caused cmd.Start to set cmd.Path. Previously it was fine if code looked at cmd.Path in one goroutine while calling cmd.Start in a different goroutine. A test case for this race is in CL 527495. Change-Id: Ic18fdadf6763727f8ea748280d5f0e601b9bf374 Reviewed-on: https://go-review.googlesource.com/c/go/+/527337 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-08-21os/exec: don't convert byte slice to string when using verb %sJes Cok
Change-Id: I4d755e401acf670fb5a154ff59e4e4335ed2138e GitHub-Last-Rev: a91d74ae55f84a0e572d2ace335ec42038d7a76f GitHub-Pull-Request: golang/go#62150 Reviewed-on: https://go-review.googlesource.com/c/go/+/520918 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-08-01os/exec: Use the built-in function min instead of minIntapocelipes
The built-in function `min` has been implemented and can now be used to replace some manually written `minType` helper functions. Change-Id: Ie8ffc7881c8652ece752751214f1242bf76a6e7e GitHub-Last-Rev: 5db344f13142c78f437571e3a1cdc0b02c0589cb GitHub-Pull-Request: golang/go#60866 Reviewed-on: https://go-review.googlesource.com/c/go/+/504315 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com>
2023-07-26os/exec: avoid calling LookPath in cmd.Start for resolved pathsqiulaidongfeng
Follow up on CL 511458, see https://go-review.googlesource.com/c/go/+/511458/2..4/src/cmd/go/main.go#b270 . For #36768. Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847 Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847 GitHub-Last-Rev: bac7e66496806d505270c5b90d53672d80a1ca29 GitHub-Pull-Request: golang/go#61517 Reviewed-on: https://go-review.googlesource.com/c/go/+/512155 Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
2023-07-11os/exec: ignore context.Canceled errors in TestConcurrentExecBryan C. Mills
We cancel the Context to unblock the test as soon as all of the "exit" processes have completed. If that happens to occur before all of the "hang" processes have started, the Start calls may fail with context.Canceled. Since those errors are possible in normal operation of the test, ignore them. Fixes #61277. Updates #61080. Change-Id: I20db083ec89ca88eb085ceb2892b9f87f83705ac Reviewed-on: https://go-review.googlesource.com/c/go/+/508755 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-07-10syscall: serialize locks on ForkLock on platforms where forkExecPipe is not ↵Bryan C. Mills
atomic In CL 421441, we changed syscall to allow concurrent calls to forkExec. On platforms that support the pipe2 syscall that is the right behavior, because pipe2 atomically opens the pipe with CLOEXEC already set. However, on platforms that do not support pipe2 (currently aix and darwin), syscall.forkExecPipe is not atomic, and the pipes do not initially have CLOEXEC set. If two calls to forkExec proceed concurrently, a pipe intended for one child process can be accidentally inherited by the other. If the process is long-lived, the pipe can be held open unexpectedly and prevent the parent process from reaching EOF reading the child's status from the pipe. Fixes #61080. Updates #23558. Updates #54162. Change-Id: I83edcc80674ff267a39d06260c5697c654ff5a4b Reviewed-on: https://go-review.googlesource.com/c/go/+/507355 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2023-05-15os, syscall: support ill-formed UTF-16 strings on Windowsqmuntal
Windows UTF-16 strings can contain unpaired surrogates, which can't be decoded into a valid UTF-8 string. This file defines a set of functions that can be used to encode and decode potentially ill-formed UTF-16 strings by using the [the WTF-8 encoding](https://simonsapin.github.io/wtf-8/). WTF-8 is a strict superset of UTF-8, i.e. any string that is well-formed in UTF-8 is also well-formed in WTF-8 and the content is unchanged. Also, the conversion never fails and is lossless. The benefit of using WTF-8 instead of UTF-8 when decoding a UTF-16 string is that the conversion is lossless even for ill-formed UTF-16 strings. This property allows to read an ill-formed UTF-16 string, convert it to a Go string, and convert it back to the same original UTF-16 string. Fixes #59971 Change-Id: Id6007f6e537844913402b233e73d698688cd5ba6 Reviewed-on: https://go-review.googlesource.com/c/go/+/493036 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Paul Hampson <Paul.Hampson@Pobox.com>
2023-04-18cmd/go: add check for unknown godebug settingRuss Cox
A //go:debug line mentioning an unknown or retired setting should be diagnosed as making the program invalid. Do that. We agreed on this in the proposal but I forgot to implement it. Change-Id: Ie69072a1682d4eeb6866c02adbbb426f608567c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/476280 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-04-07os: add wasip1 supportJohan Brandhorst-Satzkorn
For #58141 Co-authored-by: Richard Musiol <neelance@gmail.com> Co-authored-by: Achille Roussel <achille.roussel@gmail.com> Co-authored-by: Julien Fabre <ju.pryz@gmail.com> Co-authored-by: Evan Phoenix <evan@phx.io> Change-Id: I52e3e161f81dcbe8605570e47d732992979c4d34 Reviewed-on: https://go-review.googlesource.com/c/go/+/479623 Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-04-04os/exec: skip remount in TestFindExecutableVsNoexec on EROFSTobias Klauser
To allow using testenv.SyscallIsNotSupported, rewrite the test to use the exported API only. Given that path is an absolute path, exec.LookPath is equivalent to exec.findExecutable on linux. Fixes #59087 Change-Id: Ia01b84d4e9d5a65a88dd995f9e3c8a81c4ccd19f Reviewed-on: https://go-review.googlesource.com/c/go/+/481620 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Bypass: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-03-02cmd/link/internal/ld: move more of mustLinkExternal into internal/platformBryan C. Mills
internal/platform.MustLinkExternal is used in various places to determine whether external linking is required. It should always match what the linker actually requires, but today does not match because the linker imposes additional constraints. Updates #31544. Change-Id: I0cc6ad587e95c607329dea5d60d29a5fb2a9e722 Reviewed-on: https://go-review.googlesource.com/c/go/+/472515 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-02-28all: fix typospgxiaolianzi
Change-Id: Ica8d5e5799a4de532764ae86cdb623508d3a8e18 GitHub-Last-Rev: 3e97cca9de3885f2fe0d7deb776e59cc1c73146d GitHub-Pull-Request: golang/go#58689 Reviewed-on: https://go-review.googlesource.com/c/go/+/471021 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-02-21os: use testenv.Command instead of exec.Command in testscui fliter
testenv.Command sets a default timeout based on the test's deadline and sends SIGQUIT (where supported) in case of a hang. Change-Id: I84d469d12ca1f39175b713ca41e7cd2202d11d96 Reviewed-on: https://go-review.googlesource.com/c/go/+/451895 Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-01-19internal/godebug: export non-default-behavior counters in runtime/metricsRuss Cox
Allow GODEBUG users to report how many times a setting resulted in non-default behavior. Record non-default-behaviors for all existing GODEBUGs. Also rework tests to ensure that runtime is in sync with runtime/metrics.All, and generate docs mechanically from metrics.All. For #56986. Change-Id: Iefa1213e2a5c3f19ea16cd53298c487952ef05a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/453618 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-01-10os/exec: avoid leaking an exec.Cmd in TestWaitInterruptBryan C. Mills
In CL 436655 I added a GODEBUG setting to this test process to verify that Wait is eventually called for every exec.Cmd before it becomes unreachable. However, the cmdHang test helpers in TestWaitInterrupt/Exit-hang and TestWaitInterrupt/SIGKILL-hang intentially leak a subprocess in order to simulate a leaky third-party program, as Go users might encounter in practical use. To avoid tripping over the leak check, we call Wait on the leaked subprocess in a background goroutine. Since we expect the process running cmdHang to exit before its subprocess does, the call to Wait should have no effect beyond suppressing the leak check. Fixes #57596. Updates #52580. Updates #50436. Change-Id: Ia4b88ea47fc6b605c27ca6d9d7669c874867a900 Reviewed-on: https://go-review.googlesource.com/c/go/+/460998 Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-12-16os/exec: retry ETXTBSY errors in TestFindExecutableVsNoexecBryan C. Mills
I made this test parallel in CL 439196, which exposed it to the fork/exec race condition described in #22315. The ETXTBSY errors from that race should resolve on their own, so we can simply retry the call to get past them. Fixes #56811. Updates #22315. Change-Id: I2c6aa405bf3a1769d69cf08bf661a9e7f86440b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/458016 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-14internal/godebug: define more efficient APIRuss Cox
We have been expanding our use of GODEBUG for compatibility, and the current implementation forces a tradeoff between freshness and efficiency. It parses the environment variable in full each time it is called, which is expensive. But if clients cache the result, they won't respond to run-time GODEBUG changes, as happened with x509sha1 (#56436). This CL changes the GODEBUG API to provide efficient, up-to-date results. Instead of a single Get function, New returns a *godebug.Setting that itself has a Get method. Clients can save the result of New, which is no more expensive than errors.New, in a global variable, and then call that variable's Get method to get the value. Get costs only two atomic loads in the case where the variable hasn't changed since the last call. Unfortunately, these changes do require importing sync from godebug, which will mean that sync itself will never be able to use a GODEBUG setting. That doesn't seem like such a hardship. If it was really necessary, the runtime could pass a setting to package sync itself at startup, with the caveat that that setting, like the ones used by runtime itself, would not respond to run-time GODEBUG changes. Change-Id: I99a3acfa24fb2a692610af26a5d14bbc62c966ac Reviewed-on: https://go-review.googlesource.com/c/go/+/449504 Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-11os/exec: fix TestWaitInterrupt/WaitDelay error messagescott
As the comments say. Here we expect err to be nil instead of ctx.Err() Change-Id: I4cd02d62ac0a13c9577a567de36742f13d140d36 GitHub-Last-Rev: 6bedfbc9d2511140d088dc9ee5f40015725f68db GitHub-Pull-Request: golang/go#56698 Reviewed-on: https://go-review.googlesource.com/c/go/+/449737 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>