mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 14:25:49 +00:00
parasite: Add parasite_dump_tty helper
Will need it to fetch tty link parameters. This is because the kernel provides SID/PGID related to the caller context, and if we're dumping the process inside namespace -- we need local SID/PGIDs, not global ones. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
f96f580569
commit
a9241a23f7
@@ -49,4 +49,6 @@ extern int parasite_cure_seized(struct parasite_ctl *ctl);
|
||||
extern struct parasite_ctl *parasite_infect_seized(pid_t pid,
|
||||
struct list_head *vma_area_list);
|
||||
|
||||
extern int parasite_dump_tty(struct parasite_ctl *ctl);
|
||||
|
||||
#endif /* PARASITE_SYSCALL_H_ */
|
||||
|
@@ -33,6 +33,7 @@ enum {
|
||||
PARASITE_CMD_DUMP_TID_ADDR,
|
||||
PARASITE_CMD_DRAIN_FDS,
|
||||
PARASITE_CMD_GET_PROC_FD,
|
||||
PARASITE_CMD_DUMP_TTY,
|
||||
|
||||
PARASITE_CMD_MAX,
|
||||
};
|
||||
@@ -105,6 +106,14 @@ static inline int drain_fds_size(struct parasite_drain_fd *dfds)
|
||||
return sizeof(dfds->nr_fds) + dfds->nr_fds * sizeof(dfds->fds[0]);
|
||||
}
|
||||
|
||||
struct parasite_dump_tty {
|
||||
int fd;
|
||||
|
||||
int sid;
|
||||
int pgrp;
|
||||
bool hangup;
|
||||
};
|
||||
|
||||
/*
|
||||
* Some useful offsets
|
||||
*/
|
||||
|
@@ -532,6 +532,17 @@ int parasite_dump_misc_seized(struct parasite_ctl *ctl, struct parasite_dump_mis
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parasite_dump_tty(struct parasite_ctl *ctl)
|
||||
{
|
||||
struct parasite_dump_tty *p;
|
||||
|
||||
p = parasite_args(ctl, sizeof(*p));
|
||||
if (parasite_execute(PARASITE_CMD_DUMP_TTY, ctl) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parasite_dump_creds(struct parasite_ctl *ctl, CredsEntry *ce)
|
||||
{
|
||||
struct parasite_dump_creds *pc;
|
||||
|
39
parasite.c
39
parasite.c
@@ -4,6 +4,7 @@
|
||||
#include <linux/limits.h>
|
||||
#include <sys/mount.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "syscall.h"
|
||||
#include "parasite.h"
|
||||
@@ -451,6 +452,41 @@ out_send_fd:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int parasite_dump_tty(struct parasite_dump_tty *args)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sys_ioctl(args->fd, TIOCGSID, (unsigned long)&args->sid);
|
||||
if (ret < 0) {
|
||||
if (ret != -ENOTTY)
|
||||
goto err;
|
||||
args->sid = 0;
|
||||
}
|
||||
|
||||
ret = sys_ioctl(args->fd, TIOCGPGRP, (unsigned long)&args->pgrp);
|
||||
if (ret < 0) {
|
||||
if (ret != -ENOTTY)
|
||||
goto err;
|
||||
args->pgrp = 0;
|
||||
}
|
||||
|
||||
args->hangup = false;
|
||||
return 0;
|
||||
|
||||
err:
|
||||
if (ret != -EIO) {
|
||||
pr_err("TTY: Can't get sid/pgrp\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* kernel reports EIO for get ioctls on pair-less ptys */
|
||||
args->sid = 0;
|
||||
args->pgrp = 0;
|
||||
args->hangup = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parasite_cfg_log(struct parasite_log_args *args)
|
||||
{
|
||||
int ret;
|
||||
@@ -484,6 +520,7 @@ int __used parasite_service(unsigned int cmd, void *args)
|
||||
BUILD_BUG_ON(sizeof(struct parasite_dump_misc) > PARASITE_ARG_SIZE);
|
||||
BUILD_BUG_ON(sizeof(struct parasite_dump_tid_info) > PARASITE_ARG_SIZE);
|
||||
BUILD_BUG_ON(sizeof(struct parasite_drain_fd) > PARASITE_ARG_SIZE);
|
||||
BUILD_BUG_ON(sizeof(struct parasite_dump_tty) > PARASITE_ARG_SIZE);
|
||||
|
||||
pr_info("Parasite cmd %d/%x process\n", cmd, cmd);
|
||||
|
||||
@@ -514,6 +551,8 @@ int __used parasite_service(unsigned int cmd, void *args)
|
||||
return drain_fds((struct parasite_drain_fd *)args);
|
||||
case PARASITE_CMD_GET_PROC_FD:
|
||||
return parasite_get_proc_fd();
|
||||
case PARASITE_CMD_DUMP_TTY:
|
||||
return parasite_dump_tty((struct parasite_dump_tty *)args);
|
||||
}
|
||||
|
||||
pr_err("Unknown command to parasite\n");
|
||||
|
Reference in New Issue
Block a user