]> git.proxmox.com Git - lxc.git/blob - debian/patches/0009-console-non-functional-changes.patch
merge lxc-console improvements from stable branch
[lxc.git] / debian / patches / 0009-console-non-functional-changes.patch
1 From 105ec17dbcad4fc48183a824df13b825974848bb Mon Sep 17 00:00:00 2001
2 From: Christian Brauner <christian.brauner@ubuntu.com>
3 Date: Mon, 23 Oct 2017 13:41:33 +0200
4 Subject: [PATCH 09/13] console: non-functional changes
5
6 Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
7 ---
8 src/lxc/console.c | 39 +++++++++++++++++++++++----------------
9 1 file changed, 23 insertions(+), 16 deletions(-)
10
11 diff --git a/src/lxc/console.c b/src/lxc/console.c
12 index c8e545eb..3592662b 100644
13 --- a/src/lxc/console.c
14 +++ b/src/lxc/console.c
15 @@ -498,9 +498,13 @@ out:
16
17 void lxc_console_delete(struct lxc_console *console)
18 {
19 - if (console->tios && console->peer >= 0 &&
20 - tcsetattr(console->peer, TCSAFLUSH, console->tios))
21 - WARN("failed to set old terminal settings");
22 + int ret;
23 +
24 + if (console->tios && console->peer >= 0) {
25 + ret = tcsetattr(console->peer, TCSAFLUSH, console->tios);
26 + if (ret < 0)
27 + WARN("%s - Failed to set old terminal settings", strerror(errno));
28 + }
29 free(console->tios);
30 console->tios = NULL;
31
32 @@ -509,7 +513,6 @@ void lxc_console_delete(struct lxc_console *console)
33 close(console->slave);
34 if (console->log_fd >= 0)
35 close(console->log_fd);
36 -
37 console->peer = -1;
38 console->master = -1;
39 console->slave = -1;
40 @@ -518,57 +521,61 @@ void lxc_console_delete(struct lxc_console *console)
41
42 int lxc_console_create(struct lxc_conf *conf)
43 {
44 + int ret, saved_errno;
45 struct lxc_console *console = &conf->console;
46 - int ret;
47
48 if (!conf->rootfs.path) {
49 - INFO("container does not have a rootfs, console device will be shared with the host");
50 + INFO("Container does not have a rootfs. The console will be "
51 + "shared with the host");
52 return 0;
53 }
54
55 if (console->path && !strcmp(console->path, "none")) {
56 - INFO("no console requested");
57 + INFO("No console was requested");
58 return 0;
59 }
60
61 process_lock();
62 ret = openpty(&console->master, &console->slave, console->name, NULL, NULL);
63 + saved_errno = errno;
64 process_unlock();
65 if (ret < 0) {
66 - SYSERROR("failed to allocate a pty");
67 + ERROR("%s - Failed to allocate a pty", strerror(saved_errno));
68 return -1;
69 }
70
71 - if (fcntl(console->master, F_SETFD, FD_CLOEXEC)) {
72 - SYSERROR("failed to set console master to close-on-exec");
73 + ret = fcntl(console->master, F_SETFD, FD_CLOEXEC);
74 + if (ret < 0) {
75 + SYSERROR("Failed to set FD_CLOEXEC flag on console master");
76 goto err;
77 }
78
79 - if (fcntl(console->slave, F_SETFD, FD_CLOEXEC)) {
80 - SYSERROR("failed to set console slave to close-on-exec");
81 + ret = fcntl(console->slave, F_SETFD, FD_CLOEXEC);
82 + if (ret < 0) {
83 + SYSERROR("Failed to set FD_CLOEXEC flag on console slave");
84 goto err;
85 }
86
87 ret = lxc_console_peer_default(console);
88 if (ret < 0) {
89 - ERROR("failed to allocate peer tty device");
90 + ERROR("Failed to allocate a peer pty device");
91 goto err;
92 }
93
94 if (console->log_path) {
95 console->log_fd = lxc_unpriv(open(console->log_path, O_CLOEXEC | O_RDWR | O_CREAT | O_APPEND, 0600));
96 if (console->log_fd < 0) {
97 - SYSERROR("failed to open console log file \"%s\"", console->log_path);
98 + SYSERROR("Failed to open console log file \"%s\"", console->log_path);
99 goto err;
100 }
101 - DEBUG("using \"%s\" as console log file", console->log_path);
102 + DEBUG("Using \"%s\" as console log file", console->log_path);
103 }
104
105 return 0;
106
107 err:
108 lxc_console_delete(console);
109 - return -1;
110 + return -ENODEV;
111 }
112
113 int lxc_console_set_stdfds(int fd)
114 --
115 2.11.0
116