mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 03:18:59 +00:00
lib/osutil: Check PGID before trying to set it (fixes #4679)
Fixes "permission denied" return when are already process group / session leader. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4678
This commit is contained in:
parent
582539a1e6
commit
91210cbb49
@ -7,6 +7,7 @@
|
|||||||
package osutil
|
package osutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -44,8 +45,15 @@ func SetLowPriority() error {
|
|||||||
// Move ourselves to a new process group so that we can use the process
|
// Move ourselves to a new process group so that we can use the process
|
||||||
// group variants of Setpriority etc to affect all of our threads in one
|
// group variants of Setpriority etc to affect all of our threads in one
|
||||||
// go. If this fails, bail, so that we don't affect things we shouldn't.
|
// go. If this fails, bail, so that we don't affect things we shouldn't.
|
||||||
if err := syscall.Setpgid(0, 0); err != nil {
|
// If we are already the leader of our own process group, do nothing.
|
||||||
return errors.Wrap(err, "set process group")
|
if pgid, err := syscall.Getpgid(0); err != nil {
|
||||||
|
// This error really shouldn't happen
|
||||||
|
return errors.Wrap(err, "get process group")
|
||||||
|
} else if pgid != os.Getpid() {
|
||||||
|
// We are not process group leader. Elevate!
|
||||||
|
if err := syscall.Setpgid(0, 0); err != nil {
|
||||||
|
return errors.Wrap(err, "set process group")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process zero is "self", niceness value 9 is something between 0
|
// Process zero is "self", niceness value 9 is something between 0
|
||||||
|
Loading…
Reference in New Issue
Block a user