Keep the process running in foreground to avoid a breaking change/allow monitoring
This currently doesn't replace the previous process. Maybe there is a way to achieve this in Go. Need to look closer at os.exec Also start-child -> child
This commit is contained in:
parent
fe0aa52fba
commit
09e39c785a
|
@ -188,7 +188,7 @@ func ConfigLoad(proxy *Proxy, svcFlag *string) error {
|
|||
check := flag.Bool("check", false, "check the configuration file and exit")
|
||||
configFile := flag.String("config", DefaultConfigFileName, "Path to the configuration file")
|
||||
username := flag.String("username", "", "After binding to the port user privileges are dropped")
|
||||
child := flag.Bool("start-child", false, "Invokes program as a child process")
|
||||
child := flag.Bool("child", false, "Invokes program as a child process")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"github.com/jedisct1/dlog"
|
||||
)
|
||||
|
||||
|
@ -27,11 +28,11 @@ func (proxy *Proxy) dropPrivilege(userStr string, fds []*os.File) {
|
|||
if err != nil {
|
||||
dlog.Fatal(err)
|
||||
}
|
||||
exec_path, err := exec.LookPath(args[0])
|
||||
execPath, err := exec.LookPath(args[0])
|
||||
if err != nil {
|
||||
dlog.Fatal(err)
|
||||
}
|
||||
path, err := filepath.Abs(exec_path)
|
||||
path, err := filepath.Abs(execPath)
|
||||
if err != nil {
|
||||
dlog.Fatal(err)
|
||||
}
|
||||
|
@ -40,7 +41,7 @@ func (proxy *Proxy) dropPrivilege(userStr string, fds []*os.File) {
|
|||
copy(args[0:], args[0+1:])
|
||||
args[len(args)-1] = ""
|
||||
args = args[:len(args)-1]
|
||||
args = append(args, "-start-child")
|
||||
args = append(args, "-child")
|
||||
|
||||
cmd := exec.Command(path, args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
|
@ -48,8 +49,9 @@ func (proxy *Proxy) dropPrivilege(userStr string, fds []*os.File) {
|
|||
cmd.ExtraFiles = fds
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
|
||||
cmd.SysProcAttr.Setsid = true
|
||||
dlog.Notice("Dropping privileges")
|
||||
if err := cmd.Start(); err != nil {
|
||||
if err := cmd.Run(); err != nil {
|
||||
dlog.Fatal(err)
|
||||
}
|
||||
os.Exit(0)
|
Loading…
Reference in New Issue