syscallcompat: use early return in asUser()
This commit is contained in:
parent
be2bd4eec7
commit
02c91d73ce
@ -91,10 +91,15 @@ func getSupplementaryGroups(pid uint32) (gids []int) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// asUser runs the function `f` under the effective uid, gid, groups specified
|
// asUser runs `f()` under the effective uid, gid, groups specified
|
||||||
// in `context`.
|
// in `context`.
|
||||||
|
//
|
||||||
|
// If `context` is nil, `f()` is executed directly without switching user id.
|
||||||
func asUser(f func() (int, error), context *fuse.Context) (int, error) {
|
func asUser(f func() (int, error), context *fuse.Context) (int, error) {
|
||||||
if context != nil {
|
if context == nil {
|
||||||
|
return f()
|
||||||
|
}
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
@ -122,7 +127,7 @@ func asUser(f func() (int, error), context *fuse.Context) (int, error) {
|
|||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
defer unix.Setreuid(-1, 0)
|
defer unix.Setreuid(-1, 0)
|
||||||
}
|
|
||||||
return f()
|
return f()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user