@@ -145,9 +145,10 @@ var startCommand = cli.Command{
145145 fatal (err .Error (), 1 )
146146 }
147147 var (
148- tty bool
149- c = getClient (context )
150- r = & types.CreateContainerRequest {
148+ restoreAndCloseStdin func ()
149+ tty bool
150+ c = getClient (context )
151+ r = & types.CreateContainerRequest {
151152 Id : id ,
152153 BundlePath : bpath ,
153154 Checkpoint : context .String ("checkpoint" ),
@@ -157,6 +158,15 @@ var startCommand = cli.Command{
157158 Labels : context .StringSlice ("label" ),
158159 }
159160 )
161+ restoreAndCloseStdin = func () {
162+ if state != nil {
163+ term .RestoreTerminal (os .Stdin .Fd (), state )
164+ }
165+ if stdin != nil {
166+ stdin .Close ()
167+ }
168+ }
169+ defer restoreAndCloseStdin ()
160170 if context .Bool ("attach" ) {
161171 mkterm , err := readTermSetting (bpath )
162172 if err != nil {
@@ -182,12 +192,6 @@ var startCommand = cli.Command{
182192 fatal (err .Error (), 1 )
183193 }
184194 if context .Bool ("attach" ) {
185- restoreAndCloseStdin := func () {
186- if state != nil {
187- term .RestoreTerminal (os .Stdin .Fd (), state )
188- }
189- stdin .Close ()
190- }
191195 go func () {
192196 io .Copy (stdin , os .Stdin )
193197 if _ , err := c .UpdateProcess (netcontext .Background (), & types.UpdateProcessRequest {
@@ -422,6 +426,8 @@ var execCommand = cli.Command{
422426 },
423427 },
424428 Action : func (context * cli.Context ) {
429+ var restoreAndCloseStdin func ()
430+
425431 p := & types.AddProcessRequest {
426432 Id : context .String ("id" ),
427433 Pid : context .String ("pid" ),
@@ -441,6 +447,15 @@ var execCommand = cli.Command{
441447 p .Stdin = s .stdin
442448 p .Stdout = s .stdout
443449 p .Stderr = s .stderr
450+ restoreAndCloseStdin = func () {
451+ if state != nil {
452+ term .RestoreTerminal (os .Stdin .Fd (), state )
453+ }
454+ if stdin != nil {
455+ stdin .Close ()
456+ }
457+ }
458+ defer restoreAndCloseStdin ()
444459 if context .Bool ("attach" ) {
445460 if context .Bool ("tty" ) {
446461 s , err := term .SetRawTerminal (os .Stdin .Fd ())
@@ -462,12 +477,6 @@ var execCommand = cli.Command{
462477 fatal (err .Error (), 1 )
463478 }
464479 if context .Bool ("attach" ) {
465- restoreAndCloseStdin := func () {
466- if state != nil {
467- term .RestoreTerminal (os .Stdin .Fd (), state )
468- }
469- stdin .Close ()
470- }
471480 go func () {
472481 io .Copy (stdin , os .Stdin )
473482 if _ , err := c .UpdateProcess (netcontext .Background (), & types.UpdateProcessRequest {
0 commit comments