master v1.1.0
兔子 4 years ago
parent d981a03b14
commit 3501166592

2
.gitignore vendored

@ -0,0 +1,2 @@
.idea
.vscode

@ -28,7 +28,6 @@ type StarCmd struct {
errout []byte
runerr error
exitcode int
customCtx context.Context
stdoutBuf *bytes.Buffer
stderrBuf *bytes.Buffer
stdoutpoint int
@ -314,9 +313,13 @@ func (starcli *StarCmd) ExitCode() int {
return starcli.exitcode
}
func (starcli *StarCmd) Kill() {
starcli.CMD.Process.Kill()
func (starcli *StarCmd) Kill() error{
err:=starcli.CMD.Process.Kill()
if err!=nil{
return err
}
starcli.running = false
return nil
}
func (starcli *StarCmd) GetPid() int {

@ -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 starcli.CMD.SysProcAttr == nil {
starcli.CMD.SysProcAttr = &syscall.SysProcAttr{
Setsid: true,
}
} else {
starcli.CMD.SysProcAttr.Setsid = true
}
if !starcli.IsRunning() {
if err := starcli.CMD.Start(); err != nil {
return err
}
starcli.CMD.SysProcAttr = &syscall.SysProcAttr{
Setsid: true,
}
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
}

Loading…
Cancel
Save