-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Open
Labels
NeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.OS-Linuxhelp wanted
Milestone
Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
go version go1.9.4 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GORACE=""
GOROOT="/usr/lib/golang"
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build203196509=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
What did you do?
package main
import (
"os"
)
func main() {
os.Mkdir("test", 0770 | os.ModeSetgid)
}What did you expect to see?
# ls -la test
insgesamt 4
drwxr-s---. 2 root root 6 24. Mai 04:09 .
dr-xr-x---. 13 root root 4096 24. Mai 04:09 ..
#
What did you see instead?
# ls -la test
insgesamt 4
drwxr-x---. 2 root root 6 24. Mai 04:09 .
dr-xr-x---. 13 root root 4096 24. Mai 04:09 ..
#
Why did this happen?
According to strace -f ./mkdir the Go stdlib behaves as expected...
[pid 6782] mkdirat(AT_FDCWD, "test", 02770 <unfinished ...>
[pid 6782] <... mkdirat resumed> ) = 0
... but on Linux this is not enough, see mkdirat(2):
The mkdirat() system call operates in exactly the same way as mkdir(2), (...)
... and mkdir(2):
The argument mode specifies the permissions to use.
It is modified (...): the permissions of the created directory are (mode & ~umask & 0777).
Other mode bits of the created directory depend on the operating system.
For Linux, see below.
(...)
That is, under Linux the created directory actually gets mode (mode & ~umask & 01777)
How could this be fixed?
Metadata
Metadata
Assignees
Labels
NeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.OS-Linuxhelp wanted