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 package cronsun
import ( import (
"os"
"github.com/shunfei/cronsun/conf" "github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun/db" "github.com/shunfei/cronsun/db"
) )
var ( var (
initialized bool initialized bool
_Uid int
) )
func Init() (err error) { func Init() (err error) {
@ -34,6 +38,8 @@ func Init() (err error) {
return return
} }
_Uid = os.Getuid()
initialized = true initialized = true
return 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") j.Fail(t, "not support run with user on windows")
return false return false
} }
gid, _ := strconv.Atoi(u.Gid) if uid != _Uid {
sysProcAttr = &syscall.SysProcAttr{ gid, _ := strconv.Atoi(u.Gid)
Credential: &syscall.Credential{ sysProcAttr = &syscall.SysProcAttr{
Uid: uint32(uid), Credential: &syscall.Credential{
Gid: uint32(gid), Uid: uint32(uid),
}, Gid: uint32(gid),
},
}
} }
} }