coverity: #1435206

Time of check time of use Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 91ae555c
...@@ -667,33 +667,23 @@ void lxc_terminal_free(struct lxc_conf *conf, int fd) ...@@ -667,33 +667,23 @@ void lxc_terminal_free(struct lxc_conf *conf, int fd)
static int lxc_terminal_peer_default(struct lxc_terminal *terminal) static int lxc_terminal_peer_default(struct lxc_terminal *terminal)
{ {
struct lxc_terminal_state *ts; struct lxc_terminal_state *ts;
const char *path = terminal->path; const char *path;
int fd;
int ret = 0; int ret = 0;
if (!path) { if (terminal->path)
ret = access("/dev/tty", F_OK); path = terminal->path;
if (ret == 0) { else
/* If no terminal was given, try current controlling path = "/dev/tty";
* terminal, there won't be one if we were started as a
* daemon (-d).
*/
fd = open("/dev/tty", O_RDWR);
if (fd >= 0) {
close(fd);
path = "/dev/tty";
}
}
}
if (!path) {
errno = ENOTTY;
DEBUG("The process does not have a controlling terminal");
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) {
if (!terminal->path) {
errno = ENODEV;
DEBUG("%s - The process does not have a controlling "
"terminal", strerror(errno));
goto on_succes;
}
ERROR("%s - Failed to open proxy terminal \"%s\"", ERROR("%s - Failed to open proxy terminal \"%s\"",
strerror(errno), path); strerror(errno), path);
return -ENOTTY; return -ENOTTY;
......
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