提交 68547a5f 编写于 作者: jia zhang's avatar jia zhang

rune/libenclave: Fix runelet process to exit

If the program launched by rune exec is terminated, runelet process
is unstoppable. Just kick off it through the channel notifyExit.
Signed-off-by: NXiaozhe Wang <wangxiaozhe@linux.alibaba.com>
Signed-off-by: jia zhang's avatarJia Zhang <zhang.jia@linux.alibaba.com>
上级 4fc3c3c4
...@@ -125,11 +125,10 @@ func StartInitialization() (exitCode int32, err error) { ...@@ -125,11 +125,10 @@ func StartInitialization() (exitCode int32, err error) {
defer agentPipe.Close() defer agentPipe.Close()
os.Unsetenv("_LIBENCLAVE_AGENTPIPE") os.Unsetenv("_LIBENCLAVE_AGENTPIPE")
notifyExit := make(chan struct{})
notifySignal := make(chan os.Signal, signalBufferSize) notifySignal := make(chan os.Signal, signalBufferSize)
if fifoFd == -1 { if fifoFd == -1 {
exitCode, err = remoteExec(agentPipe, config, notifySignal, notifyExit) exitCode, err = remoteExec(agentPipe, config, notifySignal)
if err != nil { if err != nil {
return exitCode, err return exitCode, err
} }
...@@ -138,6 +137,7 @@ func StartInitialization() (exitCode int32, err error) { ...@@ -138,6 +137,7 @@ func StartInitialization() (exitCode int32, err error) {
return exitCode, err return exitCode, err
} }
notifyExit := make(chan struct{})
sigForwarderExit := forwardSignal(rt, notifySignal, notifyExit) sigForwarderExit := forwardSignal(rt, notifySignal, notifyExit)
agentExit := startAgentService(agentPipe, notifyExit) agentExit := startAgentService(agentPipe, notifyExit)
...@@ -230,7 +230,7 @@ func finalizeInitialization(fifoFd int) error { ...@@ -230,7 +230,7 @@ func finalizeInitialization(fifoFd int) error {
return nil return nil
} }
func remoteExec(agentPipe *os.File, config *configs.InitEnclaveConfig, notifySignal chan os.Signal, notifyExit <-chan struct{}) (exitCode int32, err error) { func remoteExec(agentPipe *os.File, config *configs.InitEnclaveConfig, notifySignal chan os.Signal) (exitCode int32, err error) {
logrus.Debugf("preparing to remote exec %s", strings.Join(config.Cmd, " ")) logrus.Debugf("preparing to remote exec %s", strings.Join(config.Cmd, " "))
c, err := net.FileConn(agentPipe) c, err := net.FileConn(agentPipe)
...@@ -289,6 +289,8 @@ func remoteExec(agentPipe *os.File, config *configs.InitEnclaveConfig, notifySig ...@@ -289,6 +289,8 @@ func remoteExec(agentPipe *os.File, config *configs.InitEnclaveConfig, notifySig
childSignalPipe.Close() childSignalPipe.Close()
signal.Notify(notifySignal) signal.Notify(notifySignal)
notifyExit := make(chan struct{})
sigForwarderExit := forwardSignalToParent(parentSignalPipe, notifySignal, notifyExit) sigForwarderExit := forwardSignalToParent(parentSignalPipe, notifySignal, notifyExit)
resp := &pb.AgentServiceResponse{} resp := &pb.AgentServiceResponse{}
...@@ -296,6 +298,7 @@ func remoteExec(agentPipe *os.File, config *configs.InitEnclaveConfig, notifySig ...@@ -296,6 +298,7 @@ func remoteExec(agentPipe *os.File, config *configs.InitEnclaveConfig, notifySig
return 1, err return 1, err
} }
notifyExit <- struct{}{}
logrus.Debug("awaiting for signal forwarder exiting ...") logrus.Debug("awaiting for signal forwarder exiting ...")
<-sigForwarderExit <-sigForwarderExit
logrus.Debug("signal forwarder exited") logrus.Debug("signal forwarder exited")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册