Blame 0004-lib-Introduce-pid_for_children-element-from-ns.patch

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