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
} }

2
job.go
View File

@ -421,6 +421,7 @@ 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
} }
if uid != _Uid {
gid, _ := strconv.Atoi(u.Gid) gid, _ := strconv.Atoi(u.Gid)
sysProcAttr = &syscall.SysProcAttr{ sysProcAttr = &syscall.SysProcAttr{
Credential: &syscall.Credential{ Credential: &syscall.Credential{
@ -429,6 +430,7 @@ func (j *Job) Run() bool {
}, },
} }
} }
}
// 超时控制 // 超时控制
if j.Timeout > 0 { if j.Timeout > 0 {