Repository: opencontainers/runc
Pull request #4377 (2024-08-14 09:45:18)

mv contrib/cmd tests/cmd (except memfd-bind)
The following commands are moved from `contrib/cmd` to `tests/cmd`:
- fs-idmap
- pidfd-kill
- recvtty
- remap-rootfs
- sd-helper
- seccompagent

So as to clarify that distro maintainers should not include these binaries in their package.

ref: https://bugs.launchpad.net/ubuntu/+source/runc/+bug/2076981

AkihiroSuda: Updated `make all` to print a note.
kolyshkin: In fact, we have 8 entries in there.
* 7 of them are used by tests/integration, and should probably be moved there (say to `tests/cmd/`). The only other thing to do is to fix the link to recvtty from docs/terminal.md.
* 1 (`memfd-bind`) can be kept as-is, its documentation is adequately telling distro maintainers what to do with it.

Patch:
diff --git a/.gitignore b/.gitignore
index 1fcbcfbd..8cab96cb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,13 +1,13 @@
 vendor/pkg
 /runc
 /runc-*
-/contrib/cmd/recvtty/recvtty
-/contrib/cmd/sd-helper/sd-helper
-/contrib/cmd/seccompagent/seccompagent
-/contrib/cmd/fs-idmap/fs-idmap
 /contrib/cmd/memfd-bind/memfd-bind
-/contrib/cmd/pidfd-kill/pidfd-kill
-/contrib/cmd/remap-rootfs/remap-rootfs
+/tests/cmd/recvtty/recvtty
+/tests/cmd/sd-helper/sd-helper
+/tests/cmd/seccompagent/seccompagent
+/tests/cmd/fs-idmap/fs-idmap
+/tests/cmd/pidfd-kill/pidfd-kill
+/tests/cmd/remap-rootfs/remap-rootfs
 man/man8
 release
 Vagrantfile
diff --git a/Makefile b/Makefile
index 94b9a3c3..ba08b886 100644
--- a/Makefile
+++ b/Makefile
@@ -78,22 +78,26 @@ runc-bin: runc-dmz
 	$(GO_BUILD) -o runc .
 
 .PHONY: all
-all: runc recvtty sd-helper seccompagent fs-idmap memfd-bind pidfd-kill remap-rootfs
+all: runc memfd-bind recvtty sd-helper seccompagent fs-idmap pidfd-kill remap-rootfs
 
-.PHONY: recvtty sd-helper seccompagent fs-idmap memfd-bind pidfd-kill remap-rootfs
-recvtty sd-helper seccompagent fs-idmap memfd-bind pidfd-kill remap-rootfs:
+.PHONY: memfd-bind
+memfd-bind:
 	$(GO_BUILD) -o contrib/cmd/$@/$@ ./contrib/cmd/$@
 
+.PHONY: recvtty sd-helper seccompagent fs-idmap pidfd-kill remap-rootfs
+recvtty sd-helper seccompagent fs-idmap pidfd-kill remap-rootfs:
+	$(GO_BUILD) -o tests/cmd/$@/$@ ./tests/cmd/$@
+
 .PHONY: clean
 clean:
 	rm -f runc runc-* libcontainer/dmz/binary/runc-dmz
-	rm -f contrib/cmd/recvtty/recvtty
-	rm -f contrib/cmd/sd-helper/sd-helper
-	rm -f contrib/cmd/seccompagent/seccompagent
-	rm -f contrib/cmd/fs-idmap/fs-idmap
 	rm -f contrib/cmd/memfd-bind/memfd-bind
-	rm -f contrib/cmd/pidfd-kill/pidfd-kill
-	rm -f contrib/cmd/remap-rootfs/remap-rootfs
+	rm -f tests/cmd/recvtty/recvtty
+	rm -f tests/cmd/sd-helper/sd-helper
+	rm -f tests/cmd/seccompagent/seccompagent
+	rm -f tests/cmd/fs-idmap/fs-idmap
+	rm -f tests/cmd/pidfd-kill/pidfd-kill
+	rm -f tests/cmd/remap-rootfs/remap-rootfs
 	sudo rm -rf release
 	rm -rf man/man8
 
diff --git a/docs/terminals.md b/docs/terminals.md
index aa9f71ee..1e53f5de 100644
--- a/docs/terminals.md
+++ b/docs/terminals.md
@@ -351,4 +351,4 @@ a [Go implementation in the `go-runc` bindings][containerd/go-runc.Socket], as
 well as [a simple client][recvtty].
 
 [containerd/go-runc.Socket]: https://godoc.org/github.com/containerd/go-runc#Socket
-[recvtty]: /contrib/cmd/recvtty
+[recvtty]: /tests/cmd/recvtty
diff --git a/contrib/cmd/fs-idmap/fs-idmap.go b/tests/cmd/fs-idmap/fs-idmap.go
similarity index 100%
rename from contrib/cmd/fs-idmap/fs-idmap.go
rename to tests/cmd/fs-idmap/fs-idmap.go
diff --git a/contrib/cmd/pidfd-kill/pidfd-kill.go b/tests/cmd/pidfd-kill/pidfd-kill.go
similarity index 97%
rename from contrib/cmd/pidfd-kill/pidfd-kill.go
rename to tests/cmd/pidfd-kill/pidfd-kill.go
index b5caa4f2..ea9a9df8 100644
--- a/contrib/cmd/pidfd-kill/pidfd-kill.go
+++ b/tests/cmd/pidfd-kill/pidfd-kill.go
@@ -14,7 +14,7 @@ import (
 )
 
 const (
-	usage = `Open Container Initiative contrib/cmd/pidfd-kill
+	usage = `Open Container Initiative tests/cmd/pidfd-kill
 
 pidfd-kill is an implementation of a consumer of runC's --pidfd-socket API.
 After received SIGTERM, pidfd-kill sends the given signal to init process by
diff --git a/contrib/cmd/recvtty/recvtty.go b/tests/cmd/recvtty/recvtty.go
similarity index 98%
rename from contrib/cmd/recvtty/recvtty.go
rename to tests/cmd/recvtty/recvtty.go
index 532a4c33..2c82665a 100644
--- a/contrib/cmd/recvtty/recvtty.go
+++ b/tests/cmd/recvtty/recvtty.go
@@ -39,7 +39,7 @@ var version = ""
 var gitCommit = ""
 
 const (
-	usage = `Open Container Initiative contrib/cmd/recvtty
+	usage = `Open Container Initiative tests/cmd/recvtty
 
 recvtty is a reference implementation of a consumer of runC's --console-socket
 API. It has two main modes of operation:
diff --git a/contrib/cmd/remap-rootfs/remap-rootfs.go b/tests/cmd/remap-rootfs/remap-rootfs.go
similarity index 98%
rename from contrib/cmd/remap-rootfs/remap-rootfs.go
rename to tests/cmd/remap-rootfs/remap-rootfs.go
index b9739ba8..0c4eb202 100644
--- a/contrib/cmd/remap-rootfs/remap-rootfs.go
+++ b/tests/cmd/remap-rootfs/remap-rootfs.go
@@ -13,7 +13,7 @@ import (
 	"github.com/opencontainers/runtime-spec/specs-go"
 )
 
-const usage = `contrib/cmd/remap-rootfs
+const usage = `tests/cmd/remap-rootfs
 
 remap-rootfs is a helper tool to remap the root filesystem of a Open Container
 Initiative bundle using user namespaces such that the file owners are remapped
diff --git a/contrib/cmd/sd-helper/helper.go b/tests/cmd/sd-helper/helper.go
similarity index 96%
rename from contrib/cmd/sd-helper/helper.go
rename to tests/cmd/sd-helper/helper.go
index fc2bf38a..49b77d00 100644
--- a/contrib/cmd/sd-helper/helper.go
+++ b/tests/cmd/sd-helper/helper.go
@@ -13,7 +13,7 @@ import (
 )
 
 func usage() {
-	fmt.Print(`Open Container Initiative contrib/cmd/sd-helper
+	fmt.Print(`Open Container Initiative tests/cmd/sd-helper
 
 sd-helper is a tool that uses runc/libcontainer/cgroups/systemd package
 functionality to communicate to systemd in order to perform various operations.
diff --git a/contrib/cmd/seccompagent/README.md b/tests/cmd/seccompagent/README.md
similarity index 97%
rename from contrib/cmd/seccompagent/README.md
rename to tests/cmd/seccompagent/README.md
index d42d4bda..80638797 100644
--- a/contrib/cmd/seccompagent/README.md
+++ b/tests/cmd/seccompagent/README.md
@@ -17,7 +17,7 @@ make all
 
 Run the seccomp agent in the background:
 ```bash
-sudo ./contrib/cmd/seccompagent/seccompagent &
+sudo ./tests/cmd/seccompagent/seccompagent &
 ```
 
 Prepare a container:


Test patch:
diff --git a/contrib/cmd/seccompagent/gen-seccomp-example-cfg.sh b/tests/cmd/seccompagent/gen-seccomp-example-cfg.sh
similarity index 100%
rename from contrib/cmd/seccompagent/gen-seccomp-example-cfg.sh
rename to tests/cmd/seccompagent/gen-seccomp-example-cfg.sh
diff --git a/contrib/cmd/seccompagent/seccompagent.go b/tests/cmd/seccompagent/seccompagent.go
similarity index 100%
rename from contrib/cmd/seccompagent/seccompagent.go
rename to tests/cmd/seccompagent/seccompagent.go
diff --git a/contrib/cmd/seccompagent/unsupported.go b/tests/cmd/seccompagent/unsupported.go
similarity index 100%
rename from contrib/cmd/seccompagent/unsupported.go
rename to tests/cmd/seccompagent/unsupported.go
diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash
index a644bbad..76fbab3f 100755
--- a/tests/integration/helpers.bash
+++ b/tests/integration/helpers.bash
@@ -13,12 +13,12 @@ eval "$IMAGES"
 unset IMAGES
 
 : "${RUNC:="${INTEGRATION_ROOT}/../../runc"}"
-RECVTTY="${INTEGRATION_ROOT}/../../contrib/cmd/recvtty/recvtty"
-SD_HELPER="${INTEGRATION_ROOT}/../../contrib/cmd/sd-helper/sd-helper"
-SECCOMP_AGENT="${INTEGRATION_ROOT}/../../contrib/cmd/seccompagent/seccompagent"
-FS_IDMAP="${INTEGRATION_ROOT}/../../contrib/cmd/fs-idmap/fs-idmap"
-PIDFD_KILL="${INTEGRATION_ROOT}/../../contrib/cmd/pidfd-kill/pidfd-kill"
-REMAP_ROOTFS="${INTEGRATION_ROOT}/../../contrib/cmd/remap-rootfs/remap-rootfs"
+RECVTTY="${INTEGRATION_ROOT}/../../tests/cmd/recvtty/recvtty"
+SD_HELPER="${INTEGRATION_ROOT}/../../tests/cmd/sd-helper/sd-helper"
+SECCOMP_AGENT="${INTEGRATION_ROOT}/../../tests/cmd/seccompagent/seccompagent"
+FS_IDMAP="${INTEGRATION_ROOT}/../../tests/cmd/fs-idmap/fs-idmap"
+PIDFD_KILL="${INTEGRATION_ROOT}/../../tests/cmd/pidfd-kill/pidfd-kill"
+REMAP_ROOTFS="${INTEGRATION_ROOT}/../../tests/cmd/remap-rootfs/remap-rootfs"
 
 # Some variables may not always be set. Set those to empty value,
 # if unset, to avoid "unbound variable" error.
diff --git a/tests/integration/seccomp-notify.bats b/tests/integration/seccomp-notify.bats
index 58492090..fcbd5664 100644
--- a/tests/integration/seccomp-notify.bats
+++ b/tests/integration/seccomp-notify.bats
@@ -214,7 +214,7 @@ function scmp_act_notify_template() {
 @test "runc run [seccomp] (SCMP_ACT_NOTIFY example config)" {
 	# Run the script used in the seccomp agent example.
 	# This takes a bare config.json and modifies it to run an example.
-	"${INTEGRATION_ROOT}/../../contrib/cmd/seccompagent/gen-seccomp-example-cfg.sh"
+	"${INTEGRATION_ROOT}/../../tests/cmd/seccompagent/gen-seccomp-example-cfg.sh"
 
 	# The listenerPath the previous command uses is the default used by the
 	# seccomp agent. However, inside bats the socket is in a bats tmp dir.