mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-31 06:16:41 -04:00
unix: add openat2 for linux
openat2 is a new syscall added to Linux 5.6. It provides a superset of openat(2) functionality, providing a way to extend it in the future, and (for now) adding flags telling the kernel how to resolve the path. For more info on openat2, see https://lwn.net/Articles/803237/ A primitive test case is added to check that Openat2 works as it should. Tested to skip on kernel 5.5 and pass on 5.6. Change-Id: Ib8bbd71791762f043200543cecdea16d2fd3c81d Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com> Reviewed-on: https://go-review.googlesource.com/c/sys/+/227280 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
committed by
Tobias Klauser
parent
c3d8025017
commit
c6e801f48b
@@ -663,3 +663,24 @@ func TestPrctlRetInt(t *testing.T) {
|
||||
t.Fatalf("unexpected return from prctl; got %v, expected %v", v, 1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenat2(t *testing.T) {
|
||||
how := &unix.OpenHow{
|
||||
Flags: unix.O_RDONLY,
|
||||
Resolve: unix.RESOLVE_NO_MAGICLINKS,
|
||||
}
|
||||
fd, err := unix.Openat2(-1, "/proc/self/fd/1", how)
|
||||
switch err {
|
||||
case nil:
|
||||
unix.Close(fd)
|
||||
t.Fatal("expected ELOOP, got nil")
|
||||
case unix.ELOOP:
|
||||
return
|
||||
case unix.ENOSYS:
|
||||
t.Skip("old kernel? (need Linux >= 5.6)")
|
||||
case unix.ENOENT:
|
||||
t.Skipf("openat2: %v, skipping test", err)
|
||||
default:
|
||||
t.Fatalf("unexpected error from openat2: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user