|
|
|
@ -283,25 +283,49 @@ func Daemon(path string, args ...string) (int, error) {
|
|
|
|
|
return pid, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (starcli *StarCmd) SetRunUser(uid, gid uint32) {
|
|
|
|
|
func DaemonWithUser(uid, gid uint32,groups []uint32,path string, args ...string) (int, error) {
|
|
|
|
|
cmd := exec.Command(path, args...)
|
|
|
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
|
|
|
Credential: &syscall.Credential{
|
|
|
|
|
Uid: uid,
|
|
|
|
|
Gid: gid,
|
|
|
|
|
Groups: groups,
|
|
|
|
|
},
|
|
|
|
|
Setsid: true,
|
|
|
|
|
}
|
|
|
|
|
if err := cmd.Start(); err != nil {
|
|
|
|
|
return -1, err
|
|
|
|
|
}
|
|
|
|
|
pid := cmd.Process.Pid
|
|
|
|
|
err := cmd.Process.Release()
|
|
|
|
|
return pid, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (starcli *StarCmd) SetRunUser(uid, gid uint32,groups []uint32) {
|
|
|
|
|
starcli.CMD.SysProcAttr = &syscall.SysProcAttr{
|
|
|
|
|
Credential: &syscall.Credential{
|
|
|
|
|
Uid: uid,
|
|
|
|
|
Gid: gid,
|
|
|
|
|
Groups: groups,
|
|
|
|
|
},
|
|
|
|
|
Setsid: true,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (starcli *StarCmd) Release() error {
|
|
|
|
|
if err := starcli.CMD.Start(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
if starcli.CMD.SysProcAttr == nil {
|
|
|
|
|
starcli.CMD.SysProcAttr = &syscall.SysProcAttr{
|
|
|
|
|
Setsid: true,
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
starcli.CMD.SysProcAttr.Setsid = true
|
|
|
|
|
}
|
|
|
|
|
starcli.CMD.SysProcAttr = &syscall.SysProcAttr{
|
|
|
|
|
Setsid: true,
|
|
|
|
|
if !starcli.IsRunning() {
|
|
|
|
|
if err := starcli.CMD.Start(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
starcli.CMD.Process.Release()
|
|
|
|
|
return nil
|
|
|
|
|
return starcli.CMD.Process.Release()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (starcli *StarCmd) SetKeepCaps() error {
|
|
|
|
@ -311,3 +335,11 @@ func (starcli *StarCmd) SetKeepCaps() error {
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SetKeepCaps() error {
|
|
|
|
|
_, _, err := syscall.RawSyscall(157 /*SYS PRCTL */, 0x8 /*PR SET KEEPCAPS*/, 1, 0)
|
|
|
|
|
if 0 != err {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|