ldd: treat nil pathname as self
All checks were successful
Test / Create distribution (push) Successful in 56s
Test / Sandbox (push) Successful in 2m35s
Test / Hakurei (push) Successful in 3m46s
Test / ShareFS (push) Successful in 3m51s
Test / Hpkg (push) Successful in 4m21s
Test / Sandbox (race detector) (push) Successful in 4m54s
Test / Hakurei (race detector) (push) Successful in 5m53s
Test / Flake checks (push) Successful in 1m46s

This is a helpful shortcut for examining a test program's ldd output.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-02-28 20:37:01 +09:00
parent cd9b534d6b
commit 4b0cce4db5
2 changed files with 14 additions and 2 deletions

View File

@@ -36,7 +36,19 @@ const (
// [os.SyscallError] for fault creating the stdout pipe, // [os.SyscallError] for fault creating the stdout pipe,
// [container.StartError] for fault during either stage of container setup. // [container.StartError] for fault during either stage of container setup.
// Otherwise, it passes through the return values of [Decoder.Decode]. // 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) c, cancel := context.WithTimeout(ctx, lddTimeout)
defer cancel() defer cancel()

View File

@@ -34,7 +34,7 @@ func TestExec(t *testing.T) {
t.Run("success", func(t *testing.T) { t.Run("success", func(t *testing.T) {
msg := message.New(nil) msg := message.New(nil)
msg.GetLogger().SetPrefix("check: ") 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) t.Fatalf("Exec: error = %v", err)
} else if testing.Verbose() { } else if testing.Verbose() {
// result cannot be measured here as build information is not known // result cannot be measured here as build information is not known