@@ -32,8 +32,6 @@ const (
32
32
ImageUserKey = "ImageUser"
33
33
// Type indicate type
34
34
Type = "virt"
35
-
36
- ttyFlag = "tty"
37
35
)
38
36
39
37
// Virt implements the core engine.API interface.
@@ -89,26 +87,27 @@ func (v *Virt) CloseConn() error {
89
87
}
90
88
91
89
// Execute executes a command in vm
92
- func (v * Virt ) Execute (ctx context.Context , ID string , config * enginetypes.ExecConfig ) (pid string , stdout , stderr io.ReadCloser , stdin io.WriteCloser , err error ) {
90
+ // in tty mode, 'execID' return value indicates the execID which has the pattern '%s_%s', at other times it indicates the pid
91
+ func (v * Virt ) Execute (ctx context.Context , ID string , config * enginetypes.ExecConfig ) (execID string , stdout , stderr io.ReadCloser , stdin io.WriteCloser , err error ) {
93
92
if config .Tty {
94
93
flags := virttypes.AttachGuestFlags {Safe : true , Force : true }
95
- _ , stream , err := v .client .AttachGuest (ctx , ID , config .Cmd , flags )
94
+ execID , stream , err := v .client .AttachGuest (ctx , ID , config .Cmd , flags )
96
95
if err != nil {
97
96
return "" , nil , nil , nil , err
98
97
}
99
- return ttyFlag , ioutil .NopCloser (stream ), nil , stream , nil
98
+ return execID , ioutil .NopCloser (stream ), nil , stream , nil
100
99
}
101
100
msg , err := v .client .ExecuteGuest (ctx , ID , config .Cmd )
102
101
return strconv .Itoa (msg .Pid ), ioutil .NopCloser (bytes .NewReader (msg .Data )), nil , nil , err
103
102
}
104
103
105
104
// ExecExitCode get return code of a specific execution.
106
- func (v * Virt ) ExecExitCode (ctx context.Context , ID , pid string ) (code int , err error ) {
107
- if pid == ttyFlag {
105
+ func (v * Virt ) ExecExitCode (ctx context.Context , ID , execID string ) (code int , err error ) {
106
+ if strings . Contains ( execID , "_" ) {
108
107
return 0 , nil
109
108
}
110
109
111
- intPid , err := strconv .Atoi (pid )
110
+ intPid , err := strconv .Atoi (execID )
112
111
if err != nil {
113
112
return - 1 , err
114
113
}
@@ -120,8 +119,8 @@ func (v *Virt) ExecExitCode(ctx context.Context, ID, pid string) (code int, err
120
119
}
121
120
122
121
// ExecResize resize exec tty
123
- func (v * Virt ) ExecResize (ctx context.Context , ID , pid string , height , width uint ) (err error ) {
124
- return v .client .ResizeConsoleWindow (ctx , ID , height , width )
122
+ func (v * Virt ) ExecResize (ctx context.Context , execID string , height , width uint ) (err error ) {
123
+ return v .client .ResizeConsoleWindow (ctx , execID , height , width )
125
124
}
126
125
127
126
// NetworkConnect connects to a network.
0 commit comments