syscallcompat: use early return in asUser()

This commit is contained in:
Jakob Unterwurzacher 2021-08-19 09:01:58 +02:00
parent be2bd4eec7
commit 02c91d73ce

View File

@ -91,10 +91,15 @@ func getSupplementaryGroups(pid uint32) (gids []int) {
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`.
//
// If `context` is nil, `f()` is executed directly without switching user id.
func asUser(f func() (int, error), context *fuse.Context) (int, error) {
if context != nil {
if context == nil {
return f()
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
@ -122,7 +127,7 @@ func asUser(f func() (int, error), context *fuse.Context) (int, error) {
return -1, err
}
defer unix.Setreuid(-1, 0)
}
return f()
}