1 diff --git a/src/controller/servicemgr/executor/nativeexecutor/nativeexecutor.go b/src/controller/servicemgr/executor/nativeexecutor/nativeexecutor.go
2 index a62a768..49f529d 100755
3 --- a/src/controller/servicemgr/executor/nativeexecutor/nativeexecutor.go
4 +++ b/src/controller/servicemgr/executor/nativeexecutor/nativeexecutor.go
17 "controller/servicemgr"
18 "controller/servicemgr/executor"
19 @@ -31,14 +31,21 @@ import (
23 - logPrefix = "[nativeexecutor]"
24 + logPrefix = "[nativeexecutor]"
25 nativeexecutor = &NativeExecutor{}
26 + handler ExecuteHandler
30 +type ExecuteHandler interface {
31 + CmdExecute(pkgName string, args string) int
34 // NativeExecutor struct
35 type NativeExecutor struct {
36 executor.ServiceExecutionInfo
37 executor.HasClientNotification
38 + executeCB ExecuteHandler
42 @@ -50,6 +57,10 @@ func GetInstance() *NativeExecutor {
46 +func (t *NativeExecutor) SetExecuteHandler(h ExecuteHandler) {
50 // Execute executes native service application
51 func (t NativeExecutor) Execute(s executor.ServiceExecutionInfo) (err error) {
52 t.ServiceExecutionInfo = s
53 @@ -57,71 +68,58 @@ func (t NativeExecutor) Execute(s executor.ServiceExecutionInfo) (err error) {
54 log.Println(logPrefix, t.ServiceName, t.ParamStr)
55 log.Println(logPrefix, "parameter length :", len(t.ParamStr))
57 - cmd, pid, err := t.setService()
58 + result, err := t.setService()
63 - log.Println(logPrefix, "Just ran subprocess ", pid)
64 + log.Println(logPrefix, "Just ran subprocess [Result] ", result)
66 + var wait sync.WaitGroup
69 executeCh := make(chan error)
71 - executeCh <- cmd.Wait()
72 + status, _ := t.waitService(executeCh)
73 + t.notifyServiceStatus(status)
77 - status, err := t.waitService(executeCh)
78 - t.notifyServiceStatus(status)
91 -func (t NativeExecutor) setService() (cmd *exec.Cmd, pid int, err error) {
92 +func (t NativeExecutor) setService() (result int, err error) {
93 if len(t.ParamStr) < 1 {
94 err = errors.New("error: empty parameter")
97 - cmd = exec.Command(t.ParamStr[0], t.ParamStr[1:]...)
99 - // set "owner" account: need to execute user app
101 - execUser, _ := user.Lookup("owner")
103 - uid, _ := strconv.Atoi(execUser.Uid)
104 - gid, _ := strconv.Atoi(execUser.Gid)
105 - groups, _ := execUser.GroupIds()
107 - var gids = []uint32{}
108 - for _, i := range groups {
109 - id, _ := strconv.Atoi(i)
110 - gids = append(gids, uint32(id))
113 - log.Printf("uid(%d), gid(%d)", uid, gid)
114 - log.Printf("groupIds: %v", gids)
116 - cmd.SysProcAttr = &syscall.SysProcAttr{}
117 - cmd.SysProcAttr.Credential = &syscall.Credential{
124 - stdout, _ := cmd.StdoutPipe()
127 - log.Println(logPrefix, err.Error())
128 + if nil == t.executeCB {
129 + err = errors.New("Failed to execute: Native Callback is nil")
133 - scanner := bufio.NewScanner(stdout)
134 - for scanner.Scan() {
135 - m := scanner.Text()
137 + if len(t.ParamStr) < 2 {
138 + result = t.executeCB.CmdExecute(t.ParamStr[0], "")
140 + args := strings.Join(t.ParamStr[1:], " ")
141 + result = t.executeCB.CmdExecute(t.ParamStr[0], args)
144 - pid = cmd.Process.Pid
147 + err = errors.New("Failed to execute in native layer")
150 + log.Println(logPrefix, "Successfully executed in native layer")