job: more appropriate credential

pull/19/head
miraclesu 2017-05-27 10:26:39 +08:00
parent 8148ff5b3d
commit 60b9437653
2 changed files with 14 additions and 6 deletions

View File

@ -1,12 +1,16 @@
package cronsun
import (
"os"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun/db"
)
var (
initialized bool
_Uid int
)
func Init() (err error) {
@ -34,6 +38,8 @@ func Init() (err error) {
return
}
_Uid = os.Getuid()
initialized = true
return
}

14
job.go
View File

@ -421,12 +421,14 @@ func (j *Job) Run() bool {
j.Fail(t, "not support run with user on windows")
return false
}
gid, _ := strconv.Atoi(u.Gid)
sysProcAttr = &syscall.SysProcAttr{
Credential: &syscall.Credential{
Uid: uint32(uid),
Gid: uint32(gid),
},
if uid != _Uid {
gid, _ := strconv.Atoi(u.Gid)
sysProcAttr = &syscall.SysProcAttr{
Credential: &syscall.Credential{
Uid: uint32(uid),
Gid: uint32(gid),
},
}
}
}