mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-25 19:14:04 +00:00
ns: Add possibility to read a ns by alternative name in __get_ns_id()
This is need for "/proc/[pid]/ns/pid_for_children_ns", which is a pid namespace with not standard file name. Also pass "alternative" parameter to generate_ns_id(). v2: Enlarge buffer size Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
parent
4c340548c9
commit
d197ed96ed
2 changed files with 12 additions and 8 deletions
|
|
@ -56,6 +56,7 @@
|
|||
struct ns_desc {
|
||||
unsigned int cflag;
|
||||
char *str;
|
||||
char *alt_str;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -410,7 +410,7 @@ int walk_namespaces(struct ns_desc *nd, int (*cb)(struct ns_id *, void *), void
|
|||
}
|
||||
|
||||
static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd,
|
||||
struct ns_id **ns_ret)
|
||||
struct ns_id **ns_ret, bool alternative)
|
||||
{
|
||||
struct ns_id *nsid;
|
||||
enum ns_type type;
|
||||
|
|
@ -456,18 +456,19 @@ found:
|
|||
return nsid->id;
|
||||
}
|
||||
|
||||
static unsigned int __get_ns_id(int pid, struct ns_desc *nd, protobuf_c_boolean *supported, struct ns_id **ns)
|
||||
static unsigned int __get_ns_id(int pid, struct ns_desc *nd, bool alternative,
|
||||
protobuf_c_boolean *supported, struct ns_id **ns)
|
||||
{
|
||||
int proc_dir;
|
||||
unsigned int kid;
|
||||
char ns_path[10];
|
||||
char ns_path[32];
|
||||
struct stat st;
|
||||
|
||||
proc_dir = open_pid_proc(pid);
|
||||
if (proc_dir < 0)
|
||||
return 0;
|
||||
|
||||
snprintf(ns_path, sizeof(ns_path), "ns/%s", nd->str);
|
||||
snprintf(ns_path, sizeof(ns_path), "ns/%s", !alternative ? nd->str : nd->alt_str);
|
||||
|
||||
if (fstatat(proc_dir, ns_path, &st, 0)) {
|
||||
if (errno == ENOENT) {
|
||||
|
|
@ -484,12 +485,12 @@ static unsigned int __get_ns_id(int pid, struct ns_desc *nd, protobuf_c_boolean
|
|||
out:
|
||||
if (supported)
|
||||
*supported = kid != 0;
|
||||
return generate_ns_id(pid, kid, nd, ns);
|
||||
return generate_ns_id(pid, kid, nd, ns, alternative);
|
||||
}
|
||||
|
||||
static unsigned int get_ns_id(int pid, struct ns_desc *nd, protobuf_c_boolean *supported)
|
||||
{
|
||||
return __get_ns_id(pid, nd, supported, NULL);
|
||||
return __get_ns_id(pid, nd, false, supported, NULL);
|
||||
}
|
||||
|
||||
int dump_one_ns_file(int lfd, u32 id, const struct fd_parms *p)
|
||||
|
|
@ -699,7 +700,8 @@ int predump_task_ns_ids(struct pstree_item *item)
|
|||
{
|
||||
int pid = item->pid->real;
|
||||
|
||||
if (!__get_ns_id(pid, &net_ns_desc, NULL, &dmpi(item)->netns))
|
||||
if (!__get_ns_id(pid, &net_ns_desc, false,
|
||||
NULL, &dmpi(item)->netns))
|
||||
return -1;
|
||||
|
||||
if (!get_ns_id(pid, &mnt_ns_desc, NULL))
|
||||
|
|
@ -735,7 +737,8 @@ int dump_task_ns_ids(struct pstree_item *item)
|
|||
return 0;
|
||||
|
||||
ids->has_net_ns_id = true;
|
||||
ids->net_ns_id = __get_ns_id(pid, &net_ns_desc, NULL, &dmpi(item)->netns);
|
||||
ids->net_ns_id = __get_ns_id(pid, &net_ns_desc, false,
|
||||
NULL, &dmpi(item)->netns);
|
||||
if (!ids->net_ns_id) {
|
||||
pr_err("Can't make netns id\n");
|
||||
return -1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue