From 5fba4820bd501fdaed6c77775808f12166c55399 Mon Sep 17 00:00:00 2001 From: Matej Marusak Date: Wed, 13 Sep 2017 08:09:35 +0200 Subject: [PATCH 4/4] lib: Introduce pid_for_children element from ns From namespaces man pages: /proc/[pid]/ns/pid_for_children (since Linux 4.12) This file is a handle for the PID namespace of child processes created by this process. Signed-off-by: Matej Marusak --- src/include/internal_libreport.h | 2 +- tests/proc_helpers.at | 39 ++++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/include/internal_libreport.h b/src/include/internal_libreport.h index 3527e0e1..1df4cba3 100644 --- a/src/include/internal_libreport.h +++ b/src/include/internal_libreport.h @@ -747,7 +747,7 @@ int get_env_variable(pid_t pid, const char *name, char **value); #define PROC_NS_ID_USER 4 #define PROC_NS_ID_UTS 5 #define PROC_NS_ID_CGROUP 6 -static const char * libreport_proc_namespaces[] = { "ipc", "mnt", "net", "pid", "uts", "user", "cgroup" }; +static const char * libreport_proc_namespaces[] = { "ipc", "mnt", "net", "pid", "uts", "user", "cgroup", "pid_for_children" }; struct ns_ids { ino_t nsi_ids[ARRAY_SIZE(libreport_proc_namespaces)]; diff --git a/tests/proc_helpers.at b/tests/proc_helpers.at index 35e9c7a5..4b118f33 100644 --- a/tests/proc_helpers.at +++ b/tests/proc_helpers.at @@ -945,30 +945,31 @@ AT_TESTFUN([dump_namespace_diff], [[ void check_file_contents(const char *filename) { - static const char *expected; + char *expected; struct stat st; - if (stat("/proc/self/ns/cgroup", &st) < 0 && errno == ENOENT) { - expected = "ipc : default\n" - "mnt : default\n" - "net : default\n" - "pid : default\n" - "uts : default\n" - "user : default\n" - "cgroup : unknown\n"; - } - else { - expected = "ipc : default\n" - "mnt : default\n" - "net : default\n" - "pid : default\n" - "uts : default\n" - "user : default\n" - "cgroup : default\n"; - } + + char const *pid_for_children = "default"; + char const *cgroup = "default"; + + if (stat("/proc/self/ns/cgroup", &st) < 0 && errno == ENOENT) + cgroup = "unknown"; + + if (stat("/proc/self/ns/pid_for_children", &st) < 0 && errno == ENOENT) + pid_for_children = "unknown"; + + expected = xasprintf("ipc : default\n" + "mnt : default\n" + "net : default\n" + "pid : default\n" + "uts : default\n" + "user : default\n" + "cgroup : %s\n" + "pid_for_children : %s\n", cgroup, pid_for_children); char *file = xmalloc_xopen_read_close(filename, NULL); TS_ASSERT_STRING_EQ(file, expected, "Namespaces"); free(file); + free(expected); } TS_MAIN -- 2.13.5