]> git.proxmox.com Git - lxc.git/blob - debian/patches/0011-console-fix-console-info-message.patch
merge lxc-console improvements from stable branch
[lxc.git] / debian / patches / 0011-console-fix-console-info-message.patch
1 From c8a9c9c9f6c189164a2eedd0d1e99905cb0a8672 Mon Sep 17 00:00:00 2001
2 From: Christian Brauner <christian.brauner@ubuntu.com>
3 Date: Fri, 10 Nov 2017 19:07:38 +0100
4 Subject: [PATCH 11/13] console: fix console info message
5
6 Now it will be displayed nicely formatted:
7
8 a1 login: chb@conventiont|~
9 > lxc console a1
10
11 Connected to tty 0
12 Type <Ctrl+a q> to exit the console, <Ctrl+a Ctrl+a> to enter Ctrl+a itself
13
14 Ubuntu 17.10 a1 console
15
16 a1 login:
17
18 Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
19 ---
20 src/lxc/console.c | 54 ++++++++++++++++++++++++++----------------------------
21 1 file changed, 26 insertions(+), 28 deletions(-)
22
23 diff --git a/src/lxc/console.c b/src/lxc/console.c
24 index eda5be62..e95f5c54 100644
25 --- a/src/lxc/console.c
26 +++ b/src/lxc/console.c
27 @@ -675,26 +675,9 @@ int lxc_console(struct lxc_container *c, int ttynum,
28 struct lxc_tty_state *ts;
29 int istty = 0;
30
31 - istty = isatty(stdinfd);
32 - if (istty) {
33 - ret = lxc_setup_tios(stdinfd, &oldtios);
34 - if (ret < 0)
35 - return -1;
36 - } else {
37 - INFO("File descriptor %d does not refer to a tty device", stdinfd);
38 - }
39 -
40 ttyfd = lxc_cmd_console(c->name, &ttynum, &masterfd, c->config_path);
41 - if (ttyfd < 0) {
42 - ret = ttyfd;
43 - goto restore_tios;
44 - }
45 -
46 - fprintf(stderr, "\n"
47 - "Connected to tty %1$d\n"
48 - "Type <Ctrl+%2$c q> to exit the console, "
49 - "<Ctrl+%2$c Ctrl+%2$c> to enter Ctrl+%2$c itself\n",
50 - ttynum, 'a' + escape - 1);
51 + if (ttyfd < 0)
52 + return -1;
53
54 ret = setsid();
55 if (ret < 0)
56 @@ -710,9 +693,12 @@ int lxc_console(struct lxc_container *c, int ttynum,
57 ts->winch_proxy_lxcpath = c->config_path;
58 ts->stdoutfd = stdoutfd;
59
60 + istty = isatty(stdinfd);
61 if (istty) {
62 lxc_console_winsz(stdinfd, masterfd);
63 lxc_cmd_console_winch(ts->winch_proxy, ts->winch_proxy_lxcpath);
64 + } else {
65 + INFO("File descriptor %d does not refer to a tty device", stdinfd);
66 }
67
68 ret = lxc_mainloop_open(&descr);
69 @@ -744,14 +730,34 @@ int lxc_console(struct lxc_container *c, int ttynum,
70 goto close_mainloop;
71 }
72
73 + fprintf(stderr, "\n"
74 + "Connected to tty %1$d\n"
75 + "Type <Ctrl+%2$c q> to exit the console, "
76 + "<Ctrl+%2$c Ctrl+%2$c> to enter Ctrl+%2$c itself\n",
77 + ttynum, 'a' + escape - 1);
78 +
79 + if (istty) {
80 + ret = lxc_setup_tios(stdinfd, &oldtios);
81 + if (ret < 0)
82 + goto close_mainloop;
83 + }
84 +
85 ret = lxc_mainloop(&descr, -1);
86 if (ret < 0) {
87 ERROR("The mainloop returned an error");
88 - goto close_mainloop;
89 + goto restore_tios;
90 }
91
92 ret = 0;
93
94 +restore_tios:
95 + if (istty) {
96 + istty = tcsetattr(stdinfd, TCSAFLUSH, &oldtios);
97 + if (istty < 0)
98 + WARN("%s - Failed to restore terminal properties",
99 + strerror(errno));
100 + }
101 +
102 close_mainloop:
103 lxc_mainloop_close(&descr);
104
105 @@ -762,13 +768,5 @@ close_fds:
106 close(masterfd);
107 close(ttyfd);
108
109 -restore_tios:
110 - if (istty) {
111 - istty = tcsetattr(stdinfd, TCSAFLUSH, &oldtios);
112 - if (istty < 0)
113 - WARN("%s - Failed to restore terminal properties",
114 - strerror(errno));
115 - }
116 -
117 return ret;
118 }
119 --
120 2.11.0
121