mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-28 04:46:44 -04:00
unix: support Faccessat flags argument
The Linux kernel faccessat system call does not take a flags parameter. The flag parameter to the C library faccessat function is implemented in C. The unix.Faccessat function takes a flags parameter. In older releases we have passed the flags parameter to the kernel, which ignored it. In CL 119495 we started returning an error if any flags were set. That seems clearly better than ignoring them, but it turns out that some code was using the flags. The code was previously subtly broken. Now it is obviously broken. That is better, but we can do better still: we can implement the flags as the C library does. That is what this CL does. Change-Id: I02d4bb981ebd39eb35e47c6e5281f85eaea68016 Reviewed-on: https://go-review.googlesource.com/126516 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
@@ -394,19 +394,19 @@ func TestFaccessat(t *testing.T) {
|
||||
defer chtmpdir(t)()
|
||||
touch(t, "file1")
|
||||
|
||||
err := unix.Faccessat(unix.AT_FDCWD, "file1", unix.O_RDONLY, 0)
|
||||
err := unix.Faccessat(unix.AT_FDCWD, "file1", unix.R_OK, 0)
|
||||
if err != nil {
|
||||
t.Errorf("Faccessat: unexpected error: %v", err)
|
||||
}
|
||||
|
||||
err = unix.Faccessat(unix.AT_FDCWD, "file1", unix.O_RDONLY, 2)
|
||||
err = unix.Faccessat(unix.AT_FDCWD, "file1", unix.R_OK, 2)
|
||||
if err != unix.EINVAL {
|
||||
t.Errorf("Faccessat: unexpected error: %v, want EINVAL", err)
|
||||
}
|
||||
|
||||
err = unix.Faccessat(unix.AT_FDCWD, "file1", unix.O_RDONLY, unix.AT_EACCESS)
|
||||
if err != unix.EOPNOTSUPP {
|
||||
t.Errorf("Faccessat: unexpected error: %v, want EOPNOTSUPP", err)
|
||||
err = unix.Faccessat(unix.AT_FDCWD, "file1", unix.R_OK, unix.AT_EACCESS)
|
||||
if err != nil {
|
||||
t.Errorf("Faccessat: unexpected error: %v", err)
|
||||
}
|
||||
|
||||
err = os.Symlink("file1", "symlink1")
|
||||
@@ -414,8 +414,30 @@ func TestFaccessat(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = unix.Faccessat(unix.AT_FDCWD, "symlink1", unix.O_RDONLY, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != unix.EOPNOTSUPP {
|
||||
t.Errorf("Faccessat: unexpected error: %v, want EOPNOTSUPP", err)
|
||||
err = unix.Faccessat(unix.AT_FDCWD, "symlink1", unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != nil {
|
||||
t.Errorf("Faccessat SYMLINK_NOFOLLOW: unexpected error %v", err)
|
||||
}
|
||||
|
||||
// We can't really test AT_SYMLINK_NOFOLLOW, because there
|
||||
// doesn't seem to be any way to change the mode of a symlink.
|
||||
// We don't test AT_EACCESS because such tests are only
|
||||
// meaningful if run as root.
|
||||
|
||||
err = unix.Fchmodat(unix.AT_FDCWD, "file1", 0, 0)
|
||||
if err != nil {
|
||||
t.Errorf("Fchmodat: unexpected error %v", err)
|
||||
}
|
||||
|
||||
err = unix.Faccessat(unix.AT_FDCWD, "file1", unix.F_OK, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != nil {
|
||||
t.Errorf("Faccessat: unexpected error: %v", err)
|
||||
}
|
||||
|
||||
err = unix.Faccessat(unix.AT_FDCWD, "file1", unix.R_OK, unix.AT_SYMLINK_NOFOLLOW)
|
||||
if err != unix.EACCES {
|
||||
if unix.Getuid() != 0 {
|
||||
t.Errorf("Faccessat: unexpected error: %v, want EACCES", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user