From a8c32c85d5f3847a1f9ea0030beb0c338af53cd5 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Mon, 12 Sep 2022 20:56:20 +1000 Subject: test: Add nsholder utility In our test scripts we need to do some ugly parsing of /proc and/or pstree output in order to get the PIDs of processes running in namespaces so that we can connect to those namespaces with nsenter or pasta. This is actually a pretty tricky problem with standard tools. To determine the PID from the outside of the namespace we need to know how the process of interest is related to the unshare or pasta process (child? one of several children? grandchild?) as well as then parsing /proc or ps output. This is slightly awkward now, and will get worse with future changes I'd like to make to have processes are dispatched. The obvious solution would be to have the process of interest (which we control) report its own PID, but that doesn't work easily, because it is in a PID namepace and sees only its local PID not the global PID we need to address it from outside. To handle this, add a small custom tool, "nsholder". This takes a path and a mode parameter. In "hold" mode it will create a unix domain socket bound to the path and listening. In "pid" mode it will get the "hold"ing process's pid via the unix socket using SO_PEERCRED, which translates between PID namespaces. In "stop" mode it will send a message to the socket causing the "hold"ing process to clean up and exit. Signed-off-by: David Gibson --- test/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'test/Makefile') diff --git a/test/Makefile b/test/Makefile index f11c4b5..e0dc7ac 100644 --- a/test/Makefile +++ b/test/Makefile @@ -56,10 +56,13 @@ DOWNLOAD_ASSETS = mbuto \ $(DEBIAN_IMGS) $(FEDORA_IMGS) $(OPENSUSE_IMGS) $(UBUNTU_IMGS) LOCAL_ASSETS = mbuto.img QEMU_EFI.fd \ $(DEBIAN_IMGS:%=prepared-%) $(FEDORA_IMGS:%=prepared-%) \ - $(UBUNTU_NEW_IMGS:%=prepared-%) + $(UBUNTU_NEW_IMGS:%=prepared-%) \ + nsholder ASSETS = $(DOWNLOAD_ASSETS) $(LOCAL_ASSETS) +CFLAGS = -Wall -Werror + assets: $(ASSETS) mbuto: @@ -68,6 +71,9 @@ mbuto: mbuto.img: passt.mbuto mbuto ./mbuto/mbuto -p ./$< -c lz4 -f $@ +nsholder: nsholder.c + $(CC) $(CFLAGS) -o $@ $^ + QEMU_EFI.fd: ./find-arm64-firmware.sh $@ -- cgit v1.2.3