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
|
||||||
}
|
}
|
||||||
|
|
14
job.go
14
job.go
|
@ -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),
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue