mirror of https://github.com/shunfei/cronsun
job: more appropriate credential
parent
8148ff5b3d
commit
60b9437653
|
@ -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
2
job.go
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue