1
0
mirror of https://github.com/golang/go synced 2024-10-01 18:18:32 -06:00
Commit Graph

523 Commits

Author SHA1 Message Date
Brad Fitzpatrick
da0d1a44ba all: use strings.ReplaceAll and bytes.ReplaceAll where applicable
I omitted vendor directories and anything necessary for bootstrapping.
(Tested by bootstrapping with Go 1.4)

Updates #27864

Change-Id: I7d9b68d0372d3a34dee22966cca323513ece7e8a
Reviewed-on: https://go-review.googlesource.com/137856
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-09-26 22:14:25 +00:00
David Heuschmann
eff3de0e63 os/user: note in doc that user.Current is being cached
user.Current caches the current user after its first call, so changes to
the uid after the first call will not affect its result. As this might
be unexpected, it should be mentioned in the docs.

Fixes #27659

Change-Id: I8b3323d55441d9a79bc9534c6490884d8561889b
Reviewed-on: https://go-review.googlesource.com/136315
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-09-25 17:10:46 +00:00
Tobias Klauser
a2a3dd00c9 os: add ModeCharDevice to ModeType
When masking FileInfo.Mode() from a character device with the ModeType
mask, ModeCharDevice cannot be recovered.

ModeCharDevice was added https://golang.org/cl/5531052, but nothing
indicates why it was omitted from ModeType. Add it now.

Fixes #27640

Change-Id: I52f56108b88b1b0a5bc6085c66c3c67e10600619
Reviewed-on: https://go-review.googlesource.com/135075
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-09-13 09:52:57 +00:00
Kevin Burke
3a18f0ecb5 os/user: retrieve Current username from /etc/passwd, not $USER
Per golang/go#27524 there are situations where the username for the
uid does not match the value in the $USER environment variable and it
seems sensible to choose the value in /etc/passwd when they disagree.

This may make the Current() call slightly more expensive, since we
read /etc/passwd with cgo disabled instead of just checking the
environment. However, we cache the result of Current() calls, so we
only invoke this cost once in the lifetime of the process.

Fixes #14626.
Fixes #27524.
Updates #24884.

Change-Id: I0dcd224cf7f61dd5292f3fcc363aa2e9656a2cb1
Reviewed-on: https://go-review.googlesource.com/134218
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-09 19:24:00 +00:00
Giovanni Bajo
1d15354fb9 os/exec: document how to do special args quoting on Windows
Updates #27199

Change-Id: I5cb6540266901697d3558ce75b8de63b1bfc2ce0
Reviewed-on: https://go-review.googlesource.com/132695
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2018-09-01 04:45:46 +00:00
Fazlul Shahriar
2e234754d7 os/exec: pass ExitCode tests on Plan 9
Fixes #27294

Change-Id: I8db5ca0f0c690bf532d3d33b8ed7d2633ad1702b
Reviewed-on: https://go-review.googlesource.com/131855
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-28 14:10:31 +00:00
Guoliang Wang
be94dac4e9 os: add ExitCode method to ProcessState
Fixes #26539

Change-Id: I6d403c1bbb552e1f1bdcc09a7ccd60b50617e0fc
GitHub-Last-Rev: 0b5262df5d
GitHub-Pull-Request: golang/go#26544
Reviewed-on: https://go-review.googlesource.com/125443
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-28 01:46:11 +00:00
Tobias Klauser
a700ae9863 Revert "syscall, os: use pipe2 syscall on DragonflyBSD instead of pipe"
This reverts commit e6c15945de.

Reason for revert: breaks the Dragonfly builders.

Fixes #27245

Change-Id: I2c147a5726aec28647f6ef5eb8f9db5efa3a9fd0
Reviewed-on: https://go-review.googlesource.com/131497
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-26 21:30:35 +00:00
Tobias Klauser
e6c15945de syscall, os: use pipe2 syscall on DragonflyBSD instead of pipe
Follow the implementation used by the other BSDs ith os.Pipe and
syscall.forkExecPipe consisting of a single syscall instead of three.

Change-Id: I602187672f244cbd8faaa3397904d71d15452d9f
Reviewed-on: https://go-review.googlesource.com/130996
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-08-24 14:41:04 +00:00
Seebs
9cfa41c826 os: use Println instead of Printf in example
This message has no format specifiers and no trailing newline.
It should use Println for consistency with other examples.

Change-Id: I49bd1652f9449fcbdd79c6b689c123090972aab3
Reviewed-on: https://go-review.googlesource.com/127836
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-08-24 07:11:38 +00:00
Kazuhiro Sera
ad644d2e86 all: fix typos detected by github.com/client9/misspell
Change-Id: Iadb3c5de8ae9ea45855013997ed70f7929a88661
GitHub-Last-Rev: ae85bcf82b
GitHub-Pull-Request: golang/go#26920
Reviewed-on: https://go-review.googlesource.com/128955
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-08-23 15:54:07 +00:00
David du Colombier
0a842d5560 os: handle TMPDIR in TempDir on Plan 9
CL 129063 added a test in TestScript/mod_enabled,
which was failing on Plan 9.

The test was failing because the Init function
of the cmd/go/internal/modload package was
expecting ModRoot to be part of os.TempDir.

However, ModRoot was set to TMPDIR, while
os.TempDir is returning /tmp on Plan 9.

This change fixes the implementation of
os.TempDir on Plan 9 to handle the TMPDIR
environment variable, similarly to Unix.

Fixes #27065.

Change-Id: Id6ff926c5c379f63cab2dfc378fa6c15293fd453
Reviewed-on: https://go-review.googlesource.com/129775
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-17 23:12:06 +00:00
Ian Lance Taylor
0bad63437e os: document that Remove removes only empty directories
Fixes #26507

Change-Id: I967e4f897ca891c70ca8bb0e66b984530c240815
Reviewed-on: https://go-review.googlesource.com/127835
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-08-03 23:09:31 +00:00
Roberto Clapis
faadda040d os: add check for empty executable path on darwin
os used to panic (access out of bounds) if executablePath was left empty

Fixes #22529

Change-Id: Iead5e60a3b000dbde421a8e8612c3690340879ce
Reviewed-on: https://go-review.googlesource.com/127546
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-02 20:31:25 +00:00
Adam Shannon
6f96cf2793 os/exec: document ExtraFiles is not supported on windows
Fixes #26182

Change-Id: I1181e191f4742f166c9b67a6f41332a237cf0ede
Reviewed-on: https://go-review.googlesource.com/123855
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-07-13 22:29:48 +00:00
Ian Lance Taylor
8d6fc84986 internal/poll: don't take read lock in SetBlocking
Taking a read lock in SetBlocking could cause SetBlocking to block
waiting for a Read in another goroutine to complete. Since SetBlocking
is called by os.(*File).Fd, that could lead to deadlock if the
goroutine calling Fd is going to use it to unblock the Read.
Use an atomic store instead.

Updates #24481

Change-Id: I79413328e06ddf28b6d5b8af7a0e29d5b4e1e6ff
Reviewed-on: https://go-review.googlesource.com/123176
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-07-11 00:34:18 +00:00
Ian Lance Taylor
e86bbc2e27 os: clarify that Close cancels pending I/O
Change-Id: I6be6818d951a999f916c2266a6753a5ce5144ee7
Reviewed-on: https://go-review.googlesource.com/122955
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-07-11 00:06:19 +00:00
Ian Lance Taylor
616da5da94 os: increase directory reading block size on Unix systems
Reportedly CIFS on RHEL 7 can fail to report files if directories are
read in 4K increments. While this seems to be a CIFS or RHEL bug,
reportedly CIFS does not return more than 5760 bytes in a block, so
reading in 8K increments should hide the problem from users with
minimal cost.

Fixes #24015

Change-Id: Iaf9f00ffe338d379c819ed9edcd4cc9834e3b0f7
Reviewed-on: https://go-review.googlesource.com/121756
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-07-06 22:39:14 +00:00
Daniel Martí
a94a390e5c os: treat "${}" in Expand like in Go 1.10
CL 103055 made it so that invalid parameter expansions, like "$|", did
not make the dollar sign silently disappear.

A few edge cases were not taken into account, such as "${}" and "${",
which were now printing just "$". For consistency and to not break
existing programs, go back to eating up the characters when invalid
syntax is encountered.

For completeness, add a "$" test case too, even though its behavior is
unchanged by this CL.

Fixes #26135.

Change-Id: I5d25db9a8356dc6047a8502e318355113a99b247
Reviewed-on: https://go-review.googlesource.com/121636
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-29 21:07:28 +00:00
Ian Lance Taylor
a6a69227f6 os: when looping in RemoveAll, close and re-open directory
On some systems removing files can cause a directory to be re-shuffled,
so simply continuing to read files can cause us to miss some.
Close and re-open the directory when looping, to avoid that.

Read more files each time through the loop, to reduce the chance of
having to re-open.

Fixes #20841

Change-Id: I98a14774ca63786ad05ba5000cbdb01ad2884332
Reviewed-on: https://go-review.googlesource.com/121255
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-27 22:05:25 +00:00
Andrew Bonventre
50bd1c4d4e os: have UserCacheDir return an error on failure
Previously, it would return an empty string if it
could not determine the user's cache directory.
Return an error instead.

Change-Id: I74f00b1ad3858efa3fe2700c599271ebfe5764b6
Reviewed-on: https://go-review.googlesource.com/120757
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-25 18:59:39 +00:00
Ian Lance Taylor
00eac8921e os, net: avoid races between dup, set-blocking-mode, and closing
Fixes #24481
Fixes #24483

Change-Id: Id7da498425a440c91582aa5480c253ae7a9c932c
Reviewed-on: https://go-review.googlesource.com/119955
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-22 14:27:22 +00:00
Tobias Klauser
d8e86caa3f os: skip TestFifoEOF on android
TestFifoEOF fails on android because the mkfifo syscall is not allowed:

--- FAIL: TestFifoEOF (0.00s)
    fifo_test.go:39: permission denied

Change-Id: I007ff359831525add39cec34de4b3d3cd3adb047
Reviewed-on: https://go-review.googlesource.com/118815
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-14 13:41:57 +00:00
Ian Lance Taylor
4a778cdf33 os: don't poll fifos on Darwin
The Darwin kqueue implementation doesn't report any event when the
last writer for a fifo is closed.

Fixes #24164

Change-Id: Ic2c47018ef1284bf2e26379f8dd7646edaad4d05
Reviewed-on: https://go-review.googlesource.com/118566
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-13 20:27:55 +00:00
Eugene Kalinin
0e934dd90e os: check setStickyBit error in mkdir
If an error occurs, delete the newly created directory.

Change-Id: I97e960d24af32f027fb23d5ce3f61959e73f6fb0
Reviewed-on: https://go-review.googlesource.com/115715
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-05 14:53:18 +00:00
Tim Cooper
161874da2a all: update comment URLs from HTTP to HTTPS, where possible
Each URL was manually verified to ensure it did not serve up incorrect
content.

Change-Id: I4dc846227af95a73ee9a3074d0c379ff0fa955df
Reviewed-on: https://go-review.googlesource.com/115798
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
2018-06-01 21:52:00 +00:00
Richard Musiol
063f97a611 os: add js/wasm architecture
This commit adds the js/wasm architecture to the os package.

Access to the actual file system is supported through Node.js.

Updates #18892

Change-Id: I6fa642fb294ca020b2c545649d4324d981aa0408
Reviewed-on: https://go-review.googlesource.com/109977
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-01 05:18:38 +00:00
Tobias Klauser
7ea2c8cf1b os/exec: gofmt
CL 109361 introduced some changes which were not properly gofmt'ed.
Because the CL was sent via Github no gofmt checks were performed
on it (cf. #24946, #18548).

Change-Id: I207065f01161044c420e272f4fd112e0a59be259
Reviewed-on: https://go-review.googlesource.com/115356
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-05-30 19:57:39 +00:00
Tim Cooper
79fbe92b7e os/signal: remove unnecessary else condition
Change-Id: I00f0195d54bf9bc30073741974ab941ec4d51a5c
Reviewed-on: https://go-review.googlesource.com/108635
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-05-29 21:06:31 +00:00
azat
ef99381676 os: Add example for Expand function.
Change-Id: I581492c29158e57ca2f98b75f47870791965a7ff
Reviewed-on: https://go-review.googlesource.com/81155
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-05-23 15:37:22 +00:00
Tobias Klauser
fc9c69a693 os: remove superfluous comments
It's apparent from the file names or build tags to which OS the code in
question applies.

Change-Id: I628ee2bf1d29a6bc30ca5fa6f9eecf809e78a182
Reviewed-on: https://go-review.googlesource.com/110815
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-05-02 14:41:57 +00:00
Brad Fitzpatrick
6a8cff5730 os: fix missing break bug in earlier CL 110295's use of Uname
The Uname name was never being used because it always generated a
too-long string.

The new test looking for zero bytes wouldn't have caught it (I thought
it would've), but is still nice to have.

Updates #24701

Change-Id: I2648074452609e4ad1b9736973e1b3a95eac658d
Reviewed-on: https://go-review.googlesource.com/110436
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-05-01 15:55:49 +00:00
Brad Fitzpatrick
3c7456c1b0 os: find Hostname using Uname to fix Android
It's also fewer system calls. Fall back to longer read
only if it seems like the Uname result is truncated.

Fixes #24701

Change-Id: Ib6550acede8dddaf184e8fa9de36377e17bbddab
Reviewed-on: https://go-review.googlesource.com/110295
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-04-30 18:10:46 +00:00
Yasuhiro Matsumoto
e656aebb5b os: os: make Stat("*.txt") fail on windows
Fixes #24999

Change-Id: Ie0bb6a6e0fa3992cdd272d42347af65ae7c95463
Reviewed-on: https://go-review.googlesource.com/108755
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2018-04-27 10:04:48 +00:00
Lubomir I. Ivanov (VMware)
353bba37df os/exec: fix Win32 tests missing 'chcp'
'%SystemRoot%/System32/chcp.com' is a tool on Windows that
is used to change the active code page in the console.

'go test os/exec' can fail with:
"'chcp' is not recognized as an internal or external command"

The test uses a custom PATH variable but does not include
'%SystemRoot%/System32'. Always append that to PATH.

Updates #24709

Change-Id: I1ab83b326072e3f0086b391b836234bcfd8a1fb7
GitHub-Last-Rev: fb930529bb
GitHub-Pull-Request: golang/go#25088
Reviewed-on: https://go-review.googlesource.com/109361
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-26 18:25:25 +00:00
Russ Cox
e9bc0c5d24 os: fix type check error in benchmark
Previously, 's' was only written to, never read,
which is disallowed by the spec. cmd/compile
has a bug where it doesn't notice this when a
closure is involved, but go/types does notice,
which was making "go vet" fail.

This CL moves the variable into the closure
and also makes sure to use it.

Change-Id: I2d83fb6b5c1c9018df03533e966cbdf455f83bf9
Reviewed-on: https://go-review.googlesource.com/108556
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-04-25 02:46:08 +00:00
Adam Azarchs
dfb1b69665 os/signal: add func Ignored(sig Signal) bool
Ignored reports whether sig is currently ignored.

This implementation only works applies on Unix systems for now.  However, at
the moment that is also the case for Ignore() and several other signal
interaction methods, so that seems fair.

Fixes #22497

Change-Id: I7c1b1a5e12373ca5da44709500ff5acedc6f1316
Reviewed-on: https://go-review.googlesource.com/108376
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-04-21 04:18:03 +00:00
shogo-ma
d75836365e os: fix typo in comment
fix misspell on code comment.

Change-Id: I8280488f71f55616da5543eac0f58cc008354af9
GitHub-Last-Rev: ea144718ee
GitHub-Pull-Request: golang/go#24975
Reviewed-on: https://go-review.googlesource.com/108458
Reviewed-by: Alberto Donizetti <alb.donizetti@gmail.com>
2018-04-20 18:35:51 +00:00
Felix Kollmann
c23afa9ddb os: enable symlink creation on Windows 10
Fixes #22874

Change-Id: Ia30fc8df39e88fbc2939a4490c34da8dd5815a94
GitHub-Last-Rev: 3ba7abcc96
GitHub-Pull-Request: golang/go#24307
Reviewed-on: https://go-review.googlesource.com/99337
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2018-04-19 10:10:22 +00:00
Tim Cooper
155aefe0c1 os/exec: remove "binary" when talking about executables
The use of binary was incorrect as executable files can also be scripts.

The docs for Error are also reworded. The old docs implied that Error was
returned when attempting to start an executable, which is not correct: it
was returned by LookPath when the file was not found or did not have the
attributes of an executable.

Change-Id: I757a44b16612936df4498b43c45c12e4c14956d2
Reviewed-on: https://go-review.googlesource.com/90315
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-17 05:05:45 +00:00
Brad Fitzpatrick
a3df9c4755 os/user: fix osusergo build on Solaris
Verified that on on Linux, with:

CGO_ENABLED=1 GOOS=solaris go install --tags=osusergo

... it builds now.

Updates #24841
Updates #24845

Change-Id: I49f40532bc2a13a9d282771592fc8d7f116b1902
Reviewed-on: https://go-review.googlesource.com/107304
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2018-04-16 21:42:05 +00:00
Brad Fitzpatrick
f613a7bf33 cmd/dist, os/user: test os/user in osusergo mode as well, fix plan9 & windows
Would've caught two regressions so far, and found two more.

Updates #24841
Updates #24845 (package net remains)

Change-Id: I57ad06eb54e04b8c99b5d2e7f24c77ad865224e8
Reviewed-on: https://go-review.googlesource.com/107300
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-04-16 19:38:57 +00:00
Kir Kolyshkin
04a27bef6f os/user: fix build on darwin with "osusergo" build tag
Fixes #24841
Updates #24845

Change-Id: Ia7e2deefe64c12ee8a76ce6ed9f9e003e912b161
Reviewed-on: https://go-review.googlesource.com/107299
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-16 18:07:04 +00:00
Sebastien Binet
98dfd400e6 os/user: fix build with "osusergo" build tag
Fixes #24841
Updates #24845

Change-Id: I4a5c05f4cbf9692bd6cab48baf3cc51fa43fe5a9
Reviewed-on: https://go-review.googlesource.com/106837
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-13 16:51:18 +00:00
Josh Bleecher Snyder
86181120bd os: allocate buffer lazily in Expand
As an example of why this might happen,
consider this code from cmd/internal/objfile:

// Expand literal "$GOROOT" rewritten by obj.AbsFile()
filename = filepath.Clean(os.ExpandEnv(filename))

In this case, filename might not contain "$GOROOT",
in which case we can skip the buffer entirely.

name               old time/op    new time/op    delta
Expand/noop-8        46.7ns ± 1%    12.9ns ± 1%   -72.47%  (p=0.000 n=9+9)
Expand/multiple-8     139ns ± 1%     137ns ± 1%    -1.36%  (p=0.001 n=10+10)

The Expand/multiple improvement is probably noise.

This speeds up cmd/objdump detectably, if not much.
Using "benchcmd ObjdumpCompile go tool objdump `go tool -n compile`":

name            old time/op       new time/op       delta
ObjdumpCompile        9.35s ± 2%        9.07s ± 3%  -3.00%  (p=0.000 n=18+18)

Updates #24725

Change-Id: Id31ec6a9b8dfb3c0f1db58fe1f958e11c39e656c
Reviewed-on: https://go-review.googlesource.com/106697
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-12 22:18:18 +00:00
Josh Bleecher Snyder
3cb067d70d os: add Expand benchmarks
Change-Id: I68e65591cc50433f97a97027e3ae3b452451adf2
Reviewed-on: https://go-review.googlesource.com/106696
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-12 22:18:08 +00:00
Brad Fitzpatrick
044d2d5af6 os: document that Chown with -1 means to leave values unchanged, like POSIX
And fix the nacl implementation.

Fixes #24710

Change-Id: I31ffeea03a72dac5021ffb183fde31e9ffd060ad
Reviewed-on: https://go-review.googlesource.com/106464
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-11 23:06:44 +00:00
Nick Patavalis
ea5825b0b6 os: use poller when NewFile is called with a blocking descriptor.
If NewFile is called with a file descriptor that is already set to
non-blocking mode, it tries to return a pollable file (one for which
SetDeadline methods work) by adding the filedes to the poll/netpoll
mechanism. If called with a filedes in blocking mode, it returns a
non-pollable file, as it always did.

Fixes #22939
Updates #24331

Change-Id: Id54c8be1b83e6d35e14e76d7df0e57a9fd64e176
Reviewed-on: https://go-review.googlesource.com/100077
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-04-11 17:39:11 +00:00
Kir Kolyshkin
62f0127d81 os/user: add a way to enforce pure Go implementation
This provides a way to enforce pure Go implementation of os/user
lookup functions on UNIX platforms by means of "osusergo" build tag,
in a manner similar to netgo/netcgo tags in the net package.

If "osusergo" build tag is set, Go implementation is selected.

If "osusergo" build tag is NOT set, the old behavior is retained,
that is to use cgo (libc-backed) implementation if both cgo and such
and such implementation are available.

The reason behind this change is to make it possible to build proper
static binaries on Linux. The problem is, glibc implementation of
getpw*, getgrp* and getgrouplist functions relies on presense of
libnss*.so libraries during runtime, making it impossible to build
a self-contained static binary which uses both cgo and os/user.
In such case, linker warnings like this are shown:

> warning: Using 'getgrouplist' in statically linked applications
> requires at runtime the shared libraries from the glibc version
> used for linking

While this can be solved by recompiling glibc with --enable-static-nss
flag or using a different libc implementation (like musl on Alpine Linux),
it is not always practical or even possible.

Fixes #23265

Change-Id: I383a448a2ecf15493ec93dbd5d076b6330cb14cb
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Reviewed-on: https://go-review.googlesource.com/92456
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-06 19:42:41 +00:00
Lubomir I. Ivanov (VMware)
2a16176a47 os/user: obtain a user GID on Windows
Add the following helpers in lookup_windows.go:
1) lookupGroupName() is used to obtain the SID of a group based
on name.
2) listGroupsForUsernameAndDomain() uses NetUserGetLocalGroups()
as a WINAPI backend to obtain the list of local groups for this
user.
3) lookupUserPrimaryGroup() is now used to populate the User.Gid
field when looking up a user by name.

Implement listGroups(), lookupGroupId(), lookupGroup() and no longer
return unimplemented errors.

Do not skip Windows User.Gid tests in user_test.go.

Change-Id: I81fd41b406da51f9a4cb24e50d392a333df81141
GitHub-Last-Rev: d1448fd55d
GitHub-Pull-Request: golang/go#24222
Reviewed-on: https://go-review.googlesource.com/98137
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-04 09:28:39 +00:00
Tobias Klauser
01237b1362 runtime: parse auxv for page size and executable name on Solaris
Decode AT_PAGESZ to determine physPageSize and AT_SUN_EXECNAME for
os.Executable.

Change-Id: I6ff774ad9d76c68fc61eb307df58217c17fd578d
Reviewed-on: https://go-review.googlesource.com/104375
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-03 15:49:45 +00:00
Joe Tsai
dfd7f35626 os: add ModeIrregular flag
There is currently no way for os.FileMode.IsRegular to report false
without being one of the following types:
	ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice

This makes it difficult for custom implementations of os.FileInfo to return
a Mode that is explicitly not regular without resorting to setting one
of the types listed above. However, every one of the aforementioned types
are ill-suited as a general-purpose "not regular" file type.

Thus, add a ModeIrregular to serve exactly for that purpose.
The ModeIrregular type carries no information other than the fact that the
file is not regular.

Updates #22903
Fixes #23878

Change-Id: I4f34d88f960bcb014816d8e7b5de8b1035077948
Reviewed-on: https://go-review.googlesource.com/94856
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-03-29 23:17:53 +00:00
Agniva De Sarker
7bf631e1fc os: keep the $ if a variable is not detected
If the character after $ cannot be detected as a valid
variable declaration, do not gobble the $.

Fixes #24345

Change-Id: Iec47be1f2e4f8147b8ceb64c30778eae8045b58f
Reviewed-on: https://go-review.googlesource.com/103055
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-03-28 18:25:41 +00:00
David du Colombier
49325dc1d2 os: fix TestDevNullFile on Plan 9
CL 102457 added TestDevNullFile. However, this
test is failing on Plan 9, because it checks
that /dev/null is a character device while there
are no special files on Plan 9.

We fix this issue by changing Stat to consider
all files served by the console device (#c)
as character devices.

Fixes #24534.

Change-Id: I1c60cdf25770358b908790b3fb71910fa914dec0
Reviewed-on: https://go-review.googlesource.com/102424
Run-TryBot: David du Colombier <0intro@gmail.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-03-27 05:30:50 +00:00
Alex Brainman
d2dd2e1524 os: do not test Lstat in TestDevNullFile
CL 102456 added Lstat check to TestDevNullFile.
But some systems have /dev/null as a symlink,
so Lstat test is wrong. Remove the test.

Fixes #24521

Change-Id: I149110b08dd05db6495ec4eccbcf943e444332f9
Reviewed-on: https://go-review.googlesource.com/102461
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-03-26 09:23:22 +00:00
Alex Brainman
48c4eeeed7 os: treat "nul" as DevNull file on windows
Also add more tests to test both nul and NUL on windows.

Fixes #24482

Change-Id: I3dfe68ec8de7f90ca869c1096dde0054df3c5cf6
Reviewed-on: https://go-review.googlesource.com/102457
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-03-25 08:33:21 +00:00
Alex Brainman
782f9ce52f os: document DevNull on windows
DevNull is documented on darwin, dragonfly, freebsd, linux,
nacl, netbsd, openbsd, solaris and plan9, but not on windows.
Add missing documentation.

Change-Id: Icdbded0dd5e322ed4360cbce6bee4cdca5cfbe72
Reviewed-on: https://go-review.googlesource.com/102456
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-03-25 00:45:33 +00:00
Alex Brainman
e83601b435 os: use WIN32_FIND_DATA.Reserved0 to identify symlinks
os.Stat implementation uses instructions described at
https://blogs.msdn.microsoft.com/oldnewthing/20100212-00/?p=14963/
to distinguish symlinks. In particular, it calls
GetFileAttributesEx or FindFirstFile and checks
either WIN32_FILE_ATTRIBUTE_DATA.dwFileAttributes
or WIN32_FIND_DATA.dwFileAttributes to see if
FILE_ATTRIBUTES_REPARSE_POINT flag is set.
And that seems to worked fine so far.

But now we discovered that OneDrive root folder
is determined as directory:

c:\>dir C:\Users\Alex | grep OneDrive
30/11/2017  07:25 PM    <DIR>          OneDrive
c:\>

while Go identified it as symlink.

But we did not follow Microsoft's advice to the letter - we never
checked WIN32_FIND_DATA.Reserved0. And adding that extra check
makes Go treat OneDrive as symlink. So use FindFirstFile and
WIN32_FIND_DATA.Reserved0 to determine symlinks.

Fixes #22579

Change-Id: I0cb88929eb8b47b1d24efaf1907ad5a0e20de83f
Reviewed-on: https://go-review.googlesource.com/86556
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-03-07 08:51:04 +00:00
Ian Lance Taylor
558769a61b internal/poll: if poller init fails, assume blocking mode
Fixes #23943

Change-Id: I16e604872f1615963925ec3c4710106bcce1330c
Reviewed-on: https://go-review.googlesource.com/99015
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-03-06 23:21:25 +00:00
Yury Smolsky
adcf2d59ec os/exec: document Process.Kill behaviour
It is not clear from documentation what the Process.Kill does. And it
leads to reccuring confusion about Cmd.Start/Wait methods.

Fixes #24220

Change-Id: I66609d21d2954e195d13648014681530eed8ea6c
Reviewed-on: https://go-review.googlesource.com/98715
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-03-05 23:47:41 +00:00
Andrey Mirtchovski
43b6476262 os/signal: disable loading of history during test
This change modifies Go to disable loading of users' shell history for
TestTerminalSignal tests. TestTerminalSignal, as part of its workload,
will execute a new interactive bash shell. Bash will attempt to load the
user's history from the file pointed to by the HISTFILE environment
variable. For users with large histories that may take up to several
seconds, pushing the whole test past the 5 second timeout and causing
it to fail.

Change-Id: I11b2f83ee91f51fa1e9774a39181ab365f9a6b3a
GitHub-Last-Rev: 7efdf616a2
GitHub-Pull-Request: golang/go#24255
Reviewed-on: https://go-review.googlesource.com/98616
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-03-05 21:03:33 +00:00
Tobias Klauser
2013ad897d os, syscall: use pipe2 instead of pipe syscall on OpenBSD
The pipe2 syscall is part of OpenBSD since version 5.7 and thus exists in
all officially supported versions.

Follows CL 38426 and CL 94035

Change-Id: I8f93ecbc89664241f1b6b0d069e948776941b1d0
Reviewed-on: https://go-review.googlesource.com/97356
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-02-27 18:37:36 +00:00
Tobias Klauser
ad9814de61 os: unify supportsCloseOnExec definition
On Darwin and FreeBSD, supportsCloseOnExec is defined in its own file,
even though it is set to true as on other Unices. Drop the separate
definitions but keep the accompanying comments.

Change-Id: Iab1d20e1b2590800f141d54b55a099c9cd7ae57e
Reviewed-on: https://go-review.googlesource.com/97155
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-02-26 17:10:24 +00:00
Alex Brainman
9cae3aaf47 os: do not forget to set ModeDevice when using ModeCharDevice
Fixes #23123

Change-Id: Ia4ac947cc49ef3d150ef60a095b86552dcef397d
Reviewed-on: https://go-review.googlesource.com/84435
Reviewed-by: Giovanni Bajo <rasky@develer.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Giovanni Bajo <rasky@develer.com>
2018-02-26 17:02:29 +00:00
Kevin Burke
db7af2e67b os/user: clean up grammar in comments
Change-Id: If9fe04894851d60a682346415c2e5523b2f04929
Reviewed-on: https://go-review.googlesource.com/96981
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2018-02-26 16:57:47 +00:00
Lubomir I. Ivanov (VMware)
7a218942be os/user: obtain a user home path on Windows
newUserFromSid() is extended so that the retriaval of the user home
path based on a user SID becomes possible.

(1) The primary method it uses is to lookup the Windows registry for
the following key:
  HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\[SID]

If the key does not exist the user might not have logged in yet.
If (1) fails it falls back to (2)

(2) The second method the function uses is to look at the default home
path for users (e.g. WINAPI's GetProfilesDirectory()) and append
the username to that. The procedure is in the lines of:
  c:\Users + \ + <username>

The function newUser() now requires the following arguments:
  uid, gid, dir, username, domain
This is done to avoid multiple calls to usid.String() and
usid.LookupAccount("") in the case of a newUserFromSid()
call stack.

The functions current() and newUserFromSid() both call newUser()
supplying the arguments in question. The helpers
lookupUsernameAndDomain() and findHomeDirInRegistry() are
added.

This commit also updates:
- go/build/deps_test.go, so that the test now includes the
"internal/syscall/windows/registry" import.
- os/user/user_test.go, so that User.HomeDir is tested on Windows.

GitHub-Last-Rev: 25423e2a38
GitHub-Pull-Request: golang/go#23822
Change-Id: I6c3ad1c4ce3e7bc0d1add024951711f615b84ee5
Reviewed-on: https://go-review.googlesource.com/93935
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-02-24 23:13:03 +00:00
Yuval Pavel Zholkover
a5e8e2d998 os: respect umask in Mkdir and OpenFile on BSD systems when perm has ModeSticky set
Instead of calling Chmod directly on perm, stat the created file/dir to extract the
actual permission bits which can be different from perm due to umask.

Fixes #23120.

Change-Id: I3e70032451fc254bf48ce9627e98988f84af8d91
Reviewed-on: https://go-review.googlesource.com/84477
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-02-23 22:37:55 +00:00
Ian Lance Taylor
b86e766813 path: use OS-specific function in MkdirAll, don't always keep trailing slash
CL 86295 changed MkdirAll to always pass a trailing path separator to
support extended-length paths on Windows.

However, when Stat is called on an existing file followed by trailing
slash, it will return a "not a directory" error, skipping the fast
path at the beginning of MkdirAll.

This change fixes MkdirAll to only pass the trailing path separator
where required on Windows, by using an OS-specific function fixRootDirectory.

Updates #23918

Change-Id: I23f84a20e65ccce556efa743d026d352b4812c34
Reviewed-on: https://go-review.googlesource.com/95255
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2018-02-23 18:37:09 +00:00
Richard Miller
a156fc08b7 syscall: ensure Mkdir(path) on Plan 9 fails if path exists
On Plan 9, the underlying create() syscall with DMDIR flag, which is
used to implement Mkdir, will fail silently if the path exists and
is not a directory.  Work around this by checking for existence
first and rejecting Mkdir with error EEXIST if the path is found.

Fixes #23918

Change-Id: I439115662307923c9f498d3e7b1f32c6d205e1ad
Reviewed-on: https://go-review.googlesource.com/94777
Reviewed-by: David du Colombier <0intro@gmail.com>
2018-02-20 13:21:12 +00:00
Mansour Rahimi
7a1347a1a1 os: make MkdirAll support path in extended-length form
Calling MkdirAll on paths in extended-length form (\\?\-prefixed)
failed.

MkdirAll calls itself recursively with parent directory of given path in
its parameter. It finds parent directory by looking for delimiter in
the path, and taking the left part. When path is in extended-length form,
it finds empty path at the end.

Here is a sample of path in extended-length form:
\\?\c:\foo\bar

This change fixes that by passing trailing path separator to MkdirAll (so
it works for path like \\?\c:\).

Fixes #22230

Change-Id: I363660b262588c5382ea829773d3b6005ab8df3c
Reviewed-on: https://go-review.googlesource.com/86295
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-02-18 03:44:53 +00:00
Mikio Hara
d50bb8dbb9 all: drop support for Windows Vista or below (Windows XP)
Per the notice in the Go 1.10 release notes, this change drops the
support for Windows Vista or below (including Windows XP) and
simplifies the code for the sake of maintenance.

There is one exception to the above. The code related to DLL and
system calls still remains in the runtime package. The remaining code
will be refined and used for supporting upcoming Windows versions in
future.

Updates #17245
Fixes #23072

Change-Id: I9e2821721f25ef9b83dfbf85be2b7ee5d9023aa5
Reviewed-on: https://go-review.googlesource.com/94255
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-02-15 17:24:42 +00:00
Tobias Klauser
eab06e65f7 syscall, os: use pipe2 syscall on NetBSD instead of pipe
The pipe2 syscall is part of NetBSD since version 6.0 and thus exists in
all officially supported versions (6.0 through 6.1 and 7.0+).

Follows CL 38426

Change-Id: I7b62b507300c3dfbcc6ae56408a7d7088ddccc77
Reviewed-on: https://go-review.googlesource.com/94035
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-02-14 15:51:46 +00:00
Andrew Bonventre
816154b065 os: add UserCacheDir
Adds a function that returns an OS-dependent location
for user-specific cache data.

Fixes golang/go#22536

Change-Id: Ifff015452494571ad357fa2d945d66a5992c751d
Reviewed-on: https://go-review.googlesource.com/78835
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-02-13 07:01:26 +00:00
Michael Hudson-Doyle
03e10bd9c4 os/signal: skip TestTerminalSignal if posix_openpt fails with EACCES
This happens in a chroot and so causes failures when packaging Go 1.10 for
Debian/Ubuntu.

Change-Id: I817038c237e584ce185b2168f8c7a10b9ef27b43
Reviewed-on: https://go-review.googlesource.com/90875
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-01-31 00:50:06 +00:00
Austin Clements
3ee8c3cc0b os: document inheritance of thread state over exec
Fixes #23570.

Change-Id: I462ada2960d710c2c94dc22a59d292703d83f612
Reviewed-on: https://go-review.googlesource.com/90255
Reviewed-by: Russ Cox <rsc@golang.org>
2018-01-26 18:54:04 +00:00
Richard Miller
e72e69a3f6 os: use the syscall version of Getwd for Plan 9
In Plan 9, each OS thread has its own independent working directory,
so the Go runtime for Plan 9 needs to coordinate Chdir and Getwd
operations to keep the working directory consistent for all goroutines.

The function os.Getwd in Plan 9 should always call syscall.Getwd
to retrieve the common working directory.  Failure to do this was
the cause of (at least some of) the intermittent failures in the
Plan 9 builders with a seemingly spurious "file does not exist"
message, when a thread's working directory had been removed in
another thread.

Change-Id: Ifb834ad025ee39578234ad3b04d08bc98e939291
Reviewed-on: https://go-review.googlesource.com/89575
Reviewed-by: David du Colombier <0intro@gmail.com>
Run-TryBot: David du Colombier <0intro@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-01-25 00:12:18 +00:00
David du Colombier
157d8cfbc1 os: homogenize error checks on Plan 9
Remove leading space at the beginning of error strings,
so the strings are consistent between isExist, isNotExist
and isPermission functions.

Here is a list of error strings returned on the most common
file servers on Plan 9:

     match                     cwfs                      fossil                   ramfs

"exists"            "create/wstat -- file exists"  "file already exists"    "file exists"
"is a directory"                                   "is a directory"         "file is a directory"

"does not exist"                                   "file does not exist"    "file does not exist"
"not found"         "directory entry not found"
"has been removed"                                 "file has been removed"

"permission denied" "access permission denied"     "permission denied"      "permission denied"

"no parent" is an error returned by lib9p when removing a file without parent.

Change-Id: I2362ed4b6730b8bec7a707a1052bd1ad8921cd97
Reviewed-on: https://go-review.googlesource.com/89315
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-01-24 07:18:36 +00:00
Fazlul Shahriar
99e6e482f4 os: handle ' is a directory' error as IsExist on Plan 9
This error is returned by os.Mkdir when the directory already exists.

This change fixes some upspin tests.

Change-Id: I9ad5aefebb32dff577726d537b4f3826d79868eb
Reviewed-on: https://go-review.googlesource.com/88656
Reviewed-by: David du Colombier <0intro@gmail.com>
Run-TryBot: David du Colombier <0intro@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-01-23 07:52:44 +00:00
Daniel Martí
c203696aa5 go/importer,os/exec: use testenv.GoToolPath
These were the last two occurences of exec.Command("go", ...) in all of
std cmd. Checked with:

	gogrep '$(f is(func))("go", $*_)' std cmd

Also changed lp_windows_test to use a test package name to avoid a
circular dependency, since internal/testenv imports os/exec.

Change-Id: I9a18948600dfecc8507ad76172e219e78b791ffd
Reviewed-on: https://go-review.googlesource.com/87200
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-01-10 20:24:15 +00:00
Brad Fitzpatrick
c5d744a4f6 os/exec: skip TestContextCancel on the Windows XP builder
Updates #17245

Change-Id: I3d7ea362809040fbbba4b33efd57bf2d27d4c390
Reviewed-on: https://go-review.googlesource.com/87257
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-01-10 19:59:44 +00:00
Russ Cox
de292613c1 os: fix grammar nit
There should not be a comma before "and" in the original text,
because what follows is not a complete sentence. Rewrite.

Change-Id: Ie99f204cc87e911fb46149e2eb65e132fa1eb63a
Reviewed-on: https://go-review.googlesource.com/87020
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-01-09 23:59:31 +00:00
Brad Fitzpatrick
0770aaca35 os: document that StartProcess's argv starts with the binary name
Fixes #23277

Change-Id: Idbe09913c95dc951b9b195eb7ff1e75d2bb4d63d
Reviewed-on: https://go-review.googlesource.com/85675
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-12-30 21:59:34 +00:00
Matthijs Kooijman
eda703ac79 os: mention the influence of umask in docs
Change-Id: Ia05fac3298334d6b44267ce02bffcd7bf8a54c72
Reviewed-on: https://go-review.googlesource.com/83775
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-12-15 21:07:41 +00:00
Wèi Cōngruì
e28a0d397b os: don't wait for Close if the File was returned by NewFile
os.NewFile doesn't put the fd into non-blocking mode.
In most cases, an *os.File returned by os.NewFile is in blocking mode.

Updates #7970
Updates #21856
Updates #23111

Change-Id: Iab08432e41f7ac1b5e25aaa8855d478adb7f98ed
Reviewed-on: https://go-review.googlesource.com/83995
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-12-14 05:54:46 +00:00
Ian Lance Taylor
0f3ab149ec net, os: don't wait for Close in blocking mode
Updates #7970
Updates #21856
Updates #23111

Change-Id: I0cd0151fcca740c40c3c976f941b04e98e67b0bf
Reviewed-on: https://go-review.googlesource.com/83715
Reviewed-by: Russ Cox <rsc@golang.org>
2017-12-14 02:02:10 +00:00
Ian Lance Taylor
ddae7fb1e8 os: don't use test logger for Getwd
Otherwise, on systems for which syscall does not implement Getwd,
a lot of unnecessary files and directories get added to the testlog,
right up the root directory. This was causing tests on such systems
to fail to cache in practice.

Updates #22593

Change-Id: Ic8cb3450ea62aa0ca8eeb15754349f151cd76f85
Reviewed-on: https://go-review.googlesource.com/83455
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-12-12 04:26:40 +00:00
Russ Cox
29be20a111 cmd/go: invalidate cached test results if env vars or files change
When we write a cached test result, we now also write a log of the
environment variables and files inspected by the test run,
along with a hash of their content. Before reusing a cached test result,
we recompute the hash of the content specified by the log, and only
use the result if that content has not changed.

This makes test caching behave correctly for tests that consult
environment variables or stat or read files or directories.

Fixes #22593.

Change-Id: I8608798e73c90e0c1911a38bf7e03e1232d784dc
Reviewed-on: https://go-review.googlesource.com/81895
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-12-11 19:08:32 +00:00
Tobias Klauser
b3a108879f os: fix typo in TestExecutable comment
Change-Id: I2ad5d73deaee57ccbb2c75378dcc2884e43be3bb
Reviewed-on: https://go-review.googlesource.com/82899
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-12-09 15:49:34 +00:00
Brad Fitzpatrick
7c46b62d0a syscall: make Seek use SetFilePointerEx on Windows, allowing large seek offsets
Fixes #21681
Updates #21728

Change-Id: I79cf4564c1355ecab891102d4215cbbffd8eb0ce
Reviewed-on: https://go-review.googlesource.com/82535
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-12-07 19:32:24 +00:00
Brad Fitzpatrick
871b79316a os: clarify docs on Interrupt and Kill
Note that Interrupt will compile but not work on Windows.

Fixes #22454

Change-Id: If011c32211f4bb45d458317e113b9794d5b4a4b1
Reviewed-on: https://go-review.googlesource.com/81035
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-12-02 02:49:01 +00:00
Ian Lance Taylor
415349575d os: calling Fd disables the SetDeadline methods
The full truth seems too complicated to write in this method's doc, so
I'm going with a simple half truth.

The full truth is that Fd returns the descriptor in blocking mode,
because that is historically how it worked, and existing programs
would be surprised if the descriptor is suddenly non-blocking. On Unix
systems whether a file is non-blocking or not is a property of the
underlying file description, not of a particular file descriptor, so
changing the returned descriptor to blocking mode also changes the
existing File to blocking mode. Blocking mode works fine, althoug I/O
operations now take up a thread. SetDeadline and friends rely on the
runtime poller, and the runtime poller only works if the descriptor is
non-blocking. So it's correct that calling Fd disables SetDeadline.
The other half of the truth is that if the program is willing to work
with a non-blocking descriptor, it could call
syscall.SetNonblock(descriptor, true) to change the descriptor, and
the original File, to non-blocking mode. At that point SetDeadline
would start working again. I tried to write that in a way that is
short and comprehensible but failed. Since deadlines mostly work on
pipes, and there isn't much reason to call Fd on a pipe, and few
people use SetDeadline, I decided to punt.

Fixes #22934

Change-Id: I2e49e036f0bcf71f5365193831696f9e4120527c
Reviewed-on: https://go-review.googlesource.com/81636
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-12-02 02:11:15 +00:00
Tobias Klauser
08176b28a3 os: drop unused return value in TestLookupEnv
Change-Id: Ibf227dcfefa179b1c3378476bcd17100b1b1c01e
Reviewed-on: https://go-review.googlesource.com/81375
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-12-01 15:43:52 +00:00
Brad Fitzpatrick
d4f48e3ff9 os: ignore Chtimes test failure on NetBSD if fs mounted noatime
Fixes #19293

Change-Id: I35f2f786e2e3972eda21ba5a948433bfcd621269
Reviewed-on: https://go-review.googlesource.com/81355
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-12-01 04:25:22 +00:00
Tobias Klauser
45c57e5907 os: remove redundant GOOS checks in chown tests
The build tags already prevent the tests from being run on windows or
plan9, so there is no need to check GOOS again.

Change-Id: I74d3c3b7756d9c50f6e5fd4c3e8b0db618fdebbb
Reviewed-on: https://go-review.googlesource.com/81295
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-30 23:34:49 +00:00
Ian Lance Taylor
eb97160f46 runtime: don't block signals that will kill the program
Otherwise we may delay the delivery of these signals for an arbitrary
length of time. We are already careful to not block signals that the
program has asked to see.

Also make sure that we don't miss a signal delivery if a thread
decides to stop for a while while executing the signal handler.

Also clean up the TestAtomicStop output a little bit.

Fixes #21433

Change-Id: Ic0c1a4eaf7eba80d1abc1e9537570bf4687c2434
Reviewed-on: https://go-review.googlesource.com/79581
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2017-11-30 23:29:30 +00:00
Brad Fitzpatrick
8064f82a15 Revert "os: remove skipped test on netbsd"
This reverts commit a631daba5f.

Reason for revert: I was wrong. It still fails on the builders.

I don't know what's different about my VMWare VM, but on GCE it fails.

Change-Id: Ic6bee494b69235768bf08ba0bf59026bca41ad12
Reviewed-on: https://go-review.googlesource.com/80915
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-30 03:32:05 +00:00
Brad Fitzpatrick
a631daba5f os: remove skipped test on netbsd
It must've been fixed since NetBSD 7.0. I can no longer reproduce it
with NetBSD 8-BETA (our new minimum NetBSD requirement).

Fixes #19293

Change-Id: I28f970ca41a53a037e1c6cddf1b7f286bda2d725
Reviewed-on: https://go-review.googlesource.com/80875
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-11-30 01:12:23 +00:00
Tobias Klauser
06d87bf854 os: correct err check in TestChdirAndGetwd
Due to err being shadowed in the else brach, the actual err return of
fd1.Chdir() is never checked. Fix it by not shadowing err anymore.

Change-Id: I9f1d52e88d8bc9a1c035960aa7af9f5224a63ab0
Reviewed-on: https://go-review.googlesource.com/80556
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-11-29 15:53:14 +00:00
Mikio Hara
e76ae8af92 all: drop support for FreeBSD 9 or below
This change drops the support for FreeBSD 9 or below and simplifies
platform-dependent code for the sake of maintenance.

Updates #7187.
Fixes #11412.
Updates #16064.
Updates #18854.
Fixes #19072.

Change-Id: I9129130aafbfc7d0d7e9b674b6fc6cb31b7381be
Reviewed-on: https://go-review.googlesource.com/64910
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-11-28 18:57:25 +00:00
Tom Lanyon
c866110689 os/exec: Stdout/Stderr doc cleanup.
Following comments on CL 76320.

Breaks Cmd.Std{out,err} doc into three paragraphs and updates Cmd.Stdin
formatting to match.

Fixes an erroneous reference to Stdin in the output goroutine comment, while
keeping the wording consistent between Stdin and Stdout/Stderr.

Change-Id: I186a0e2d4b85dfb939443a17e62a1eb2ef64b1bf
Reviewed-on: https://go-review.googlesource.com/79595
Reviewed-by: Rob Pike <r@golang.org>
2017-11-23 20:01:56 +00:00
Ian Lance Taylor
571ee0436f os/signal: don't run TestTerminalSignal on Android
At least some versions of the Android libc do not define posix_openpt.

Updates #22845

Change-Id: Id21705f47ef0f9694313a7dc7351a952d48d407b
Reviewed-on: https://go-review.googlesource.com/79399
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-23 00:34:48 +00:00
Tom Lanyon
5051671c7e os/exec: update docs for cmd.Std{out,err} and cmd.Wait to clarify how copying is done
Fixes #22610.

Change-Id: I172fe1d1941a8a2750af7ee75f7af7e81a702c40
Reviewed-on: https://go-review.googlesource.com/76320
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-11-22 23:18:02 +00:00
Ian Lance Taylor
c6c0f47e92 os/signal: fix t.Fatal that should be t.Fatalf
Change-Id: I2a24b2bde9a7c641b3bc802ff8b2ddebf4990109
Reviewed-on: https://go-review.googlesource.com/79496
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dave Cheney <dave@cheney.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-11-22 21:16:29 +00:00
Ian Lance Taylor
9adfe0f475 os/signal: don't run TestTerminalSignal on Solaris
Fixes #22849

Change-Id: Icf7f07d0d1d0669f5db4943030588646c819c62a
Reviewed-on: https://go-review.googlesource.com/79495
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-11-22 20:58:08 +00:00
Ian Lance Taylor
6ecd843e7c os/signal: make TestTerminalSignal more reliable
Look for program output and shell prompt to see when to continue.

Updates #22845

Change-Id: I44ed1908861f3b0dc098aee9a401324b77268921
Reviewed-on: https://go-review.googlesource.com/79395
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Munday <mike.munday@ibm.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-22 19:19:02 +00:00
Kevin Burke
f100e0c228 os/user: fix darwin GetGroupIds for n > 256
If a Mac user has more than 256 groups, getGroupList returns -1 but
does not correctly set n. We need to retry the syscall with an
ever-increasing group size until we get all of the user's groups.

The easiest way to test this change is to set n to a value lower than
the current user's number of groups, test on a Mac and observe
a failure, then apply the patch and test that it passes.

Fixes #21067.

Change-Id: I0f5c4eac1c465226a460bc0803eff791dcfd4200
Reviewed-on: https://go-review.googlesource.com/51892
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-11-22 17:14:47 +00:00
Ian Lance Taylor
3fec6da0ab internal/poll: loop on EINTR in Read on Darwin
Test is in os/signal package because the problem is signal related.

Fixes #22838.

Change-Id: I223eeebb5fbc972910737eddef8ab9784cb984a6
Reviewed-on: https://go-review.googlesource.com/79215
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-22 02:27:19 +00:00
Brad Fitzpatrick
7edb721fbc os/user: handle large 32-bit uid/gid values when stringifying User.Uid/Gid
Fixes #22739

Change-Id: I374c29d237c498c9e5ac848b01f6d49d7c41b31f
Reviewed-on: https://go-review.googlesource.com/77930
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-11-16 18:42:02 +00:00
Tim Wright
37b15baa3b syscall: fix NaCl Link syscall error handling
The existing NaCl filesystem Link system call erroneously allowed
a caller to call Link on an existing target which violates the POSIX
standard and effectively corrupted the internal filesystem
representation.

Fixes #22383

Change-Id: I77b16c37af9bf00a1799fa84277f066180edac47
Reviewed-on: https://go-review.googlesource.com/76110
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-06 16:36:34 +00:00
David du Colombier
32f994acc6 os: fix RemoveAll on large directories on Plan 9 and NaCl
On Plan 9, some file servers, like ramfs, handle the read
offset when reading directories. However, the offset isn't
valid anymore after directory entries have been removed
between successive calls to read.

This issue happens when os.RemoveAll is called on a
directory that doesn't fit on a single 9P response message.

In this case, the first part of the directory is read,
then directory entries are removed and the second read
will be incomplete because the read offset won't be valid
anymore. Consequently, the content of the directory will
only be partially removed.

We change RemoveAll to call fd.Seek(0, 0) before calling
fd.Readdirnames, so the read offset will always be reset
after removing the directory entries.

After adding TestRemoveAllLarge, we noticed the same issue
appears on NaCl and the same fix applies as well.

Fixes #22572.

Change-Id: Ifc76ea7ccaf0168c34dc8ec0f400dc04db1baf8f
Reviewed-on: https://go-review.googlesource.com/75974
Run-TryBot: David du Colombier <0intro@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-06 07:09:50 +00:00
Leigh McCulloch
8db19a4966 all: change github.com issue links to golang.org
The go repository contains a mix of github.com/golang/go/issues/xxxxx
and golang.org/issues/xxxxx URLs for references to issues in the issue
tracker. We should use one for consistency, and golang.org is preferred
in case the project moves the issue tracker in the future.

This reasoning is taken from a comment Sam Whited left on a CL I
recently opened: https://go-review.googlesource.com/c/go/+/73890.

In that CL I referenced an issue using its github.com URL, because other
tests in the file I was changing contained references to issues using
their github.com URL. Sam Whited left a comment on the CL stating I
should change it to the golang.org URL.

If new code is intended to reference issues via golang.org and not
github.com, existing code should be updated so that precedence exists
for contributors who are looking at the existing code as a guide for the
code they should write.

Change-Id: I3b9053fe38a1c56fc101a8b7fd7b8f310ba29724
Reviewed-on: https://go-review.googlesource.com/75673
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-04 04:13:41 +00:00
Russ Cox
0d18875252 cmd/go: run vet automatically during go test
This CL adds an automatic, limited "go vet" to "go test".
If the building of a test package fails, vet is not run.
If vet fails, the test is not run.
The goal is that users don't notice vet as part of the "go test"
process at all, until vet speaks up and says something important.
This should help users find real problems in their code faster
(vet can just point to them instead of needing to debug a
test failure) and expands the scope of what kinds of things
vet can help with.

The "go vet" runs in parallel with the linking of the test binary,
so for incremental builds it typically does not slow the overall
"go test" at all: there's spare machine capacity during the link.

all.bash has less spare machine capacity. This CL increases
the time for all.bash on my laptop from 4m41s to 4m48s (+2.5%)

To opt out for a given run, use "go test -vet=off".

The vet checks used during "go test" are a subset of the full set,
restricted to ones that are 100% correct and therefore acceptable
to make mandatory. In this CL, that set is atomic, bool, buildtags,
nilfunc, and printf. Including printf is debatable, but I want to
include it for now and find out what needs to be scaled back.
(It already found one real problem in package os's tests that
previous go vet os had not turned up.)
Now that we can rely on type information it may be that printf
should make its function-name-based heuristic less aggressive
and have a whitelist of known print/printf functions.
Determining the exact set for Go 1.10 is #18085.

Running vet also means that programs now have to type-check
with both cmd/compile and go/types in order to pass "go test".
We don't start vet until cmd/compile has built the test package,
so normally the added go/types check doesn't find anything.
However, there is at least one instance where go/types is more
precise than cmd/compile: declared and not used errors involving
variables captured into closures.

This CL includes a printf fix to os/os_test.go and many declared
and not used fixes in the race detector tests.

Fixes #18084.

Change-Id: I353e00b9d1f9fec540c7557db5653e7501f5e1c9
Reviewed-on: https://go-review.googlesource.com/74356
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-11-03 22:09:38 +00:00
Ian Lance Taylor
86b7721ce3 os: rearrange OpenFile Flags doc
Updates #21322

Change-Id: Ib03ee9dbe1b44c2fecd51f2f2c23a88482158e7e
Reviewed-on: https://go-review.googlesource.com/75250
Reviewed-by: Rob Pike <r@golang.org>
2017-11-01 21:28:43 +00:00
Radek Sohlich
66764cc5b3 os/signal: improve documentation for the Notify function
It is easy to miss the documentation information that no arguments
in the Notify function means that the Notify will catch all possible signals.
So the example was added with explicit comment above the Notify usage.

Fixes #22257

Change-Id: Ia6a16dd4a419f7c77d89020ca5db85979b5b474e
Reviewed-on: https://go-review.googlesource.com/74730
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-11-01 18:38:23 +00:00
Ian Lance Taylor
94d9371780 os: clarify that OpenFile reqires one of O_RDONLY/O_WRONLY/O_RDWR
Fixes #21322.

Change-Id: Ia589c576be0b5cdb7cde5d35cd857ad7c93c372b
Reviewed-on: https://go-review.googlesource.com/74550
Reviewed-by: Robert Griesemer <gri@golang.org>
2017-10-31 03:23:10 +00:00
Ian Lance Taylor
187957d370 os: add deadline methods for File type
Add SetDeadline, SetReadDeadline, and SetWriteDeadline methods to os.File,
just as they exist today for the net package.

Fixes #22114

Change-Id: I4d390d739169b991175baba676010897dc8568fa
Reviewed-on: https://go-review.googlesource.com/71770
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2017-10-25 18:27:06 +00:00
Alex Brainman
6407b3c80e os: simplify windows Pipe
windows version of Pipe function is implemented by calling
syscall.Pipe which returns handles inheritable by client process,
and then adjusting returned handles with syscall.CloseOnExec.

Just create non-inheritable handles in the first place.
Now that we don't have a race window in the code, drop use
of syscall.ForkLock.

Change-Id: Ie325da7c2397b5995db4a5ddb0117e2ce1745187
Reviewed-on: https://go-review.googlesource.com/72010
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-10-21 00:22:33 +00:00
Tim Cooper
5d168a90d9 os: add period at end of O_EXCL comment
Change-Id: I9d723e49bf2cabf97a09e29e46fd2c426845fd1d
Reviewed-on: https://go-review.googlesource.com/71470
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-17 23:30:52 +00:00
Marvin Stenger
d153df8e4b all: revert "all: prefer strings.LastIndexByte over strings.LastIndex"
This reverts https://golang.org/cl/66372.

Updates #22148

Change-Id: I3e94af3dfc11a2883bf28e1d5e1f32f98760b3ee
Reviewed-on: https://go-review.googlesource.com/68431
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-05 23:19:42 +00:00
Marvin Stenger
90d71fe99e all: revert "all: prefer strings.IndexByte over strings.Index"
This reverts https://golang.org/cl/65930.

Fixes #22148

Change-Id: Ie0712621ed89c43bef94417fc32de9af77607760
Reviewed-on: https://go-review.googlesource.com/68430
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-05 23:19:10 +00:00
Alex Brainman
66c03d39f3 path/filepath: re-implement windows EvalSymlinks
CL 41834 used approach suggested by Raymond Chen in
https://blogs.msdn.microsoft.com/oldnewthing/20100212-00/?p=14963/
to implement os.Stat by getting Windows I/O manager
follow symbolic links.

Do the same for filepath.EvalSymlinks, when existing
strategy fails.

Updates #19922
Fixes #20506

Change-Id: I15f3d3a80256bae86ac4fb321fd8877e84d8834f
Reviewed-on: https://go-review.googlesource.com/55612
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-05 04:16:00 +00:00
Marvin Stenger
d2826d3e06 all: prefer strings.LastIndexByte over strings.LastIndex
strings.LastIndexByte was introduced in go1.5 and it can be used
effectively wherever the second argument to strings.LastIndex is
exactly one byte long.

This avoids generating unnecessary string symbols and saves
a few calls to strings.LastIndex.

Change-Id: I7b5679d616197b055cffe6882a8675d24a98b574
Reviewed-on: https://go-review.googlesource.com/66372
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-27 00:54:24 +00:00
Alex Brainman
8e2d90dca8 internal/poll: be explicit when using runtime netpoller
internal/poll package assumes that only net sockets use runtime
netpoller on windows. We get memory corruption if other file
handles are passed into runtime poller. Make FD.Init receive
and use useNetpoller argument, so FD.Init caller is explicit
about using runtime netpoller.

Fixes #21172

Change-Id: I60e2bfedf9dda9b341eb7a3e5221035db29f5739
Reviewed-on: https://go-review.googlesource.com/65810
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-09-26 04:39:19 +00:00
Marvin Stenger
f22ba1f247 all: prefer strings.IndexByte over strings.Index
strings.IndexByte was introduced in go1.2 and it can be used
effectively wherever the second argument to strings.Index is
exactly one byte long.

This avoids generating unnecessary string symbols and saves
a few calls to strings.Index.

Change-Id: I1ab5edb7c4ee9058084cfa57cbcc267c2597e793
Reviewed-on: https://go-review.googlesource.com/65930
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-25 17:35:41 +00:00
Ian Lance Taylor
9f7fd893dc os: don't refer directly to Sysfd in epipecheck
Instead record in the File whether it is stdout/stderr. This avoids a
race between a call to epipecheck and closing the file.

Fixes #21994

Change-Id: Ic3d552ffa83402136276bcb5029ec3e6691042c2
Reviewed-on: https://go-review.googlesource.com/65750
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-09-24 14:25:50 +00:00
Ian Lance Taylor
8cb2952f2f os/exec: remove protection against simultaneous Wait/Write
CL 31148 added code to protect again simultaneous calls to Close and
Wait when using the standard input pipe, to fix the race condition
described in issue #9307. That issue is a special case of the race
between Close and Write described by issue #7970. Since issue #7970
was not fixed, CL 31148 fixed the problem specific to os/exec.

Since then, issue #7970 has been fixed, so the specific fix in os/exec
is no longer necessary. Remove it, effectively reverting CL 31148 and
followup CL 33298.

Updates #7970
Updates #9307
Updates #17647

Change-Id: Ic0b62569cb0aba44b32153cf5f9632bd1f1b411a
Reviewed-on: https://go-review.googlesource.com/65490
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Miguel Bernabeu <miguelbernadi@gmail.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Joe Tsai <joetsai@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-09-22 21:10:07 +00:00
Hiroshi Ioka
fb54abe9ce all: correct location of go tool
In general, there are no guarantee that `go` command exist on $PATH.
This CL tries to get `go` command from $GOROOT/bin instead.

There are three kinds of code we should handle:
    For normal code, the CL implements goCmd() or goCmdName().
    For unit tests, the CL uses testenv.GoTool() or testenv.GoToolPath().
    For integration tests, the CL sets PATH=$GOROOT/bin:$PATH in cmd/dist.

Note that make.bash sets PATH=$GOROOT/bin:$PATH in the build process.
So this change is only useful when we use toolchain manually.

Updates #21875

Change-Id: I963b9f22ea732dd735363ececde4cf94a5db5ca2
Reviewed-on: https://go-review.googlesource.com/64650
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-20 03:54:16 +00:00
Kunpei Sakai
5a986eca86 all: fix article typos
a -> an

Change-Id: I7362bdc199e83073a712be657f5d9ba16df3077e
Reviewed-on: https://go-review.googlesource.com/63850
Reviewed-by: Rob Pike <r@golang.org>
2017-09-15 02:39:16 +00:00
Ian Lance Taylor
29415eb2b9 os: avoid crashing with a thundering herd in TestPipeThreads
Fixes #21559

Change-Id: I3393c4bee4c84fe0724a9c9aeb1a809b1a92eea6
Reviewed-on: https://go-review.googlesource.com/63650
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Joe Tsai <joetsai@google.com>
2017-09-13 22:53:09 +00:00
Ron Minnich
0cf7e54f2f os: don't assume /bin/pwd in test, find it in $PATH
There are several distros now that no longer have /bin.
Instead of assuming /bin/pwd, we will look for it in $PATH.

Fixes #21684.

Change-Id: I61478326500edeadc3c26803990550dad00c7971
Signed-off-by: Ron Minnich <rminnich@gmail.com>
Reviewed-on: https://go-review.googlesource.com/60010
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-08-29 20:08:16 +00:00
Bryan C. Mills
d5b0ec858b {net,os/user,plugin}: eliminate unnecessary C round-trips
We're making two extra round-trips to C to malloc and free strings
that originate in Go and don't escape. Skip those round-trips by
allocating null-terminated slices in Go memory instead.

Change-Id: I9e4c5ad999a7924ba50b82293c52073ec75518be
Reviewed-on: https://go-review.googlesource.com/56530
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-17 18:14:16 +00:00
Johnny Luo
5125a96710 os: remove duplicate check from windows os.Stat
Fixes #21075

Change-Id: Idfe5002dfe17943844d9427e27f82ce894b92e80
Reviewed-on: https://go-review.googlesource.com/50270
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-07-20 07:43:15 +00:00
André Carvalho
2b7a08c3c7 os/exec: add example for Cmd.Run
Change-Id: Ic47198bc8bf5baabfcf4d0599825eab30d7b126c
Reviewed-on: https://go-review.googlesource.com/48853
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-07-15 21:36:39 +00:00
Taro Aoki
4f299f93f6 os: use Fstat instead of Stat in FileMode example
The existing example for FileMode using Stat to get FileInfo.
But, Stat cannot get symlink info, it need to use Fstat instead.

Change-Id: I5cc38cd10caaa5912946abe2a2b90995a91ee10f
Reviewed-on: https://go-review.googlesource.com/47370
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2017-07-15 16:46:50 +00:00
Ian Lance Taylor
26f0a7af45 internal/poll: don't wait for unpollable files
If we get an EAGAIN error on an unpollable file, don't try to wait for
it to be ready; just return EAGAIN.

It's possible that we should instead ensure that when Stdin is a pipe
in non-blocking mode, we wait for data to appear. For now take the
conservative approach of doing what we did in previous releases.

Based on https://golang.org/cl/47555 by Totoro W.

Fixes #20915

Change-Id: Icc9e97a5a877b0a3583ec056c35412d1afab62d1
Reviewed-on: https://go-review.googlesource.com/48490
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-07-14 04:03:31 +00:00
Ian Lance Taylor
5bcfd88472 testing: roll back CL 44352 (show in-progress tests upon SIGINT)
CL 44352 changed the behavior of SIGINT, which can break tests that
themselves use SIGINT.  I think we can only implement this if the
testing package has a way to know whether the code under test is using
SIGINT, but os/signal does not provide an API for that.  Roll back for
1.9 and think about this again for 1.10.

Updates #19397

Change-Id: I021c314db2b9d0a80d0088b120a6ade685459990
Reviewed-on: https://go-review.googlesource.com/48370
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-07-13 16:01:49 +00:00
Brad Fitzpatrick
23ae7a70f9 os/exec: clarify Cmd.Wait documentation a bit more explicitly
It already implied that Cmd.Wait is more than os.Process.Wait, but say
so explicitly.

See https://github.com/golang/go/issues/18874#issuecomment-309921486

Updates #18874

Change-Id: Iaa46defd776ae0be817d9f4466a99ac78cfd672b
Reviewed-on: https://go-review.googlesource.com/47650
Reviewed-by: Russ Cox <rsc@golang.org>
2017-07-06 19:29:20 +00:00
Brad Fitzpatrick
e335643864 os/exec: document lack of implicit shell usage or globbing
Fixes #20894

Change-Id: I0c0e906964bbd789317d07f245e64e3d61ecfa8c
Reviewed-on: https://go-review.googlesource.com/47550
Reviewed-by: Russ Cox <rsc@golang.org>
2017-07-06 03:38:37 +00:00
Brad Fitzpatrick
92ad8df5d1 os: add documentation for Windows users
Updates #18581
Updates #20858

Change-Id: I6b5ce0e255a42c028d46815fff5a5aca68690fd9
Reviewed-on: https://go-review.googlesource.com/47254
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-06-30 01:36:38 +00:00
Ibrahim AshShohail
cfb8404e76 os: fix passing long paths to Chmod on Windows
os.Chmod returns an error when passed a long path (>=260) characters on
Windows. CL 32451 fixed most file functions in os. This change applies the
same fix to os.Chmod.

Fixes #20829

Change-Id: I3270db8317ce6e06e6d77070a32a5df6ab2491e0
Reviewed-on: https://go-review.googlesource.com/47010
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-28 18:49:21 +00:00
Ian Lance Taylor
b4dd1d965d os/signal: check MustHaveExec in TestAtomicStop
Change-Id: I284ecfab574b3058ba66b75f8f8d2ccdb90a8a0c
Reviewed-on: https://go-review.googlesource.com/46650
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Elias Naur <elias.naur@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-25 15:57:18 +00:00
Ian Lance Taylor
8ec7a39fec os/signal: avoid race between Stop and receiving on channel
When Stop is called on a channel, wait until all signals have been
delivered to the channel before returning.

Use atomic operations in sigqueue to communicate more reliably between
the os/signal goroutine and the signal handler.

Fixes #14571

Change-Id: I6c5a9eea1cff85e37a34dffe96f4bb2699e12c6e
Reviewed-on: https://go-review.googlesource.com/46003
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2017-06-24 00:54:01 +00:00
Ian Lance Taylor
ddeab53826 os: align siginfo argument to waitid
I have no test case for this, but there is one report on the mailing list
(https://groups.google.com/d/msg/golang-dev/sDg-t1_DPw0/-AJmLxgPBQAJ)
in which waitid running on MIPS returns EFAULT.

Change-Id: I79bde63c7427eefc1f2925d78d97cc9cf2fffde3
Reviewed-on: https://go-review.googlesource.com/46511
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-23 17:02:41 +00:00
Michael Hendricks
b3301865a0 os: run more of TestExecutable on OpenBSD
On OpenBSD, Executable relies on Args[0].  Removing the forgery on
that OS allows the rest of the test to run.

See #19453

Change-Id: Idf99f86894de5c702893791bc3684f8665f4019d
Reviewed-on: https://go-review.googlesource.com/46398
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-06-22 04:42:40 +00:00
Michael Hendricks
ded29e7b39 os: fix documentation for Executable on OpenBSD
Executable on OpenBSD now uses Args[0] so procfs is no longer
required.

Change-Id: I4155ac76f8909499783e876e92ee4f13a35b47dd
Reviewed-on: https://go-review.googlesource.com/46211
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-21 04:56:15 +00:00
Ian Lance Taylor
c60d6c0b43 os: on OpenBSD implement Executable using Args[0]
OpenBSD no longer has procfs.

Based on a patch by Matthieu Sarter.

Fixes #19453.

Change-Id: Ia09d16f8a1cbef2f8cc1c5f49e9c61ec7d026a40
Reviewed-on: https://go-review.googlesource.com/46004
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-17 03:32:59 +00:00
Brad Fitzpatrick
0b81c023a7 os: clarify behavior of TempDir
Fixes #19695

Change-Id: Ie5103f7905969e25dba6e5fb37344b70e807fc69
Reviewed-on: https://go-review.googlesource.com/45702
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-06-14 20:12:49 +00:00
Brad Fitzpatrick
467f87ce60 os/exec: remove BUG for old and unsupported OS
Nobody uses 10.6 these days anyway.

Fixes #20623

Change-Id: I698c83cbc288082558e34097ff54d1428aed75ec
Reviewed-on: https://go-review.googlesource.com/45171
Reviewed-by: Matt Layher <mdlayher@gmail.com>
2017-06-09 18:09:27 +00:00
Meir Fischer
11c61eb6af testing: show in-progress tests upon SIGINT
Because of parallel tests, which have stalled executions, the RUN
output of a test can be much earlier than its completion output resulting
in hard-to-read verbose output.

The tests are displayed in the order in which the output shows
that they began, to make it easy to line up with the "RUN" output.
Similarly, the definitions of when tests begin and complete is
determined by when RUN and FAIL/SKIP/PASS are output since the
focus of this code is on enhancing readability.

Fixes #19397

Change-Id: I4d0ca3fd268b620484e7a190117f79a33b3dc461
Reviewed-on: https://go-review.googlesource.com/44352
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-06-09 04:38:37 +00:00
Alex Brainman
f3f29d1dea os/exec: ignore some pipe write errors on windows
This change is windows version of CL 12152.
It also extends test to cover scenarios reported on issue #20445.
Some source files copied and renamed to make code clearer.

Fixes #20445

Change-Id: Idd2f636f27c6bd5cfe98017ba2df911358263382
Reviewed-on: https://go-review.googlesource.com/43910
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-05-23 04:27:01 +00:00