Improve error logging, not only on Linux

This commit is contained in:
Frank Denis 2018-12-23 18:11:55 +01:00
parent 1cf7ce94ba
commit 3ccc989be5
1 changed files with 6 additions and 6 deletions

View File

@ -51,13 +51,13 @@ func (proxy *Proxy) dropPrivilege(userStr string, fds []*os.File) {
dlog.Notice("Dropping privileges")
runtime.LockOSThread()
if _, _, rcode := syscall.RawSyscall(syscall.SYS_SETGROUPS, uintptr(0), uintptr(0), 0); rcode != 0 {
dlog.Fatalf("Unable to drop additional groups: %s", err)
dlog.Fatalf("Unable to drop additional groups: %s", rcode.Error())
}
if _, _, rcode := syscall.RawSyscall(syscall.SYS_SETGID, uintptr(gid), 0, 0); rcode != 0 {
dlog.Fatalf("Unable to drop user privileges: %s", err)
dlog.Fatalf("Unable to drop user privileges: %s", rcode.Error())
}
if _, _, rcode := syscall.RawSyscall(syscall.SYS_SETUID, uintptr(uid), 0, 0); rcode != 0 {
dlog.Fatalf("Unable to drop user privileges: %s", err)
dlog.Fatalf("Unable to drop user privileges: %s", rcode.Error())
}
maxfd := uintptr(0)
for _, fd := range fds {
@ -68,15 +68,15 @@ func (proxy *Proxy) dropPrivilege(userStr string, fds []*os.File) {
fdbase := maxfd + 1
for i, fd := range fds {
if _, _, rcode := syscall.RawSyscall(syscall.SYS_DUP2, fd.Fd(), fdbase+uintptr(i), 0); rcode != 0 {
dlog.Fatal("Unable to clone file descriptor")
dlog.Fatalf("Unable to clone file descriptor: [%s]", rcode.Error())
}
if _, _, rcode := syscall.RawSyscall(syscall.SYS_FCNTL, fd.Fd(), syscall.F_SETFD, syscall.FD_CLOEXEC); rcode != 0 {
dlog.Fatal("Unable to set the close on exec flag")
dlog.Fatalf("Unable to set the close on exec flag: [%s]", rcode.Error())
}
}
for i := range fds {
if _, _, rcode := syscall.RawSyscall(syscall.SYS_DUP2, fdbase+uintptr(i), uintptr(i)+3, 0); rcode != 0 {
dlog.Fatal("Unable to reassign descriptor")
dlog.Fatalf("Unable to reassign descriptor: [%s]", rcode.Error())
}
}
err = syscall.Exec(path, args, os.Environ())