2017-10-16 16:36:49 +08:00
|
|
|
// +build linux
|
2019-08-27 02:54:48 +08:00
|
|
|
// +build arm64 amd64 mips mipsle mips64 mips64le ppc ppc64 ppc64le riscv64 s390x
|
2014-11-06 00:56:47 +08:00
|
|
|
|
2014-10-21 03:20:08 +08:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
2017-05-10 05:38:27 +08:00
|
|
|
"golang.org/x/sys/unix"
|
2014-10-21 03:20:08 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Setuid sets the uid of the calling thread to the specified uid.
|
|
|
|
func Setuid(uid int) (err error) {
|
2017-05-10 05:38:27 +08:00
|
|
|
_, _, e1 := unix.RawSyscall(unix.SYS_SETUID, uintptr(uid), 0, 0)
|
2014-10-21 03:20:08 +08:00
|
|
|
if e1 != 0 {
|
|
|
|
err = e1
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setgid sets the gid of the calling thread to the specified gid.
|
|
|
|
func Setgid(gid int) (err error) {
|
2017-05-10 05:38:27 +08:00
|
|
|
_, _, e1 := unix.RawSyscall(unix.SYS_SETGID, uintptr(gid), 0, 0)
|
2014-10-21 03:20:08 +08:00
|
|
|
if e1 != 0 {
|
|
|
|
err = e1
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|