Fix cases where ctr wouldn't properly restore the terminal termios
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
		| @@ -145,9 +145,10 @@ var startCommand = cli.Command{ | ||||
| 			fatal(err.Error(), 1) | ||||
| 		} | ||||
| 		var ( | ||||
| 			tty bool | ||||
| 			c   = getClient(context) | ||||
| 			r   = &types.CreateContainerRequest{ | ||||
| 			restoreAndCloseStdin func() | ||||
| 			tty                  bool | ||||
| 			c                    = getClient(context) | ||||
| 			r                    = &types.CreateContainerRequest{ | ||||
| 				Id:         id, | ||||
| 				BundlePath: bpath, | ||||
| 				Checkpoint: context.String("checkpoint"), | ||||
| @@ -157,6 +158,15 @@ var startCommand = cli.Command{ | ||||
| 				Labels:     context.StringSlice("label"), | ||||
| 			} | ||||
| 		) | ||||
| 		restoreAndCloseStdin = func() { | ||||
| 			if state != nil { | ||||
| 				term.RestoreTerminal(os.Stdin.Fd(), state) | ||||
| 			} | ||||
| 			if stdin != nil { | ||||
| 				stdin.Close() | ||||
| 			} | ||||
| 		} | ||||
| 		defer restoreAndCloseStdin() | ||||
| 		if context.Bool("attach") { | ||||
| 			mkterm, err := readTermSetting(bpath) | ||||
| 			if err != nil { | ||||
| @@ -182,12 +192,6 @@ var startCommand = cli.Command{ | ||||
| 			fatal(err.Error(), 1) | ||||
| 		} | ||||
| 		if context.Bool("attach") { | ||||
| 			restoreAndCloseStdin := func() { | ||||
| 				if state != nil { | ||||
| 					term.RestoreTerminal(os.Stdin.Fd(), state) | ||||
| 				} | ||||
| 				stdin.Close() | ||||
| 			} | ||||
| 			go func() { | ||||
| 				io.Copy(stdin, os.Stdin) | ||||
| 				if _, err := c.UpdateProcess(netcontext.Background(), &types.UpdateProcessRequest{ | ||||
| @@ -422,6 +426,8 @@ var execCommand = cli.Command{ | ||||
| 		}, | ||||
| 	}, | ||||
| 	Action: func(context *cli.Context) { | ||||
| 		var restoreAndCloseStdin func() | ||||
|  | ||||
| 		p := &types.AddProcessRequest{ | ||||
| 			Id:       context.String("id"), | ||||
| 			Pid:      context.String("pid"), | ||||
| @@ -441,6 +447,15 @@ var execCommand = cli.Command{ | ||||
| 		p.Stdin = s.stdin | ||||
| 		p.Stdout = s.stdout | ||||
| 		p.Stderr = s.stderr | ||||
| 		restoreAndCloseStdin = func() { | ||||
| 			if state != nil { | ||||
| 				term.RestoreTerminal(os.Stdin.Fd(), state) | ||||
| 			} | ||||
| 			if stdin != nil { | ||||
| 				stdin.Close() | ||||
| 			} | ||||
| 		} | ||||
| 		defer restoreAndCloseStdin() | ||||
| 		if context.Bool("attach") { | ||||
| 			if context.Bool("tty") { | ||||
| 				s, err := term.SetRawTerminal(os.Stdin.Fd()) | ||||
| @@ -462,12 +477,6 @@ var execCommand = cli.Command{ | ||||
| 			fatal(err.Error(), 1) | ||||
| 		} | ||||
| 		if context.Bool("attach") { | ||||
| 			restoreAndCloseStdin := func() { | ||||
| 				if state != nil { | ||||
| 					term.RestoreTerminal(os.Stdin.Fd(), state) | ||||
| 				} | ||||
| 				stdin.Close() | ||||
| 			} | ||||
| 			go func() { | ||||
| 				io.Copy(stdin, os.Stdin) | ||||
| 				if _, err := c.UpdateProcess(netcontext.Background(), &types.UpdateProcessRequest{ | ||||
|   | ||||
							
								
								
									
										15
									
								
								ctr/main.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								ctr/main.go
									
									
									
									
									
								
							| @@ -11,7 +11,20 @@ import ( | ||||
|  | ||||
| const usage = `High performance container daemon cli` | ||||
|  | ||||
| type Exit struct { | ||||
| 	Code int | ||||
| } | ||||
|  | ||||
| func main() { | ||||
| 	// We want our defer functions to be run when calling fatal() | ||||
| 	defer func() { | ||||
| 		if e := recover(); e != nil { | ||||
| 			if ex, ok := e.(Exit); ok == true { | ||||
| 				os.Exit(ex.Code) | ||||
| 			} | ||||
| 			panic(e) | ||||
| 		} | ||||
| 	}() | ||||
| 	app := cli.NewApp() | ||||
| 	app.Name = "ctr" | ||||
| 	if containerd.GitCommit != "" { | ||||
| @@ -50,5 +63,5 @@ func main() { | ||||
|  | ||||
| func fatal(err string, code int) { | ||||
| 	fmt.Fprintf(os.Stderr, "[ctr] %s\n", err) | ||||
| 	os.Exit(code) | ||||
| 	panic(Exit{code}) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Kenfe-Mickael Laventure
					Kenfe-Mickael Laventure