console: non-functional changes

parent 63b74cda
...@@ -780,18 +780,16 @@ int lxc_console(struct lxc_container *c, int ttynum, ...@@ -780,18 +780,16 @@ int lxc_console(struct lxc_container *c, int ttynum,
istty = isatty(stdinfd); istty = isatty(stdinfd);
if (istty) { if (istty) {
ret = lxc_setup_tios(stdinfd, &oldtios); ret = lxc_setup_tios(stdinfd, &oldtios);
if (ret) { if (ret < 0)
ERROR("failed to setup terminal properties");
return -1; return -1;
}
} else { } else {
INFO("fd %d does not refer to a tty device", stdinfd); INFO("File descriptor %d does not refer to a tty device", stdinfd);
} }
ttyfd = lxc_cmd_console(c->name, &ttynum, &masterfd, c->config_path); ttyfd = lxc_cmd_console(c->name, &ttynum, &masterfd, c->config_path);
if (ttyfd < 0) { if (ttyfd < 0) {
ret = ttyfd; ret = ttyfd;
goto err1; goto restore_tios;
} }
fprintf(stderr, "\n" fprintf(stderr, "\n"
...@@ -801,13 +799,13 @@ int lxc_console(struct lxc_container *c, int ttynum, ...@@ -801,13 +799,13 @@ int lxc_console(struct lxc_container *c, int ttynum,
ttynum, 'a' + escape - 1); ttynum, 'a' + escape - 1);
ret = setsid(); ret = setsid();
if (ret) if (ret < 0)
INFO("already group leader"); TRACE("Process is already group leader");
ts = lxc_console_sigwinch_init(stdinfd, masterfd); ts = lxc_console_sigwinch_init(stdinfd, masterfd);
if (!ts) { if (!ts) {
ret = -1; ret = -1;
goto err2; goto close_fds;
} }
ts->escape = escape; ts->escape = escape;
ts->winch_proxy = c->name; ts->winch_proxy = c->name;
...@@ -821,52 +819,57 @@ int lxc_console(struct lxc_container *c, int ttynum, ...@@ -821,52 +819,57 @@ int lxc_console(struct lxc_container *c, int ttynum,
ret = lxc_mainloop_open(&descr); ret = lxc_mainloop_open(&descr);
if (ret) { if (ret) {
ERROR("failed to create mainloop"); ERROR("Failed to create mainloop");
goto err3; goto sigwinch_fini;
} }
if (ts->sigfd != -1) { if (ts->sigfd != -1) {
ret = lxc_mainloop_add_handler(&descr, ts->sigfd, ret = lxc_mainloop_add_handler(&descr, ts->sigfd,
lxc_console_cb_sigwinch_fd, ts); lxc_console_cb_sigwinch_fd, ts);
if (ret) { if (ret < 0) {
ERROR("failed to add handler for SIGWINCH fd"); ERROR("Failed to add SIGWINCH handler");
goto err4; goto close_mainloop;
} }
} }
ret = lxc_mainloop_add_handler(&descr, ts->stdinfd, ret = lxc_mainloop_add_handler(&descr, ts->stdinfd,
lxc_console_cb_tty_stdin, ts); lxc_console_cb_tty_stdin, ts);
if (ret) { if (ret < 0) {
ERROR("failed to add handler for stdinfd"); ERROR("Failed to add stdin handler");
goto err4; goto close_mainloop;
} }
ret = lxc_mainloop_add_handler(&descr, ts->masterfd, ret = lxc_mainloop_add_handler(&descr, ts->masterfd,
lxc_console_cb_tty_master, ts); lxc_console_cb_tty_master, ts);
if (ret) { if (ret < 0) {
ERROR("failed to add handler for masterfd"); ERROR("Failed to add master handler");
goto err4; goto close_mainloop;
} }
ret = lxc_mainloop(&descr, -1); ret = lxc_mainloop(&descr, -1);
if (ret) { if (ret < 0) {
ERROR("mainloop returned an error"); ERROR("The mainloop returned an error");
goto err4; goto close_mainloop;
} }
ret = 0; ret = 0;
err4: close_mainloop:
lxc_mainloop_close(&descr); lxc_mainloop_close(&descr);
err3:
sigwinch_fini:
lxc_console_sigwinch_fini(ts); lxc_console_sigwinch_fini(ts);
err2:
close_fds:
close(masterfd); close(masterfd);
close(ttyfd); close(ttyfd);
err1:
restore_tios:
if (istty) { if (istty) {
if (tcsetattr(stdinfd, TCSAFLUSH, &oldtios) < 0) istty = tcsetattr(stdinfd, TCSAFLUSH, &oldtios);
WARN("failed to reset terminal properties: %s.", strerror(errno)); if (istty < 0)
WARN("%s - Failed to restore terminal properties",
strerror(errno));
} }
return ret; return ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment