aboutsummaryrefslogtreecommitdiffhomepage
path: root/ldd
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-02-28 20:37:01 +0900
committerOphestra <cat@gensokyo.uk>2026-02-28 20:37:01 +0900
commit4b0cce4db5f8e75c79e104f8c5ec02cb4541ed76 (patch)
tree3143e1a8f9f28dbd3093b4329066b6d6db0b8156 /ldd
parentcd9b534d6b1d432d3c997ccc5b14f630afb9dda6 (diff)
ldd: treat nil pathname as self
This is a helpful shortcut for examining a test program's ldd output. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'ldd')
-rw-r--r--ldd/exec.go14
-rw-r--r--ldd/exec_test.go2
2 files changed, 14 insertions, 2 deletions
diff --git a/ldd/exec.go b/ldd/exec.go
index bbcf2958..c0b40655 100644
--- a/ldd/exec.go
+++ b/ldd/exec.go
@@ -36,7 +36,19 @@ const (
// [os.SyscallError] for fault creating the stdout pipe,
// [container.StartError] for fault during either stage of container setup.
// Otherwise, it passes through the return values of [Decoder.Decode].
-func Resolve(ctx context.Context, msg message.Msg, pathname *check.Absolute) ([]*Entry, error) {
+func Resolve(
+ ctx context.Context,
+ msg message.Msg,
+ pathname *check.Absolute,
+) ([]*Entry, error) {
+ if pathname == nil {
+ if p, err := os.Executable(); err != nil {
+ return nil, err
+ } else if pathname, err = check.NewAbs(p); err != nil {
+ return nil, err
+ }
+ }
+
c, cancel := context.WithTimeout(ctx, lddTimeout)
defer cancel()
diff --git a/ldd/exec_test.go b/ldd/exec_test.go
index 8c35a905..a1e97344 100644
--- a/ldd/exec_test.go
+++ b/ldd/exec_test.go
@@ -34,7 +34,7 @@ func TestExec(t *testing.T) {
t.Run("success", func(t *testing.T) {
msg := message.New(nil)
msg.GetLogger().SetPrefix("check: ")
- if entries, err := ldd.Resolve(t.Context(), nil, check.MustAbs(container.MustExecutable(msg))); err != nil {
+ if entries, err := ldd.Resolve(t.Context(), nil, nil); err != nil {
t.Fatalf("Exec: error = %v", err)
} else if testing.Verbose() {
// result cannot be measured here as build information is not known