Commit 07aa6682 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

tty: Squash tty_get_sid, tty_get_pgrp into tty_get_sid_pgrp

This patch squashes tty_get_sid, tty_get_pgrp into
one tty_get_sid_pgrp helper (which allows to detect
if dumping terminal is hanging up, the real use of
this ability will be addressed in next patch).
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 978cecd6
...@@ -290,34 +290,37 @@ static int lock_pty(int fd) ...@@ -290,34 +290,37 @@ static int lock_pty(int fd)
return 0; return 0;
} }
static int tty_get_sid(int fd) static int tty_get_sid_pgrp(int fd, int *sid, int *pgrp, bool *hangup)
{ {
int sid, ret; int ret;
ret = ioctl(fd, TIOCGSID, &sid); ret = ioctl(fd, TIOCGSID, sid);
if (ret < 0) { if (ret < 0) {
if (errno != ENOTTY) { if (errno != ENOTTY)
pr_perror("Can't get sid on %d", fd); goto err;
return -1; *sid = 0;
} }
sid = 0;
ret = ioctl(fd, TIOCGPGRP, pgrp);
if (ret < 0) {
if (errno != ENOTTY)
goto err;
*pgrp = 0;
} }
return sid;
}
static int tty_get_pgrp(int fd) *hangup = false;
{ return 0;
int prgp, ret;
ret = ioctl(fd, TIOCGPGRP, &prgp); err:
if (ret < 0) { if (errno != EIO) {
if (errno != ENOTTY) { pr_perror("Can't get sid/pgrp on %d", fd);
pr_perror("Can't get prgp on %d", fd);
return -1; return -1;
} }
prgp = 0;
} /* kernel reports EIO for get ioctls on pair-less ptys */
return prgp; *sid = *pgrp = 0;
*hangup = true;
return 0;
} }
static int tty_set_sid(int fd) static int tty_set_sid(int fd)
...@@ -789,14 +792,13 @@ static int dump_pty_info(int lfd, u32 id, const struct fd_parms *p, int major, i ...@@ -789,14 +792,13 @@ static int dump_pty_info(int lfd, u32 id, const struct fd_parms *p, int major, i
WinsizeEntry winsize = WINSIZE_ENTRY__INIT; WinsizeEntry winsize = WINSIZE_ENTRY__INIT;
TtyPtyEntry pty = TTY_PTY_ENTRY__INIT; TtyPtyEntry pty = TTY_PTY_ENTRY__INIT;
bool hangup = false;
struct termios t; struct termios t;
struct winsize w; struct winsize w;
int ret = -1, sid, pgrp; int ret = -1, sid, pgrp;
sid = tty_get_sid(lfd); if (tty_get_sid_pgrp(lfd, &sid, &pgrp, &hangup))
pgrp = tty_get_pgrp(lfd);
if (sid < 0 || pgrp < 0)
return -1; return -1;
info.id = id; info.id = id;
......
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