terminal: lxc_terminal_peer_default()

parent 1b5e93c4
...@@ -671,65 +671,69 @@ static int lxc_terminal_peer_default(struct lxc_terminal *terminal) ...@@ -671,65 +671,69 @@ static int lxc_terminal_peer_default(struct lxc_terminal *terminal)
int fd; int fd;
int ret = 0; int ret = 0;
/* If no terminal was given, try current controlling terminal, there if (!path) {
* won't be one if we were started as a daemon (-d). ret = access("/dev/tty", F_OK);
*/ if (ret == 0) {
if (!path && !access("/dev/tty", F_OK)) { /* If no terminal was given, try current controlling
fd = open("/dev/tty", O_RDWR); * terminal, there won't be one if we were started as a
if (fd >= 0) { * daemon (-d).
close(fd); */
path = "/dev/tty"; fd = open("/dev/tty", O_RDWR);
if (fd >= 0) {
close(fd);
path = "/dev/tty";
}
} }
} }
if (!path) { if (!path) {
errno = ENOTTY; errno = ENOTTY;
DEBUG("process does not have a controlling terminal"); DEBUG("Theh process does not have a controlling terminal");
goto out; goto on_succes;
} }
terminal->peer = lxc_unpriv(open(path, O_RDWR | O_CLOEXEC)); terminal->peer = lxc_unpriv(open(path, O_RDWR | O_CLOEXEC));
if (terminal->peer < 0) { if (terminal->peer < 0) {
ERROR("Failed to open \"%s\": %s", path, strerror(errno)); ERROR("%s - Failed to open proxy terminal \"%s\"",
strerror(errno), path);
return -ENOTTY; return -ENOTTY;
} }
DEBUG("using \"%s\" as peer tty device", path); DEBUG("Using terminal \"%s\" as proxy", path);
if (!isatty(terminal->peer)) { if (!isatty(terminal->peer)) {
ERROR("file descriptor for file \"%s\" does not refer to a tty device", path); ERROR("File descriptor for \"%s\" does not refer to a terminal", path);
goto on_error1; goto on_error_free_tios;
} }
ts = lxc_terminal_signal_init(terminal->peer, terminal->master); ts = lxc_terminal_signal_init(terminal->peer, terminal->master);
terminal->tty_state = ts; terminal->tty_state = ts;
if (!ts) { if (!ts) {
WARN("Failed to install signal handler"); WARN("Failed to install signal handler");
goto on_error1; goto on_error_free_tios;
} }
lxc_terminal_winsz(terminal->peer, terminal->master); lxc_terminal_winsz(terminal->peer, terminal->master);
terminal->tios = malloc(sizeof(*terminal->tios)); terminal->tios = malloc(sizeof(*terminal->tios));
if (!terminal->tios) { if (!terminal->tios)
SYSERROR("failed to allocate memory"); goto on_error_free_tios;
goto on_error1;
}
if (lxc_setup_tios(terminal->peer, terminal->tios) < 0) ret = lxc_setup_tios(terminal->peer, terminal->tios);
goto on_error2; if (ret < 0)
goto on_error_close_peer;
else else
goto out; goto on_succes;
on_error2: on_error_free_tios:
free(terminal->tios); free(terminal->tios);
terminal->tios = NULL; terminal->tios = NULL;
on_error1: on_error_close_peer:
close(terminal->peer); close(terminal->peer);
terminal->peer = -1; terminal->peer = -1;
ret = -ENOTTY; ret = -ENOTTY;
out: on_succes:
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