diff --git a/BUILD.bazel b/BUILD.bazel index a8ded62..1ef1e5d 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,3 +1,4 @@ +load("@aspect_bazel_lib//lib:run_binary.bzl", "run_binary") load("@bazel_gazelle//:def.bzl", "gazelle") load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier") @@ -6,3 +7,16 @@ load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier") gazelle( name = "gazelle", ) + +# $ bazel build //cmd/ls-proc +# $ cp -f bazel-bin/cmd/ls-proc/ls-proc_/ls-proc ls-proc +run_binary( + name = "introspection", + outs = ["out"], + args = ["$(location out)"], + execution_requirements = { + "no-cache": "1", + }, + tool = ":ls-proc", + srcs = ["usr/bin/env"], +) diff --git a/cmd/ls-proc/BUILD.bazel b/cmd/ls-proc/BUILD.bazel new file mode 100644 index 0000000..57e2e7b --- /dev/null +++ b/cmd/ls-proc/BUILD.bazel @@ -0,0 +1,15 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") + +go_library( + name = "go_default_library", + srcs = ["main.go"], + importpath = "github.com/buildbarn/bb-deployments/cmd/ls-proc", + visibility = ["//visibility:private"], +) + +go_binary( + name = "ls-proc", + embed = [":go_default_library"], + visibility = ["//visibility:public"], + pure = "on", +) diff --git a/cmd/ls-proc/main.go b/cmd/ls-proc/main.go new file mode 100644 index 0000000..771b8a1 --- /dev/null +++ b/cmd/ls-proc/main.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "os" + "log" +) + +func main() { + entries, err := os.ReadDir("/proc/self") + if err != nil { + log.Fatal("Reading /proc/self:", err) + } + + max := 10 + for i, e := range entries { + if i > max { + break + } + fmt.Println(e.Name()) + } + + os.Create(os.Args[1]) +} diff --git a/ls-proc b/ls-proc new file mode 100755 index 0000000..011b4bb Binary files /dev/null and b/ls-proc differ diff --git a/usr/bin/env b/usr/bin/env new file mode 100755 index 0000000..6b888df Binary files /dev/null and b/usr/bin/env differ