Blame SOURCES/0137-Implement-testing-framework-for-pidns.patch

b4ec74
From 4362ddaba8634a5ac6b4add0eaf25eec5f7315f5 Mon Sep 17 00:00:00 2001
b4ec74
From: =?UTF-8?q?=C3=81kos=20Uzonyi?= <uzonyi.akos@gmail.com>
b4ec74
Date: Fri, 26 Jun 2020 20:13:28 +0200
b4ec74
Subject: [PATCH 137/138] Implement testing framework for pidns
b4ec74
b4ec74
* tests/pidns.c: New file.
b4ec74
* tests/pidns.h: New file.
b4ec74
* tests/Makefile.am (libtests_a_SOURCES): Add pidns.c, pidns.h.
b4ec74
* tests/init.sh (test_pidns, test_pidns_run_strace): New functions.
b4ec74
---
b4ec74
 tests/Makefile.am |   2 +
b4ec74
 tests/init.sh     |  30 +++++++
b4ec74
 tests/pidns.c     | 237 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
b4ec74
 tests/pidns.h     |  56 +++++++++++++
b4ec74
 4 files changed, 325 insertions(+)
b4ec74
 create mode 100644 tests/pidns.c
b4ec74
 create mode 100644 tests/pidns.h
b4ec74
b4ec74
Index: strace-5.7/tests/Makefile.am
b4ec74
===================================================================
b4ec74
--- strace-5.7.orig/tests/Makefile.am	2020-09-09 19:32:50.846965498 +0200
b4ec74
+++ strace-5.7/tests/Makefile.am	2020-09-09 19:49:54.008575349 +0200
b4ec74
@@ -44,6 +44,8 @@
b4ec74
 	libsocketcall.c \
b4ec74
 	lock_file.c \
b4ec74
 	overflowuid.c \
b4ec74
+	pidns.c \
b4ec74
+	pidns.h \
b4ec74
 	pipe_maxfd.c \
b4ec74
 	print_quoted_string.c \
b4ec74
 	print_time.c \
b4ec74
Index: strace-5.7/tests/init.sh
b4ec74
===================================================================
b4ec74
--- strace-5.7.orig/tests/init.sh	2020-09-09 19:32:50.846965498 +0200
b4ec74
+++ strace-5.7/tests/init.sh	2020-09-09 19:49:54.008575349 +0200
b4ec74
@@ -387,6 +387,36 @@
b4ec74
 	test_pure_prog_set "$@" < "$srcdir/$NAME.in"
b4ec74
 }
b4ec74
 
b4ec74
+test_pidns_run_strace()
b4ec74
+{
b4ec74
+	local parent_pid init_pid
b4ec74
+
b4ec74
+	check_prog tail
b4ec74
+	check_prog cut
b4ec74
+	check_prog grep
b4ec74
+
b4ec74
+	run_prog > /dev/null
b4ec74
+	run_strace --pidns-translation -f $@ $args > "$EXP"
b4ec74
+
b4ec74
+	# filter out logs made by the parent or init process of the pidns test
b4ec74
+	parent_pid="$(tail -n 2 $LOG | head -n 1 | cut -d' ' -f1)"
b4ec74
+	init_pid="$(tail -n 1 $LOG | cut -d' ' -f1)"
b4ec74
+	grep -E -v "^($parent_pid|$init_pid) " "$LOG" > "$OUT"
b4ec74
+	match_diff "$OUT" "$EXP"
b4ec74
+}
b4ec74
+
b4ec74
+test_pidns()
b4ec74
+{
b4ec74
+	check_prog unshare
b4ec74
+	unshare -Urpf true || framework_skip_ "unshare -Urpf true failed"
b4ec74
+
b4ec74
+	test_pidns_run_strace "$@"
b4ec74
+
b4ec74
+	# test PID translation when /proc is mounted from an other namespace
b4ec74
+	STRACE="unshare -Urpf $STRACE"
b4ec74
+	test_pidns_run_strace "$@"
b4ec74
+}
b4ec74
+
b4ec74
 check_prog cat
b4ec74
 check_prog rm
b4ec74
 
b4ec74
Index: strace-5.7/tests/pidns.c
b4ec74
===================================================================
b4ec74
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
b4ec74
+++ strace-5.7/tests/pidns.c	2020-09-09 19:49:54.009575350 +0200
b4ec74
@@ -0,0 +1,237 @@
b4ec74
+/*
b4ec74
+ * Testing framework for PID namespace translation
b4ec74
+ *
b4ec74
+ * Copyright (c) 2020 Ákos Uzonyi <uzonyi.akos@gmail.com>
b4ec74
+ * All rights reserved.
b4ec74
+ *
b4ec74
+ * SPDX-License-Identifier: LGPL-2.1-or-later
b4ec74
+ */
b4ec74
+#include "tests.h"
b4ec74
+#include "pidns.h"
b4ec74
+#include "nsfs.h"
b4ec74
+
b4ec74
+#include <errno.h>
b4ec74
+#include <stdio.h>
b4ec74
+#include <string.h>
b4ec74
+#include <sys/types.h>
b4ec74
+#include <signal.h>
b4ec74
+#include <stdlib.h>
b4ec74
+#include <sched.h>
b4ec74
+#include <unistd.h>
b4ec74
+#include <sys/wait.h>
b4ec74
+#include <linux/sched.h>
b4ec74
+#include <fcntl.h>
b4ec74
+#include <sys/ioctl.h>
b4ec74
+
b4ec74
+#ifndef CLONE_NEWUSER
b4ec74
+# define CLONE_NEWUSER 0x10000000
b4ec74
+#endif
b4ec74
+
b4ec74
+#ifndef CLONE_NEWPID
b4ec74
+# define CLONE_NEWPID 0x20000000
b4ec74
+#endif
b4ec74
+
b4ec74
+static bool pidns_translation = false;
b4ec74
+static bool pidns_unshared = false;
b4ec74
+
b4ec74
+/* Our PIDs in strace's namespace */
b4ec74
+static pid_t pidns_strace_ids[PT_COUNT];
b4ec74
+
b4ec74
+void
b4ec74
+pidns_print_leader(void)
b4ec74
+{
b4ec74
+	if (pidns_translation)
b4ec74
+		printf("%-5d ", pidns_strace_ids[PT_TID]);
b4ec74
+}
b4ec74
+
b4ec74
+const char *
b4ec74
+pidns_pid2str(enum pid_type type)
b4ec74
+{
b4ec74
+	static const char format[] = " /* %d in strace's PID NS */";
b4ec74
+	static char buf[PT_COUNT][sizeof(format) + sizeof(int) * 3];
b4ec74
+
b4ec74
+	if (type < 0 || type >= PT_COUNT)
b4ec74
+		return "";
b4ec74
+
b4ec74
+	if (!pidns_unshared || !pidns_strace_ids[type])
b4ec74
+		return "";
b4ec74
+
b4ec74
+	snprintf(buf[type], sizeof(buf[type]), format, pidns_strace_ids[type]);
b4ec74
+	return buf[type];
b4ec74
+}
b4ec74
+
b4ec74
+/**
b4ec74
+ * This function is like fork, but does a few more things. It sets up the
b4ec74
+ * child's PGID and SID according to the parameters. Also it fills the
b4ec74
+ * pidns_strace_ids array in the child's memory with the PIDs of the child in
b4ec74
+ * parent's PID namespace. In the parent it waits for the child to terminate
b4ec74
+ * (but leaves the zombie to use it later as a process group). If the child
b4ec74
+ * terminates with nonzero exit status, the test is failed.
b4ec74
+ *
b4ec74
+ * @param pgid     The process group the child should be moved to. It's expected
b4ec74
+ *                 to be a PID of a zombie process (will be reaped). If
b4ec74
+ *                 negative, leave the child in the process group of the parent.
b4ec74
+ *                 If 0, move the process to its own process group.
b4ec74
+ * @param new_sid  Wheather child should be moved to a new session.
b4ec74
+ */
b4ec74
+static pid_t
b4ec74
+pidns_fork(pid_t pgid, bool new_sid)
b4ec74
+{
b4ec74
+	int strace_ids_pipe[2];
b4ec74
+	if (pipe(strace_ids_pipe) < 0)
b4ec74
+		perror_msg_and_fail("pipe");
b4ec74
+
b4ec74
+	fflush(stdout);
b4ec74
+	pid_t pid = fork();
b4ec74
+	if (pid < 0)
b4ec74
+		perror_msg_and_fail("fork");
b4ec74
+
b4ec74
+	if (!pid) {
b4ec74
+		close(strace_ids_pipe[1]);
b4ec74
+
b4ec74
+		ssize_t len = read(strace_ids_pipe[0], pidns_strace_ids,
b4ec74
+				sizeof(pidns_strace_ids));
b4ec74
+		if (len < 0)
b4ec74
+			perror_msg_and_fail("read");
b4ec74
+		if (len != sizeof(pidns_strace_ids))
b4ec74
+			error_msg_and_fail("read returned < sizeof(pidns_strace_ids)");
b4ec74
+
b4ec74
+		close(strace_ids_pipe[0]);
b4ec74
+
b4ec74
+		if (pidns_strace_ids[PT_SID])
b4ec74
+			setsid();
b4ec74
+
b4ec74
+		return 0;
b4ec74
+	}
b4ec74
+
b4ec74
+	pidns_strace_ids[PT_TID] = pid;
b4ec74
+	pidns_strace_ids[PT_TGID] = pid;
b4ec74
+	pidns_strace_ids[PT_PGID] = 0;
b4ec74
+	pidns_strace_ids[PT_SID] = 0;
b4ec74
+
b4ec74
+	if (!pgid)
b4ec74
+		pgid = pid;
b4ec74
+
b4ec74
+	if (pgid > 0) {
b4ec74
+		if (setpgid(pid, pgid) < 0)
b4ec74
+			perror_msg_and_fail("setpgid");
b4ec74
+
b4ec74
+		pidns_strace_ids[PT_PGID] = pgid;
b4ec74
+	}
b4ec74
+
b4ec74
+	/* Reap group leader to test PGID decoding */
b4ec74
+	if (pgid > 0 && pgid != pid) {
b4ec74
+		int ret = waitpid(pgid, NULL, WNOHANG);
b4ec74
+		if (ret < 0)
b4ec74
+			perror_msg_and_fail("wait");
b4ec74
+		if (!ret)
b4ec74
+			error_msg_and_fail("could not reap group leader");
b4ec74
+	}
b4ec74
+
b4ec74
+	if (new_sid) {
b4ec74
+		pidns_strace_ids[PT_SID] = pid;
b4ec74
+		pidns_strace_ids[PT_PGID] = pid;
b4ec74
+	}
b4ec74
+
b4ec74
+	ssize_t len = write(strace_ids_pipe[1], pidns_strace_ids,
b4ec74
+	                     sizeof(pidns_strace_ids));
b4ec74
+	if (len < 0)
b4ec74
+		perror_msg_and_fail("write");
b4ec74
+	if (len != sizeof(pidns_strace_ids))
b4ec74
+		error_msg_and_fail("write returned < sizeof(pidns_strace_ids)");
b4ec74
+
b4ec74
+	close(strace_ids_pipe[0]);
b4ec74
+	close(strace_ids_pipe[1]);
b4ec74
+
b4ec74
+	/* WNOWAIT: leave the zombie, to be able to use it as a process group */
b4ec74
+	siginfo_t siginfo;
b4ec74
+	if (waitid(P_PID, pid, &siginfo, WEXITED | WNOWAIT) < 0)
b4ec74
+		perror_msg_and_fail("wait");
b4ec74
+	if (siginfo.si_code != CLD_EXITED || siginfo.si_status)
b4ec74
+		error_msg_and_fail("child terminated with nonzero exit status");
b4ec74
+
b4ec74
+	return pid;
b4ec74
+}
b4ec74
+
b4ec74
+static void
b4ec74
+create_init_process(void)
b4ec74
+{
b4ec74
+	int child_pipe[2];
b4ec74
+	if (pipe(child_pipe) < 0)
b4ec74
+		perror_msg_and_fail("pipe");
b4ec74
+
b4ec74
+	pid_t pid = fork();
b4ec74
+	if (pid < 0)
b4ec74
+		perror_msg_and_fail("fork");
b4ec74
+
b4ec74
+	if (!pid) {
b4ec74
+		close(child_pipe[1]);
b4ec74
+		if (read(child_pipe[0], &child_pipe[1], sizeof(int)) != 0)
b4ec74
+			_exit(1);
b4ec74
+		_exit(0);
b4ec74
+	}
b4ec74
+
b4ec74
+	close(child_pipe[0]);
b4ec74
+}
b4ec74
+
b4ec74
+void
b4ec74
+check_ns_ioctl(void)
b4ec74
+{
b4ec74
+	int fd = open("/proc/self/ns/pid", O_RDONLY);
b4ec74
+	if (fd < 0) {
b4ec74
+		if (errno == ENOENT)
b4ec74
+			perror_msg_and_skip("opening /proc/self/ns/pid");
b4ec74
+		else
b4ec74
+			perror_msg_and_fail("opening /proc/self/ns/pid");
b4ec74
+	}
b4ec74
+
b4ec74
+	int userns_fd = ioctl(fd, NS_GET_USERNS);
b4ec74
+	if (userns_fd < 0) {
b4ec74
+		if (errno == ENOTTY)
b4ec74
+			error_msg_and_skip("NS_* ioctl commands are not "
b4ec74
+			                   "supported by the kernel");
b4ec74
+		else
b4ec74
+			perror_msg_and_fail("ioctl(NS_GET_USERNS)");
b4ec74
+	}
b4ec74
+
b4ec74
+	close(userns_fd);
b4ec74
+	close(fd);
b4ec74
+}
b4ec74
+
b4ec74
+void
b4ec74
+pidns_test_init(void)
b4ec74
+{
b4ec74
+	pidns_translation = true;
b4ec74
+
b4ec74
+	check_ns_ioctl();
b4ec74
+
b4ec74
+	if (!pidns_fork(-1, false))
b4ec74
+		return;
b4ec74
+
b4ec74
+	/* Unshare user namespace too, so we do not need to be root */
b4ec74
+	if (unshare(CLONE_NEWUSER | CLONE_NEWPID) < 0) {
b4ec74
+		if (errno == EPERM)
b4ec74
+			perror_msg_and_skip("unshare");
b4ec74
+
b4ec74
+		perror_msg_and_fail("unshare");
b4ec74
+	}
b4ec74
+
b4ec74
+	pidns_unshared = true;
b4ec74
+
b4ec74
+	create_init_process();
b4ec74
+
b4ec74
+	if (!pidns_fork(-1, false))
b4ec74
+		return;
b4ec74
+
b4ec74
+	if (!pidns_fork(-1, true))
b4ec74
+		return;
b4ec74
+
b4ec74
+	pid_t pgid;
b4ec74
+	if (!(pgid = pidns_fork(0, false)))
b4ec74
+		return;
b4ec74
+
b4ec74
+	if (!pidns_fork(pgid, false))
b4ec74
+		return;
b4ec74
+
b4ec74
+	exit(0);
b4ec74
+}
b4ec74
Index: strace-5.7/tests/pidns.h
b4ec74
===================================================================
b4ec74
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
b4ec74
+++ strace-5.7/tests/pidns.h	2020-09-09 19:49:54.009575350 +0200
b4ec74
@@ -0,0 +1,56 @@
b4ec74
+/*
b4ec74
+ * Test PID namespace translation
b4ec74
+ *
b4ec74
+ * Copyright (c) 2020 Ákos Uzonyi <uzonyi.akos@gmail.com>
b4ec74
+ * All rights reserved.
b4ec74
+ *
b4ec74
+ * SPDX-License-Identifier: LGPL-2.1-or-later
b4ec74
+ */
b4ec74
+#ifndef STRACE_PIDNS_H
b4ec74
+#define STRACE_PIDNS_H
b4ec74
+
b4ec74
+#ifdef PIDNS_TRANSLATION
b4ec74
+# define PIDNS_TEST_INIT pidns_test_init()
b4ec74
+#else
b4ec74
+# define PIDNS_TEST_INIT
b4ec74
+#endif
b4ec74
+
b4ec74
+#include <sys/types.h>
b4ec74
+
b4ec74
+enum pid_type {
b4ec74
+	PT_TID,
b4ec74
+	PT_TGID,
b4ec74
+	PT_PGID,
b4ec74
+	PT_SID,
b4ec74
+
b4ec74
+	PT_COUNT,
b4ec74
+	PT_NONE = -1
b4ec74
+};
b4ec74
+
b4ec74
+/* Prints leader (process tid) if pidns_test_init was called */
b4ec74
+void pidns_print_leader(void);
b4ec74
+
b4ec74
+/*
b4ec74
+ * Returns a static buffer containing the translation string of our PID.
b4ec74
+ */
b4ec74
+const char *pidns_pid2str(enum pid_type type);
b4ec74
+
b4ec74
+/**
b4ec74
+ * Skips the test if NS_* ioctl commands are not supported by the kernel.
b4ec74
+ */
b4ec74
+void check_ns_ioctl(void);
b4ec74
+
b4ec74
+/**
b4ec74
+ * Init pidns testing.
b4ec74
+ *
b4ec74
+ * Should be called at the beginning of the test's main function
b4ec74
+ *
b4ec74
+ * This function calls fork a couple of times, and returns in the child
b4ec74
+ * processes. These child processes are in a new PID namespace with different
b4ec74
+ * PID configurations (group leader, session leader, ...). If any child
b4ec74
+ * terminates with nonzero exit status the test is failed. Otherwise the test is
b4ec74
+ * succesful, and the parent process exits with 0.
b4ec74
+ */
b4ec74
+void pidns_test_init(void);
b4ec74
+
b4ec74
+#endif
b4ec74
\ No newline at end of file
b4ec74
Index: strace-5.7/tests-m32/Makefile.am
b4ec74
===================================================================
b4ec74
--- strace-5.7.orig/tests-m32/Makefile.am	2020-09-09 19:32:50.846965498 +0200
b4ec74
+++ strace-5.7/tests-m32/Makefile.am	2020-09-09 19:49:54.009575350 +0200
b4ec74
@@ -7,14 +7,14 @@
b4ec74
 # SPDX-License-Identifier: GPL-2.0-or-later
b4ec74
 
b4ec74
 OS = linux
b4ec74
-CC = @CC_FOR_M32@
b4ec74
-ARCH = @arch_m32@
b4ec74
+CC = @CC@
b4ec74
+ARCH = @arch@
b4ec74
 NATIVE_ARCH = @arch_native@
b4ec74
-SIZEOF_KERNEL_LONG_T = 4
b4ec74
-SIZEOF_LONG = 4
b4ec74
-MPERS_NAME = m32
b4ec74
-MPERS_CC_FLAGS = @CFLAGS_FOR_M32@ @cc_flags_m32@
b4ec74
-ARCH_MFLAGS = -DMPERS_IS_$(MPERS_NAME) $(MPERS_CC_FLAGS)
b4ec74
+SIZEOF_KERNEL_LONG_T = @SIZEOF_KERNEL_LONG_T@
b4ec74
+SIZEOF_LONG = @SIZEOF_LONG@
b4ec74
+MPERS_NAME =
b4ec74
+MPERS_CC_FLAGS =
b4ec74
+ARCH_MFLAGS =
b4ec74
 AM_CFLAGS = $(WARN_CFLAGS)
b4ec74
 AM_CPPFLAGS = $(ARCH_MFLAGS) \
b4ec74
 	      -I$(builddir) \
b4ec74
@@ -44,6 +44,8 @@
b4ec74
 	libsocketcall.c \
b4ec74
 	lock_file.c \
b4ec74
 	overflowuid.c \
b4ec74
+	pidns.c \
b4ec74
+	pidns.h \
b4ec74
 	pipe_maxfd.c \
b4ec74
 	print_quoted_string.c \
b4ec74
 	print_time.c \
b4ec74
Index: strace-5.7/tests-m32/init.sh
b4ec74
===================================================================
b4ec74
--- strace-5.7.orig/tests-m32/init.sh	2020-09-09 19:32:50.846965498 +0200
b4ec74
+++ strace-5.7/tests-m32/init.sh	2020-09-09 19:49:54.009575350 +0200
b4ec74
@@ -387,6 +387,36 @@
b4ec74
 	test_pure_prog_set "$@" < "$srcdir/$NAME.in"
b4ec74
 }
b4ec74
 
b4ec74
+test_pidns_run_strace()
b4ec74
+{
b4ec74
+	local parent_pid init_pid
b4ec74
+
b4ec74
+	check_prog tail
b4ec74
+	check_prog cut
b4ec74
+	check_prog grep
b4ec74
+
b4ec74
+	run_prog > /dev/null
b4ec74
+	run_strace --pidns-translation -f $@ $args > "$EXP"
b4ec74
+
b4ec74
+	# filter out logs made by the parent or init process of the pidns test
b4ec74
+	parent_pid="$(tail -n 2 $LOG | head -n 1 | cut -d' ' -f1)"
b4ec74
+	init_pid="$(tail -n 1 $LOG | cut -d' ' -f1)"
b4ec74
+	grep -E -v "^($parent_pid|$init_pid) " "$LOG" > "$OUT"
b4ec74
+	match_diff "$OUT" "$EXP"
b4ec74
+}
b4ec74
+
b4ec74
+test_pidns()
b4ec74
+{
b4ec74
+	check_prog unshare
b4ec74
+	unshare -Urpf true || framework_skip_ "unshare -Urpf true failed"
b4ec74
+
b4ec74
+	test_pidns_run_strace "$@"
b4ec74
+
b4ec74
+	# test PID translation when /proc is mounted from an other namespace
b4ec74
+	STRACE="unshare -Urpf $STRACE"
b4ec74
+	test_pidns_run_strace "$@"
b4ec74
+}
b4ec74
+
b4ec74
 check_prog cat
b4ec74
 check_prog rm
b4ec74
 
b4ec74
Index: strace-5.7/tests-m32/pidns.c
b4ec74
===================================================================
b4ec74
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
b4ec74
+++ strace-5.7/tests-m32/pidns.c	2020-09-09 19:49:54.009575350 +0200
b4ec74
@@ -0,0 +1,237 @@
b4ec74
+/*
b4ec74
+ * Testing framework for PID namespace translation
b4ec74
+ *
b4ec74
+ * Copyright (c) 2020 Ákos Uzonyi <uzonyi.akos@gmail.com>
b4ec74
+ * All rights reserved.
b4ec74
+ *
b4ec74
+ * SPDX-License-Identifier: LGPL-2.1-or-later
b4ec74
+ */
b4ec74
+#include "tests.h"
b4ec74
+#include "pidns.h"
b4ec74
+#include "nsfs.h"
b4ec74
+
b4ec74
+#include <errno.h>
b4ec74
+#include <stdio.h>
b4ec74
+#include <string.h>
b4ec74
+#include <sys/types.h>
b4ec74
+#include <signal.h>
b4ec74
+#include <stdlib.h>
b4ec74
+#include <sched.h>
b4ec74
+#include <unistd.h>
b4ec74
+#include <sys/wait.h>
b4ec74
+#include <linux/sched.h>
b4ec74
+#include <fcntl.h>
b4ec74
+#include <sys/ioctl.h>
b4ec74
+
b4ec74
+#ifndef CLONE_NEWUSER
b4ec74
+# define CLONE_NEWUSER 0x10000000
b4ec74
+#endif
b4ec74
+
b4ec74
+#ifndef CLONE_NEWPID
b4ec74
+# define CLONE_NEWPID 0x20000000
b4ec74
+#endif
b4ec74
+
b4ec74
+static bool pidns_translation = false;
b4ec74
+static bool pidns_unshared = false;
b4ec74
+
b4ec74
+/* Our PIDs in strace's namespace */
b4ec74
+static pid_t pidns_strace_ids[PT_COUNT];
b4ec74
+
b4ec74
+void
b4ec74
+pidns_print_leader(void)
b4ec74
+{
b4ec74
+	if (pidns_translation)
b4ec74
+		printf("%-5d ", pidns_strace_ids[PT_TID]);
b4ec74
+}
b4ec74
+
b4ec74
+const char *
b4ec74
+pidns_pid2str(enum pid_type type)
b4ec74
+{
b4ec74
+	static const char format[] = " /* %d in strace's PID NS */";
b4ec74
+	static char buf[PT_COUNT][sizeof(format) + sizeof(int) * 3];
b4ec74
+
b4ec74
+	if (type < 0 || type >= PT_COUNT)
b4ec74
+		return "";
b4ec74
+
b4ec74
+	if (!pidns_unshared || !pidns_strace_ids[type])
b4ec74
+		return "";
b4ec74
+
b4ec74
+	snprintf(buf[type], sizeof(buf[type]), format, pidns_strace_ids[type]);
b4ec74
+	return buf[type];
b4ec74
+}
b4ec74
+
b4ec74
+/**
b4ec74
+ * This function is like fork, but does a few more things. It sets up the
b4ec74
+ * child's PGID and SID according to the parameters. Also it fills the
b4ec74
+ * pidns_strace_ids array in the child's memory with the PIDs of the child in
b4ec74
+ * parent's PID namespace. In the parent it waits for the child to terminate
b4ec74
+ * (but leaves the zombie to use it later as a process group). If the child
b4ec74
+ * terminates with nonzero exit status, the test is failed.
b4ec74
+ *
b4ec74
+ * @param pgid     The process group the child should be moved to. It's expected
b4ec74
+ *                 to be a PID of a zombie process (will be reaped). If
b4ec74
+ *                 negative, leave the child in the process group of the parent.
b4ec74
+ *                 If 0, move the process to its own process group.
b4ec74
+ * @param new_sid  Wheather child should be moved to a new session.
b4ec74
+ */
b4ec74
+static pid_t
b4ec74
+pidns_fork(pid_t pgid, bool new_sid)
b4ec74
+{
b4ec74
+	int strace_ids_pipe[2];
b4ec74
+	if (pipe(strace_ids_pipe) < 0)
b4ec74
+		perror_msg_and_fail("pipe");
b4ec74
+
b4ec74
+	fflush(stdout);
b4ec74
+	pid_t pid = fork();
b4ec74
+	if (pid < 0)
b4ec74
+		perror_msg_and_fail("fork");
b4ec74
+
b4ec74
+	if (!pid) {
b4ec74
+		close(strace_ids_pipe[1]);
b4ec74
+
b4ec74
+		ssize_t len = read(strace_ids_pipe[0], pidns_strace_ids,
b4ec74
+				sizeof(pidns_strace_ids));
b4ec74
+		if (len < 0)
b4ec74
+			perror_msg_and_fail("read");
b4ec74
+		if (len != sizeof(pidns_strace_ids))
b4ec74
+			error_msg_and_fail("read returned < sizeof(pidns_strace_ids)");
b4ec74
+
b4ec74
+		close(strace_ids_pipe[0]);
b4ec74
+
b4ec74
+		if (pidns_strace_ids[PT_SID])
b4ec74
+			setsid();
b4ec74
+
b4ec74
+		return 0;
b4ec74
+	}
b4ec74
+
b4ec74
+	pidns_strace_ids[PT_TID] = pid;
b4ec74
+	pidns_strace_ids[PT_TGID] = pid;
b4ec74
+	pidns_strace_ids[PT_PGID] = 0;
b4ec74
+	pidns_strace_ids[PT_SID] = 0;
b4ec74
+
b4ec74
+	if (!pgid)
b4ec74
+		pgid = pid;
b4ec74
+
b4ec74
+	if (pgid > 0) {
b4ec74
+		if (setpgid(pid, pgid) < 0)
b4ec74
+			perror_msg_and_fail("setpgid");
b4ec74
+
b4ec74
+		pidns_strace_ids[PT_PGID] = pgid;
b4ec74
+	}
b4ec74
+
b4ec74
+	/* Reap group leader to test PGID decoding */
b4ec74
+	if (pgid > 0 && pgid != pid) {
b4ec74
+		int ret = waitpid(pgid, NULL, WNOHANG);
b4ec74
+		if (ret < 0)
b4ec74
+			perror_msg_and_fail("wait");
b4ec74
+		if (!ret)
b4ec74
+			error_msg_and_fail("could not reap group leader");
b4ec74
+	}
b4ec74
+
b4ec74
+	if (new_sid) {
b4ec74
+		pidns_strace_ids[PT_SID] = pid;
b4ec74
+		pidns_strace_ids[PT_PGID] = pid;
b4ec74
+	}
b4ec74
+
b4ec74
+	ssize_t len = write(strace_ids_pipe[1], pidns_strace_ids,
b4ec74
+	                     sizeof(pidns_strace_ids));
b4ec74
+	if (len < 0)
b4ec74
+		perror_msg_and_fail("write");
b4ec74
+	if (len != sizeof(pidns_strace_ids))
b4ec74
+		error_msg_and_fail("write returned < sizeof(pidns_strace_ids)");
b4ec74
+
b4ec74
+	close(strace_ids_pipe[0]);
b4ec74
+	close(strace_ids_pipe[1]);
b4ec74
+
b4ec74
+	/* WNOWAIT: leave the zombie, to be able to use it as a process group */
b4ec74
+	siginfo_t siginfo;
b4ec74
+	if (waitid(P_PID, pid, &siginfo, WEXITED | WNOWAIT) < 0)
b4ec74
+		perror_msg_and_fail("wait");
b4ec74
+	if (siginfo.si_code != CLD_EXITED || siginfo.si_status)
b4ec74
+		error_msg_and_fail("child terminated with nonzero exit status");
b4ec74
+
b4ec74
+	return pid;
b4ec74
+}
b4ec74
+
b4ec74
+static void
b4ec74
+create_init_process(void)
b4ec74
+{
b4ec74
+	int child_pipe[2];
b4ec74
+	if (pipe(child_pipe) < 0)
b4ec74
+		perror_msg_and_fail("pipe");
b4ec74
+
b4ec74
+	pid_t pid = fork();
b4ec74
+	if (pid < 0)
b4ec74
+		perror_msg_and_fail("fork");
b4ec74
+
b4ec74
+	if (!pid) {
b4ec74
+		close(child_pipe[1]);
b4ec74
+		if (read(child_pipe[0], &child_pipe[1], sizeof(int)) != 0)
b4ec74
+			_exit(1);
b4ec74
+		_exit(0);
b4ec74
+	}
b4ec74
+
b4ec74
+	close(child_pipe[0]);
b4ec74
+}
b4ec74
+
b4ec74
+void
b4ec74
+check_ns_ioctl(void)
b4ec74
+{
b4ec74
+	int fd = open("/proc/self/ns/pid", O_RDONLY);
b4ec74
+	if (fd < 0) {
b4ec74
+		if (errno == ENOENT)
b4ec74
+			perror_msg_and_skip("opening /proc/self/ns/pid");
b4ec74
+		else
b4ec74
+			perror_msg_and_fail("opening /proc/self/ns/pid");
b4ec74
+	}
b4ec74
+
b4ec74
+	int userns_fd = ioctl(fd, NS_GET_USERNS);
b4ec74
+	if (userns_fd < 0) {
b4ec74
+		if (errno == ENOTTY)
b4ec74
+			error_msg_and_skip("NS_* ioctl commands are not "
b4ec74
+			                   "supported by the kernel");
b4ec74
+		else
b4ec74
+			perror_msg_and_fail("ioctl(NS_GET_USERNS)");
b4ec74
+	}
b4ec74
+
b4ec74
+	close(userns_fd);
b4ec74
+	close(fd);
b4ec74
+}
b4ec74
+
b4ec74
+void
b4ec74
+pidns_test_init(void)
b4ec74
+{
b4ec74
+	pidns_translation = true;
b4ec74
+
b4ec74
+	check_ns_ioctl();
b4ec74
+
b4ec74
+	if (!pidns_fork(-1, false))
b4ec74
+		return;
b4ec74
+
b4ec74
+	/* Unshare user namespace too, so we do not need to be root */
b4ec74
+	if (unshare(CLONE_NEWUSER | CLONE_NEWPID) < 0) {
b4ec74
+		if (errno == EPERM)
b4ec74
+			perror_msg_and_skip("unshare");
b4ec74
+
b4ec74
+		perror_msg_and_fail("unshare");
b4ec74
+	}
b4ec74
+
b4ec74
+	pidns_unshared = true;
b4ec74
+
b4ec74
+	create_init_process();
b4ec74
+
b4ec74
+	if (!pidns_fork(-1, false))
b4ec74
+		return;
b4ec74
+
b4ec74
+	if (!pidns_fork(-1, true))
b4ec74
+		return;
b4ec74
+
b4ec74
+	pid_t pgid;
b4ec74
+	if (!(pgid = pidns_fork(0, false)))
b4ec74
+		return;
b4ec74
+
b4ec74
+	if (!pidns_fork(pgid, false))
b4ec74
+		return;
b4ec74
+
b4ec74
+	exit(0);
b4ec74
+}
b4ec74
Index: strace-5.7/tests-m32/pidns.h
b4ec74
===================================================================
b4ec74
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
b4ec74
+++ strace-5.7/tests-m32/pidns.h	2020-09-09 19:49:54.010575350 +0200
b4ec74
@@ -0,0 +1,56 @@
b4ec74
+/*
b4ec74
+ * Test PID namespace translation
b4ec74
+ *
b4ec74
+ * Copyright (c) 2020 Ákos Uzonyi <uzonyi.akos@gmail.com>
b4ec74
+ * All rights reserved.
b4ec74
+ *
b4ec74
+ * SPDX-License-Identifier: LGPL-2.1-or-later
b4ec74
+ */
b4ec74
+#ifndef STRACE_PIDNS_H
b4ec74
+#define STRACE_PIDNS_H
b4ec74
+
b4ec74
+#ifdef PIDNS_TRANSLATION
b4ec74
+# define PIDNS_TEST_INIT pidns_test_init()
b4ec74
+#else
b4ec74
+# define PIDNS_TEST_INIT
b4ec74
+#endif
b4ec74
+
b4ec74
+#include <sys/types.h>
b4ec74
+
b4ec74
+enum pid_type {
b4ec74
+	PT_TID,
b4ec74
+	PT_TGID,
b4ec74
+	PT_PGID,
b4ec74
+	PT_SID,
b4ec74
+
b4ec74
+	PT_COUNT,
b4ec74
+	PT_NONE = -1
b4ec74
+};
b4ec74
+
b4ec74
+/* Prints leader (process tid) if pidns_test_init was called */
b4ec74
+void pidns_print_leader(void);
b4ec74
+
b4ec74
+/*
b4ec74
+ * Returns a static buffer containing the translation string of our PID.
b4ec74
+ */
b4ec74
+const char *pidns_pid2str(enum pid_type type);
b4ec74
+
b4ec74
+/**
b4ec74
+ * Skips the test if NS_* ioctl commands are not supported by the kernel.
b4ec74
+ */
b4ec74
+void check_ns_ioctl(void);
b4ec74
+
b4ec74
+/**
b4ec74
+ * Init pidns testing.
b4ec74
+ *
b4ec74
+ * Should be called at the beginning of the test's main function
b4ec74
+ *
b4ec74
+ * This function calls fork a couple of times, and returns in the child
b4ec74
+ * processes. These child processes are in a new PID namespace with different
b4ec74
+ * PID configurations (group leader, session leader, ...). If any child
b4ec74
+ * terminates with nonzero exit status the test is failed. Otherwise the test is
b4ec74
+ * succesful, and the parent process exits with 0.
b4ec74
+ */
b4ec74
+void pidns_test_init(void);
b4ec74
+
b4ec74
+#endif
b4ec74
\ No newline at end of file
b4ec74
Index: strace-5.7/tests-mx32/Makefile.am
b4ec74
===================================================================
b4ec74
--- strace-5.7.orig/tests-mx32/Makefile.am	2020-09-09 19:32:50.846965498 +0200
b4ec74
+++ strace-5.7/tests-mx32/Makefile.am	2020-09-09 19:49:54.010575350 +0200
b4ec74
@@ -7,14 +7,14 @@
b4ec74
 # SPDX-License-Identifier: GPL-2.0-or-later
b4ec74
 
b4ec74
 OS = linux
b4ec74
-CC = @CC_FOR_MX32@
b4ec74
-ARCH = @arch_mx32@
b4ec74
+CC = @CC@
b4ec74
+ARCH = @arch@
b4ec74
 NATIVE_ARCH = @arch_native@
b4ec74
 SIZEOF_KERNEL_LONG_T = @SIZEOF_KERNEL_LONG_T@
b4ec74
-SIZEOF_LONG = 4
b4ec74
-MPERS_NAME = mx32
b4ec74
-MPERS_CC_FLAGS = @CFLAGS_FOR_MX32@ @cc_flags_mx32@
b4ec74
-ARCH_MFLAGS = -DMPERS_IS_$(MPERS_NAME) $(MPERS_CC_FLAGS)
b4ec74
+SIZEOF_LONG = @SIZEOF_LONG@
b4ec74
+MPERS_NAME =
b4ec74
+MPERS_CC_FLAGS =
b4ec74
+ARCH_MFLAGS =
b4ec74
 AM_CFLAGS = $(WARN_CFLAGS)
b4ec74
 AM_CPPFLAGS = $(ARCH_MFLAGS) \
b4ec74
 	      -I$(builddir) \
b4ec74
@@ -44,6 +44,8 @@
b4ec74
 	libsocketcall.c \
b4ec74
 	lock_file.c \
b4ec74
 	overflowuid.c \
b4ec74
+	pidns.c \
b4ec74
+	pidns.h \
b4ec74
 	pipe_maxfd.c \
b4ec74
 	print_quoted_string.c \
b4ec74
 	print_time.c \
b4ec74
Index: strace-5.7/tests-mx32/init.sh
b4ec74
===================================================================
b4ec74
--- strace-5.7.orig/tests-mx32/init.sh	2020-09-09 19:32:50.846965498 +0200
b4ec74
+++ strace-5.7/tests-mx32/init.sh	2020-09-09 19:49:54.010575350 +0200
b4ec74
@@ -387,6 +387,36 @@
b4ec74
 	test_pure_prog_set "$@" < "$srcdir/$NAME.in"
b4ec74
 }
b4ec74
 
b4ec74
+test_pidns_run_strace()
b4ec74
+{
b4ec74
+	local parent_pid init_pid
b4ec74
+
b4ec74
+	check_prog tail
b4ec74
+	check_prog cut
b4ec74
+	check_prog grep
b4ec74
+
b4ec74
+	run_prog > /dev/null
b4ec74
+	run_strace --pidns-translation -f $@ $args > "$EXP"
b4ec74
+
b4ec74
+	# filter out logs made by the parent or init process of the pidns test
b4ec74
+	parent_pid="$(tail -n 2 $LOG | head -n 1 | cut -d' ' -f1)"
b4ec74
+	init_pid="$(tail -n 1 $LOG | cut -d' ' -f1)"
b4ec74
+	grep -E -v "^($parent_pid|$init_pid) " "$LOG" > "$OUT"
b4ec74
+	match_diff "$OUT" "$EXP"
b4ec74
+}
b4ec74
+
b4ec74
+test_pidns()
b4ec74
+{
b4ec74
+	check_prog unshare
b4ec74
+	unshare -Urpf true || framework_skip_ "unshare -Urpf true failed"
b4ec74
+
b4ec74
+	test_pidns_run_strace "$@"
b4ec74
+
b4ec74
+	# test PID translation when /proc is mounted from an other namespace
b4ec74
+	STRACE="unshare -Urpf $STRACE"
b4ec74
+	test_pidns_run_strace "$@"
b4ec74
+}
b4ec74
+
b4ec74
 check_prog cat
b4ec74
 check_prog rm
b4ec74
 
b4ec74
Index: strace-5.7/tests-mx32/pidns.c
b4ec74
===================================================================
b4ec74
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
b4ec74
+++ strace-5.7/tests-mx32/pidns.c	2020-09-09 19:49:54.010575350 +0200
b4ec74
@@ -0,0 +1,237 @@
b4ec74
+/*
b4ec74
+ * Testing framework for PID namespace translation
b4ec74
+ *
b4ec74
+ * Copyright (c) 2020 Ákos Uzonyi <uzonyi.akos@gmail.com>
b4ec74
+ * All rights reserved.
b4ec74
+ *
b4ec74
+ * SPDX-License-Identifier: LGPL-2.1-or-later
b4ec74
+ */
b4ec74
+#include "tests.h"
b4ec74
+#include "pidns.h"
b4ec74
+#include "nsfs.h"
b4ec74
+
b4ec74
+#include <errno.h>
b4ec74
+#include <stdio.h>
b4ec74
+#include <string.h>
b4ec74
+#include <sys/types.h>
b4ec74
+#include <signal.h>
b4ec74
+#include <stdlib.h>
b4ec74
+#include <sched.h>
b4ec74
+#include <unistd.h>
b4ec74
+#include <sys/wait.h>
b4ec74
+#include <linux/sched.h>
b4ec74
+#include <fcntl.h>
b4ec74
+#include <sys/ioctl.h>
b4ec74
+
b4ec74
+#ifndef CLONE_NEWUSER
b4ec74
+# define CLONE_NEWUSER 0x10000000
b4ec74
+#endif
b4ec74
+
b4ec74
+#ifndef CLONE_NEWPID
b4ec74
+# define CLONE_NEWPID 0x20000000
b4ec74
+#endif
b4ec74
+
b4ec74
+static bool pidns_translation = false;
b4ec74
+static bool pidns_unshared = false;
b4ec74
+
b4ec74
+/* Our PIDs in strace's namespace */
b4ec74
+static pid_t pidns_strace_ids[PT_COUNT];
b4ec74
+
b4ec74
+void
b4ec74
+pidns_print_leader(void)
b4ec74
+{
b4ec74
+	if (pidns_translation)
b4ec74
+		printf("%-5d ", pidns_strace_ids[PT_TID]);
b4ec74
+}
b4ec74
+
b4ec74
+const char *
b4ec74
+pidns_pid2str(enum pid_type type)
b4ec74
+{
b4ec74
+	static const char format[] = " /* %d in strace's PID NS */";
b4ec74
+	static char buf[PT_COUNT][sizeof(format) + sizeof(int) * 3];
b4ec74
+
b4ec74
+	if (type < 0 || type >= PT_COUNT)
b4ec74
+		return "";
b4ec74
+
b4ec74
+	if (!pidns_unshared || !pidns_strace_ids[type])
b4ec74
+		return "";
b4ec74
+
b4ec74
+	snprintf(buf[type], sizeof(buf[type]), format, pidns_strace_ids[type]);
b4ec74
+	return buf[type];
b4ec74
+}
b4ec74
+
b4ec74
+/**
b4ec74
+ * This function is like fork, but does a few more things. It sets up the
b4ec74
+ * child's PGID and SID according to the parameters. Also it fills the
b4ec74
+ * pidns_strace_ids array in the child's memory with the PIDs of the child in
b4ec74
+ * parent's PID namespace. In the parent it waits for the child to terminate
b4ec74
+ * (but leaves the zombie to use it later as a process group). If the child
b4ec74
+ * terminates with nonzero exit status, the test is failed.
b4ec74
+ *
b4ec74
+ * @param pgid     The process group the child should be moved to. It's expected
b4ec74
+ *                 to be a PID of a zombie process (will be reaped). If
b4ec74
+ *                 negative, leave the child in the process group of the parent.
b4ec74
+ *                 If 0, move the process to its own process group.
b4ec74
+ * @param new_sid  Wheather child should be moved to a new session.
b4ec74
+ */
b4ec74
+static pid_t
b4ec74
+pidns_fork(pid_t pgid, bool new_sid)
b4ec74
+{
b4ec74
+	int strace_ids_pipe[2];
b4ec74
+	if (pipe(strace_ids_pipe) < 0)
b4ec74
+		perror_msg_and_fail("pipe");
b4ec74
+
b4ec74
+	fflush(stdout);
b4ec74
+	pid_t pid = fork();
b4ec74
+	if (pid < 0)
b4ec74
+		perror_msg_and_fail("fork");
b4ec74
+
b4ec74
+	if (!pid) {
b4ec74
+		close(strace_ids_pipe[1]);
b4ec74
+
b4ec74
+		ssize_t len = read(strace_ids_pipe[0], pidns_strace_ids,
b4ec74
+				sizeof(pidns_strace_ids));
b4ec74
+		if (len < 0)
b4ec74
+			perror_msg_and_fail("read");
b4ec74
+		if (len != sizeof(pidns_strace_ids))
b4ec74
+			error_msg_and_fail("read returned < sizeof(pidns_strace_ids)");
b4ec74
+
b4ec74
+		close(strace_ids_pipe[0]);
b4ec74
+
b4ec74
+		if (pidns_strace_ids[PT_SID])
b4ec74
+			setsid();
b4ec74
+
b4ec74
+		return 0;
b4ec74
+	}
b4ec74
+
b4ec74
+	pidns_strace_ids[PT_TID] = pid;
b4ec74
+	pidns_strace_ids[PT_TGID] = pid;
b4ec74
+	pidns_strace_ids[PT_PGID] = 0;
b4ec74
+	pidns_strace_ids[PT_SID] = 0;
b4ec74
+
b4ec74
+	if (!pgid)
b4ec74
+		pgid = pid;
b4ec74
+
b4ec74
+	if (pgid > 0) {
b4ec74
+		if (setpgid(pid, pgid) < 0)
b4ec74
+			perror_msg_and_fail("setpgid");
b4ec74
+
b4ec74
+		pidns_strace_ids[PT_PGID] = pgid;
b4ec74
+	}
b4ec74
+
b4ec74
+	/* Reap group leader to test PGID decoding */
b4ec74
+	if (pgid > 0 && pgid != pid) {
b4ec74
+		int ret = waitpid(pgid, NULL, WNOHANG);
b4ec74
+		if (ret < 0)
b4ec74
+			perror_msg_and_fail("wait");
b4ec74
+		if (!ret)
b4ec74
+			error_msg_and_fail("could not reap group leader");
b4ec74
+	}
b4ec74
+
b4ec74
+	if (new_sid) {
b4ec74
+		pidns_strace_ids[PT_SID] = pid;
b4ec74
+		pidns_strace_ids[PT_PGID] = pid;
b4ec74
+	}
b4ec74
+
b4ec74
+	ssize_t len = write(strace_ids_pipe[1], pidns_strace_ids,
b4ec74
+	                     sizeof(pidns_strace_ids));
b4ec74
+	if (len < 0)
b4ec74
+		perror_msg_and_fail("write");
b4ec74
+	if (len != sizeof(pidns_strace_ids))
b4ec74
+		error_msg_and_fail("write returned < sizeof(pidns_strace_ids)");
b4ec74
+
b4ec74
+	close(strace_ids_pipe[0]);
b4ec74
+	close(strace_ids_pipe[1]);
b4ec74
+
b4ec74
+	/* WNOWAIT: leave the zombie, to be able to use it as a process group */
b4ec74
+	siginfo_t siginfo;
b4ec74
+	if (waitid(P_PID, pid, &siginfo, WEXITED | WNOWAIT) < 0)
b4ec74
+		perror_msg_and_fail("wait");
b4ec74
+	if (siginfo.si_code != CLD_EXITED || siginfo.si_status)
b4ec74
+		error_msg_and_fail("child terminated with nonzero exit status");
b4ec74
+
b4ec74
+	return pid;
b4ec74
+}
b4ec74
+
b4ec74
+static void
b4ec74
+create_init_process(void)
b4ec74
+{
b4ec74
+	int child_pipe[2];
b4ec74
+	if (pipe(child_pipe) < 0)
b4ec74
+		perror_msg_and_fail("pipe");
b4ec74
+
b4ec74
+	pid_t pid = fork();
b4ec74
+	if (pid < 0)
b4ec74
+		perror_msg_and_fail("fork");
b4ec74
+
b4ec74
+	if (!pid) {
b4ec74
+		close(child_pipe[1]);
b4ec74
+		if (read(child_pipe[0], &child_pipe[1], sizeof(int)) != 0)
b4ec74
+			_exit(1);
b4ec74
+		_exit(0);
b4ec74
+	}
b4ec74
+
b4ec74
+	close(child_pipe[0]);
b4ec74
+}
b4ec74
+
b4ec74
+void
b4ec74
+check_ns_ioctl(void)
b4ec74
+{
b4ec74
+	int fd = open("/proc/self/ns/pid", O_RDONLY);
b4ec74
+	if (fd < 0) {
b4ec74
+		if (errno == ENOENT)
b4ec74
+			perror_msg_and_skip("opening /proc/self/ns/pid");
b4ec74
+		else
b4ec74
+			perror_msg_and_fail("opening /proc/self/ns/pid");
b4ec74
+	}
b4ec74
+
b4ec74
+	int userns_fd = ioctl(fd, NS_GET_USERNS);
b4ec74
+	if (userns_fd < 0) {
b4ec74
+		if (errno == ENOTTY)
b4ec74
+			error_msg_and_skip("NS_* ioctl commands are not "
b4ec74
+			                   "supported by the kernel");
b4ec74
+		else
b4ec74
+			perror_msg_and_fail("ioctl(NS_GET_USERNS)");
b4ec74
+	}
b4ec74
+
b4ec74
+	close(userns_fd);
b4ec74
+	close(fd);
b4ec74
+}
b4ec74
+
b4ec74
+void
b4ec74
+pidns_test_init(void)
b4ec74
+{
b4ec74
+	pidns_translation = true;
b4ec74
+
b4ec74
+	check_ns_ioctl();
b4ec74
+
b4ec74
+	if (!pidns_fork(-1, false))
b4ec74
+		return;
b4ec74
+
b4ec74
+	/* Unshare user namespace too, so we do not need to be root */
b4ec74
+	if (unshare(CLONE_NEWUSER | CLONE_NEWPID) < 0) {
b4ec74
+		if (errno == EPERM)
b4ec74
+			perror_msg_and_skip("unshare");
b4ec74
+
b4ec74
+		perror_msg_and_fail("unshare");
b4ec74
+	}
b4ec74
+
b4ec74
+	pidns_unshared = true;
b4ec74
+
b4ec74
+	create_init_process();
b4ec74
+
b4ec74
+	if (!pidns_fork(-1, false))
b4ec74
+		return;
b4ec74
+
b4ec74
+	if (!pidns_fork(-1, true))
b4ec74
+		return;
b4ec74
+
b4ec74
+	pid_t pgid;
b4ec74
+	if (!(pgid = pidns_fork(0, false)))
b4ec74
+		return;
b4ec74
+
b4ec74
+	if (!pidns_fork(pgid, false))
b4ec74
+		return;
b4ec74
+
b4ec74
+	exit(0);
b4ec74
+}
b4ec74
Index: strace-5.7/tests-mx32/pidns.h
b4ec74
===================================================================
b4ec74
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
b4ec74
+++ strace-5.7/tests-mx32/pidns.h	2020-09-09 19:49:54.010575350 +0200
b4ec74
@@ -0,0 +1,56 @@
b4ec74
+/*
b4ec74
+ * Test PID namespace translation
b4ec74
+ *
b4ec74
+ * Copyright (c) 2020 Ákos Uzonyi <uzonyi.akos@gmail.com>
b4ec74
+ * All rights reserved.
b4ec74
+ *
b4ec74
+ * SPDX-License-Identifier: LGPL-2.1-or-later
b4ec74
+ */
b4ec74
+#ifndef STRACE_PIDNS_H
b4ec74
+#define STRACE_PIDNS_H
b4ec74
+
b4ec74
+#ifdef PIDNS_TRANSLATION
b4ec74
+# define PIDNS_TEST_INIT pidns_test_init()
b4ec74
+#else
b4ec74
+# define PIDNS_TEST_INIT
b4ec74
+#endif
b4ec74
+
b4ec74
+#include <sys/types.h>
b4ec74
+
b4ec74
+enum pid_type {
b4ec74
+	PT_TID,
b4ec74
+	PT_TGID,
b4ec74
+	PT_PGID,
b4ec74
+	PT_SID,
b4ec74
+
b4ec74
+	PT_COUNT,
b4ec74
+	PT_NONE = -1
b4ec74
+};
b4ec74
+
b4ec74
+/* Prints leader (process tid) if pidns_test_init was called */
b4ec74
+void pidns_print_leader(void);
b4ec74
+
b4ec74
+/*
b4ec74
+ * Returns a static buffer containing the translation string of our PID.
b4ec74
+ */
b4ec74
+const char *pidns_pid2str(enum pid_type type);
b4ec74
+
b4ec74
+/**
b4ec74
+ * Skips the test if NS_* ioctl commands are not supported by the kernel.
b4ec74
+ */
b4ec74
+void check_ns_ioctl(void);
b4ec74
+
b4ec74
+/**
b4ec74
+ * Init pidns testing.
b4ec74
+ *
b4ec74
+ * Should be called at the beginning of the test's main function
b4ec74
+ *
b4ec74
+ * This function calls fork a couple of times, and returns in the child
b4ec74
+ * processes. These child processes are in a new PID namespace with different
b4ec74
+ * PID configurations (group leader, session leader, ...). If any child
b4ec74
+ * terminates with nonzero exit status the test is failed. Otherwise the test is
b4ec74
+ * succesful, and the parent process exits with 0.
b4ec74
+ */
b4ec74
+void pidns_test_init(void);
b4ec74
+
b4ec74
+#endif
b4ec74
\ No newline at end of file
b4ec74
Index: strace-5.7/tests/Makefile.in
b4ec74
===================================================================
b4ec74
--- strace-5.7.orig/tests/Makefile.in	2020-09-09 19:46:24.904450714 +0200
b4ec74
+++ strace-5.7/tests/Makefile.in	2020-09-09 19:51:23.607628754 +0200
b4ec74
@@ -531,7 +531,7 @@
b4ec74
 	libtests_a-libmmsg.$(OBJEXT) \
b4ec74
 	libtests_a-libsocketcall.$(OBJEXT) \
b4ec74
 	libtests_a-lock_file.$(OBJEXT) \
b4ec74
-	libtests_a-overflowuid.$(OBJEXT) \
b4ec74
+	libtests_a-overflowuid.$(OBJEXT) libtests_a-pidns.$(OBJEXT) \
b4ec74
 	libtests_a-pipe_maxfd.$(OBJEXT) \
b4ec74
 	libtests_a-print_quoted_string.$(OBJEXT) \
b4ec74
 	libtests_a-print_time.$(OBJEXT) \
b4ec74
@@ -3899,6 +3899,7 @@
b4ec74
 	./$(DEPDIR)/libtests_a-libsocketcall.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-lock_file.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-overflowuid.Po \
b4ec74
+	./$(DEPDIR)/libtests_a-pidns.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-pipe_maxfd.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-print_quoted_string.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-print_time.Po \
b4ec74
@@ -5122,6 +5123,8 @@
b4ec74
 	libsocketcall.c \
b4ec74
 	lock_file.c \
b4ec74
 	overflowuid.c \
b4ec74
+	pidns.c \
b4ec74
+	pidns.h \
b4ec74
 	pipe_maxfd.c \
b4ec74
 	print_quoted_string.c \
b4ec74
 	print_time.c \
b4ec74
@@ -9926,6 +9929,7 @@
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-libsocketcall.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-lock_file.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-overflowuid.Po@am__quote@ # am--include-marker
b4ec74
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-pidns.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-pipe_maxfd.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-print_quoted_string.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-print_time.Po@am__quote@ # am--include-marker
b4ec74
@@ -10651,6 +10655,20 @@
b4ec74
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
b4ec74
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libtests_a-overflowuid.obj `if test -f 'overflowuid.c'; then $(CYGPATH_W) 'overflowuid.c'; else $(CYGPATH_W) '$(srcdir)/overflowuid.c'; fi`
b4ec74
 
b4ec74
+libtests_a-pidns.o: pidns.c
b4ec74
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libtests_a-pidns.o -MD -MP -MF $(DEPDIR)/libtests_a-pidns.Tpo -c -o libtests_a-pidns.o `test -f 'pidns.c' || echo '$(srcdir)/'`pidns.c
b4ec74
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libtests_a-pidns.Tpo $(DEPDIR)/libtests_a-pidns.Po
b4ec74
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='pidns.c' object='libtests_a-pidns.o' libtool=no @AMDEPBACKSLASH@
b4ec74
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
b4ec74
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libtests_a-pidns.o `test -f 'pidns.c' || echo '$(srcdir)/'`pidns.c
b4ec74
+
b4ec74
+libtests_a-pidns.obj: pidns.c
b4ec74
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libtests_a-pidns.obj -MD -MP -MF $(DEPDIR)/libtests_a-pidns.Tpo -c -o libtests_a-pidns.obj `if test -f 'pidns.c'; then $(CYGPATH_W) 'pidns.c'; else $(CYGPATH_W) '$(srcdir)/pidns.c'; fi`
b4ec74
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libtests_a-pidns.Tpo $(DEPDIR)/libtests_a-pidns.Po
b4ec74
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='pidns.c' object='libtests_a-pidns.obj' libtool=no @AMDEPBACKSLASH@
b4ec74
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
b4ec74
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libtests_a-pidns.obj `if test -f 'pidns.c'; then $(CYGPATH_W) 'pidns.c'; else $(CYGPATH_W) '$(srcdir)/pidns.c'; fi`
b4ec74
+
b4ec74
 libtests_a-pipe_maxfd.o: pipe_maxfd.c
b4ec74
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libtests_a-pipe_maxfd.o -MD -MP -MF $(DEPDIR)/libtests_a-pipe_maxfd.Tpo -c -o libtests_a-pipe_maxfd.o `test -f 'pipe_maxfd.c' || echo '$(srcdir)/'`pipe_maxfd.c
b4ec74
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libtests_a-pipe_maxfd.Tpo $(DEPDIR)/libtests_a-pipe_maxfd.Po
b4ec74
@@ -11748,6 +11766,7 @@
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-libsocketcall.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-lock_file.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-overflowuid.Po
b4ec74
+	-rm -f ./$(DEPDIR)/libtests_a-pidns.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-pipe_maxfd.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-print_quoted_string.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-print_time.Po
b4ec74
@@ -12605,6 +12624,7 @@
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-libsocketcall.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-lock_file.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-overflowuid.Po
b4ec74
+	-rm -f ./$(DEPDIR)/libtests_a-pidns.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-pipe_maxfd.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-print_quoted_string.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-print_time.Po
b4ec74
Index: strace-5.7/tests-m32/Makefile.in
b4ec74
===================================================================
b4ec74
--- strace-5.7.orig/tests-m32/Makefile.in	2020-09-09 19:49:34.530563739 +0200
b4ec74
+++ strace-5.7/tests-m32/Makefile.in	2020-09-09 19:52:01.333651241 +0200
b4ec74
@@ -531,7 +531,7 @@
b4ec74
 	libtests_a-libmmsg.$(OBJEXT) \
b4ec74
 	libtests_a-libsocketcall.$(OBJEXT) \
b4ec74
 	libtests_a-lock_file.$(OBJEXT) \
b4ec74
-	libtests_a-overflowuid.$(OBJEXT) \
b4ec74
+	libtests_a-overflowuid.$(OBJEXT) libtests_a-pidns.$(OBJEXT) \
b4ec74
 	libtests_a-pipe_maxfd.$(OBJEXT) \
b4ec74
 	libtests_a-print_quoted_string.$(OBJEXT) \
b4ec74
 	libtests_a-print_time.$(OBJEXT) \
b4ec74
@@ -3899,6 +3899,7 @@
b4ec74
 	./$(DEPDIR)/libtests_a-libsocketcall.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-lock_file.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-overflowuid.Po \
b4ec74
+	./$(DEPDIR)/libtests_a-pidns.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-pipe_maxfd.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-print_quoted_string.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-print_time.Po \
b4ec74
@@ -5122,6 +5123,8 @@
b4ec74
 	libsocketcall.c \
b4ec74
 	lock_file.c \
b4ec74
 	overflowuid.c \
b4ec74
+	pidns.c \
b4ec74
+	pidns.h \
b4ec74
 	pipe_maxfd.c \
b4ec74
 	print_quoted_string.c \
b4ec74
 	print_time.c \
b4ec74
@@ -9926,6 +9929,7 @@
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-libsocketcall.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-lock_file.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-overflowuid.Po@am__quote@ # am--include-marker
b4ec74
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-pidns.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-pipe_maxfd.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-print_quoted_string.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-print_time.Po@am__quote@ # am--include-marker
b4ec74
@@ -10651,6 +10655,20 @@
b4ec74
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
b4ec74
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libtests_a-overflowuid.obj `if test -f 'overflowuid.c'; then $(CYGPATH_W) 'overflowuid.c'; else $(CYGPATH_W) '$(srcdir)/overflowuid.c'; fi`
b4ec74
 
b4ec74
+libtests_a-pidns.o: pidns.c
b4ec74
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libtests_a-pidns.o -MD -MP -MF $(DEPDIR)/libtests_a-pidns.Tpo -c -o libtests_a-pidns.o `test -f 'pidns.c' || echo '$(srcdir)/'`pidns.c
b4ec74
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libtests_a-pidns.Tpo $(DEPDIR)/libtests_a-pidns.Po
b4ec74
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='pidns.c' object='libtests_a-pidns.o' libtool=no @AMDEPBACKSLASH@
b4ec74
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
b4ec74
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libtests_a-pidns.o `test -f 'pidns.c' || echo '$(srcdir)/'`pidns.c
b4ec74
+
b4ec74
+libtests_a-pidns.obj: pidns.c
b4ec74
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libtests_a-pidns.obj -MD -MP -MF $(DEPDIR)/libtests_a-pidns.Tpo -c -o libtests_a-pidns.obj `if test -f 'pidns.c'; then $(CYGPATH_W) 'pidns.c'; else $(CYGPATH_W) '$(srcdir)/pidns.c'; fi`
b4ec74
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libtests_a-pidns.Tpo $(DEPDIR)/libtests_a-pidns.Po
b4ec74
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='pidns.c' object='libtests_a-pidns.obj' libtool=no @AMDEPBACKSLASH@
b4ec74
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
b4ec74
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libtests_a-pidns.obj `if test -f 'pidns.c'; then $(CYGPATH_W) 'pidns.c'; else $(CYGPATH_W) '$(srcdir)/pidns.c'; fi`
b4ec74
+
b4ec74
 libtests_a-pipe_maxfd.o: pipe_maxfd.c
b4ec74
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libtests_a-pipe_maxfd.o -MD -MP -MF $(DEPDIR)/libtests_a-pipe_maxfd.Tpo -c -o libtests_a-pipe_maxfd.o `test -f 'pipe_maxfd.c' || echo '$(srcdir)/'`pipe_maxfd.c
b4ec74
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libtests_a-pipe_maxfd.Tpo $(DEPDIR)/libtests_a-pipe_maxfd.Po
b4ec74
@@ -11748,6 +11766,7 @@
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-libsocketcall.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-lock_file.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-overflowuid.Po
b4ec74
+	-rm -f ./$(DEPDIR)/libtests_a-pidns.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-pipe_maxfd.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-print_quoted_string.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-print_time.Po
b4ec74
@@ -12605,6 +12624,7 @@
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-libsocketcall.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-lock_file.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-overflowuid.Po
b4ec74
+	-rm -f ./$(DEPDIR)/libtests_a-pidns.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-pipe_maxfd.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-print_quoted_string.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-print_time.Po
b4ec74
Index: strace-5.7/tests-mx32/Makefile.in
b4ec74
===================================================================
b4ec74
--- strace-5.7.orig/tests-mx32/Makefile.in	2020-09-09 19:49:39.557566736 +0200
b4ec74
+++ strace-5.7/tests-mx32/Makefile.in	2020-09-09 19:52:26.062665980 +0200
b4ec74
@@ -531,7 +531,7 @@
b4ec74
 	libtests_a-libmmsg.$(OBJEXT) \
b4ec74
 	libtests_a-libsocketcall.$(OBJEXT) \
b4ec74
 	libtests_a-lock_file.$(OBJEXT) \
b4ec74
-	libtests_a-overflowuid.$(OBJEXT) \
b4ec74
+	libtests_a-overflowuid.$(OBJEXT) libtests_a-pidns.$(OBJEXT) \
b4ec74
 	libtests_a-pipe_maxfd.$(OBJEXT) \
b4ec74
 	libtests_a-print_quoted_string.$(OBJEXT) \
b4ec74
 	libtests_a-print_time.$(OBJEXT) \
b4ec74
@@ -3899,6 +3899,7 @@
b4ec74
 	./$(DEPDIR)/libtests_a-libsocketcall.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-lock_file.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-overflowuid.Po \
b4ec74
+	./$(DEPDIR)/libtests_a-pidns.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-pipe_maxfd.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-print_quoted_string.Po \
b4ec74
 	./$(DEPDIR)/libtests_a-print_time.Po \
b4ec74
@@ -5122,6 +5123,8 @@
b4ec74
 	libsocketcall.c \
b4ec74
 	lock_file.c \
b4ec74
 	overflowuid.c \
b4ec74
+	pidns.c \
b4ec74
+	pidns.h \
b4ec74
 	pipe_maxfd.c \
b4ec74
 	print_quoted_string.c \
b4ec74
 	print_time.c \
b4ec74
@@ -9926,6 +9929,7 @@
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-libsocketcall.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-lock_file.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-overflowuid.Po@am__quote@ # am--include-marker
b4ec74
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-pidns.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-pipe_maxfd.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-print_quoted_string.Po@am__quote@ # am--include-marker
b4ec74
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests_a-print_time.Po@am__quote@ # am--include-marker
b4ec74
@@ -10651,6 +10655,20 @@
b4ec74
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
b4ec74
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libtests_a-overflowuid.obj `if test -f 'overflowuid.c'; then $(CYGPATH_W) 'overflowuid.c'; else $(CYGPATH_W) '$(srcdir)/overflowuid.c'; fi`
b4ec74
 
b4ec74
+libtests_a-pidns.o: pidns.c
b4ec74
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libtests_a-pidns.o -MD -MP -MF $(DEPDIR)/libtests_a-pidns.Tpo -c -o libtests_a-pidns.o `test -f 'pidns.c' || echo '$(srcdir)/'`pidns.c
b4ec74
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libtests_a-pidns.Tpo $(DEPDIR)/libtests_a-pidns.Po
b4ec74
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='pidns.c' object='libtests_a-pidns.o' libtool=no @AMDEPBACKSLASH@
b4ec74
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
b4ec74
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libtests_a-pidns.o `test -f 'pidns.c' || echo '$(srcdir)/'`pidns.c
b4ec74
+
b4ec74
+libtests_a-pidns.obj: pidns.c
b4ec74
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libtests_a-pidns.obj -MD -MP -MF $(DEPDIR)/libtests_a-pidns.Tpo -c -o libtests_a-pidns.obj `if test -f 'pidns.c'; then $(CYGPATH_W) 'pidns.c'; else $(CYGPATH_W) '$(srcdir)/pidns.c'; fi`
b4ec74
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libtests_a-pidns.Tpo $(DEPDIR)/libtests_a-pidns.Po
b4ec74
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='pidns.c' object='libtests_a-pidns.obj' libtool=no @AMDEPBACKSLASH@
b4ec74
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
b4ec74
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libtests_a-pidns.obj `if test -f 'pidns.c'; then $(CYGPATH_W) 'pidns.c'; else $(CYGPATH_W) '$(srcdir)/pidns.c'; fi`
b4ec74
+
b4ec74
 libtests_a-pipe_maxfd.o: pipe_maxfd.c
b4ec74
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtests_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libtests_a-pipe_maxfd.o -MD -MP -MF $(DEPDIR)/libtests_a-pipe_maxfd.Tpo -c -o libtests_a-pipe_maxfd.o `test -f 'pipe_maxfd.c' || echo '$(srcdir)/'`pipe_maxfd.c
b4ec74
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libtests_a-pipe_maxfd.Tpo $(DEPDIR)/libtests_a-pipe_maxfd.Po
b4ec74
@@ -11748,6 +11766,7 @@
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-libsocketcall.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-lock_file.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-overflowuid.Po
b4ec74
+	-rm -f ./$(DEPDIR)/libtests_a-pidns.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-pipe_maxfd.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-print_quoted_string.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-print_time.Po
b4ec74
@@ -12605,6 +12624,7 @@
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-libsocketcall.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-lock_file.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-overflowuid.Po
b4ec74
+	-rm -f ./$(DEPDIR)/libtests_a-pidns.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-pipe_maxfd.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-print_quoted_string.Po
b4ec74
 	-rm -f ./$(DEPDIR)/libtests_a-print_time.Po