2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-09-04 00:05:26 +00:00

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: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Cyrill Gorcunov
2012-09-14 17:50:42 +04:00
committed by Pavel Emelyanov
parent 978cecd629
commit 07aa668282

50
tty.c
View File

@@ -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;
} }
return sid;
}
static int tty_get_pgrp(int fd) ret = ioctl(fd, TIOCGPGRP, pgrp);
{
int prgp, ret;
ret = ioctl(fd, TIOCGPGRP, &prgp);
if (ret < 0) { if (ret < 0) {
if (errno != ENOTTY) { if (errno != ENOTTY)
pr_perror("Can't get prgp on %d", fd); goto err;
return -1; *pgrp = 0;
}
prgp = 0;
} }
return prgp;
*hangup = false;
return 0;
err:
if (errno != EIO) {
pr_perror("Can't get sid/pgrp on %d", fd);
return -1;
}
/* kernel reports EIO for get ioctls on pair-less ptys */
*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
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;