mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-02 23:27:31 -04:00
unix: fix TestSCMCredentials to not fail when root
Fixes golang/go#25354 Change-Id: Ic74005ed26792a78354ffe76f567e9a009eabe9a Reviewed-on: https://go-review.googlesource.com/112738 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
+1
-16
@@ -11,7 +11,6 @@ import (
|
|||||||
"go/build"
|
"go/build"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
@@ -72,24 +71,10 @@ func TestSCMCredentials(t *testing.T) {
|
|||||||
defer cli.Close()
|
defer cli.Close()
|
||||||
|
|
||||||
var ucred unix.Ucred
|
var ucred unix.Ucred
|
||||||
ucred.Pid = int32(os.Getpid() - 1)
|
ucred.Pid = int32(os.Getpid())
|
||||||
ucred.Uid = uint32(os.Getuid())
|
ucred.Uid = uint32(os.Getuid())
|
||||||
ucred.Gid = uint32(os.Getgid())
|
ucred.Gid = uint32(os.Getgid())
|
||||||
oob := unix.UnixCredentials(&ucred)
|
oob := unix.UnixCredentials(&ucred)
|
||||||
_, _, err = cli.(*net.UnixConn).WriteMsgUnix(nil, oob, nil)
|
|
||||||
if op, ok := err.(*net.OpError); ok {
|
|
||||||
err = op.Err
|
|
||||||
}
|
|
||||||
if sys, ok := err.(*os.SyscallError); ok {
|
|
||||||
err = sys.Err
|
|
||||||
}
|
|
||||||
if err != syscall.EPERM {
|
|
||||||
t.Fatalf("WriteMsgUnix failed with %v, want EPERM", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fix the PID.
|
|
||||||
ucred.Pid = int32(os.Getpid())
|
|
||||||
oob = unix.UnixCredentials(&ucred)
|
|
||||||
|
|
||||||
// On SOCK_STREAM, this is internally going to send a dummy byte
|
// On SOCK_STREAM, this is internally going to send a dummy byte
|
||||||
n, oobn, err := cli.(*net.UnixConn).WriteMsgUnix(nil, oob, nil)
|
n, oobn, err := cli.(*net.UnixConn).WriteMsgUnix(nil, oob, nil)
|
||||||
|
|||||||
Reference in New Issue
Block a user