aboutsummaryrefslogtreecommitdiffhomepage
path: root/ldd
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-03-17 13:53:14 +0900
committerOphestra <cat@gensokyo.uk>2026-03-17 13:53:14 +0900
commit0cb1007daaea2b8f6b28bff72aa5d08aea981ea9 (patch)
tree9950dcdaaaf67bdd937c83855dd6401e35012d6e /ldd
parente292031624b7fe57d508476828e51ca66d520bcb (diff)
ldd: remove deprecated API
Closes #25. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'ldd')
-rw-r--r--ldd/exec.go21
-rw-r--r--ldd/ldd.go63
2 files changed, 42 insertions, 42 deletions
diff --git a/ldd/exec.go b/ldd/exec.go
index c0b40655..7392bd8b 100644
--- a/ldd/exec.go
+++ b/ldd/exec.go
@@ -18,14 +18,17 @@ import (
)
const (
- // msgStaticSuffix is the suffix of message printed to stderr by musl on a statically linked program.
+ // msgStaticSuffix is the suffix of message printed to stderr by musl on a
+ // statically linked program.
msgStaticSuffix = ": Not a valid dynamic program"
- // msgStaticGlibc is a substring of the message printed to stderr by glibc on a statically linked program.
+ // msgStaticGlibc is a substring of the message printed to stderr by glibc
+ // on a statically linked program.
msgStaticGlibc = "not a dynamic executable"
// lddName is the file name of ldd(1) passed to exec.LookPath.
lddName = "ldd"
- // lddTimeout is the maximum duration ldd(1) is allowed to ran for before it is terminated.
+ // lddTimeout is the maximum duration ldd(1) is allowed to ran for before it
+ // is terminated.
lddTimeout = 4 * time.Second
)
@@ -104,15 +107,3 @@ func Resolve(
}
return entries, decodeErr
}
-
-// Exec runs ldd(1) in a restrictive [container] and connects it to a [Decoder], returning resulting entries.
-//
-// Deprecated: this function takes an unchecked pathname string.
-// Relative pathnames do not work in the container as working directory information is not sent.
-func Exec(ctx context.Context, msg message.Msg, pathname string) ([]*Entry, error) {
- if a, err := check.NewAbs(pathname); err != nil {
- return nil, err
- } else {
- return Resolve(ctx, msg, a)
- }
-}
diff --git a/ldd/ldd.go b/ldd/ldd.go
index 9c892d7a..2e8cf59f 100644
--- a/ldd/ldd.go
+++ b/ldd/ldd.go
@@ -1,9 +1,9 @@
-// Package ldd provides a robust parser for ldd(1) output, and a convenience function
-// for running ldd(1) in a strict sandbox.
+// Package ldd provides a robust parser for ldd(1) output, and a convenience
+// function for running ldd(1) in a strict sandbox.
//
-// Note: despite the additional hardening, great care must be taken when using ldd(1).
-// As a general rule, you must never run ldd(1) against a file that you do not wish to
-// execute within the same context.
+// Note: despite the additional hardening, great care must be taken when using
+// ldd(1). As a general rule, you must never run ldd(1) against a file that you
+// do not wish to execute within the same context.
package ldd
import (
@@ -27,8 +27,8 @@ var (
ErrBadLocationFormat = errors.New("bad location format")
)
-// EntryUnexpectedSegmentsError is returned when encountering
-// a line containing unexpected number of segments.
+// EntryUnexpectedSegmentsError is returned when encountering a line containing
+// unexpected number of segments.
type EntryUnexpectedSegmentsError string
func (e EntryUnexpectedSegmentsError) Error() string {
@@ -51,26 +51,31 @@ const (
// entrySegmentIndexPath is the index of the segment holding [Entry.Path],
// present only for a line describing a fully populated [Entry].
entrySegmentIndexPath = 2
- // entrySegmentIndexSeparator is the index of the segment containing the magic bytes entrySegmentFullSeparator,
- // present only for a line describing a fully populated [Entry].
+ // entrySegmentIndexSeparator is the index of the segment containing the
+ // magic bytes entrySegmentFullSeparator, present only for a line describing
+ // a fully populated [Entry].
entrySegmentIndexSeparator = 1
- // entrySegmentIndexLocation is the index of the segment holding [Entry.Location]
- // for a line describing a fully populated [Entry].
+ // entrySegmentIndexLocation is the index of the segment holding
+ // [Entry.Location] for a line describing a fully populated [Entry].
entrySegmentIndexLocation = 3
- // entrySegmentIndexLocationShort is the index of the segment holding [Entry.Location]
- // for a line describing only [Entry.Name].
+ // entrySegmentIndexLocationShort is the index of the segment holding
+ // [Entry.Location] for a line describing only [Entry.Name].
entrySegmentIndexLocationShort = 1
// entrySegmentSep is the byte separating segments in an [Entry] line.
entrySegmentSep = ' '
- // entrySegmentFullSeparator is the exact contents of the segment at index entrySegmentIndexSeparator.
+ // entrySegmentFullSeparator is the exact contents of the segment at index
+ // entrySegmentIndexSeparator.
entrySegmentFullSeparator = "=>"
- // entrySegmentLocationLengthMin is the minimum possible length of a segment corresponding to [Entry.Location].
+ // entrySegmentLocationLengthMin is the minimum possible length of a segment
+ // corresponding to [Entry.Location].
entrySegmentLocationLengthMin = 4
- // entrySegmentLocationPrefix are magic bytes prefixing a segment corresponding to [Entry.Location].
+ // entrySegmentLocationPrefix are magic bytes prefixing a segment
+ // corresponding to [Entry.Location].
entrySegmentLocationPrefix = "(0x"
- // entrySegmentLocationSuffix is the magic byte suffixing a segment corresponding to [Entry.Location].
+ // entrySegmentLocationSuffix is the magic byte suffixing a segment
+ // corresponding to [Entry.Location].
entrySegmentLocationSuffix = ')'
)
@@ -144,7 +149,9 @@ func (e *Entry) String() string {
if e.Path != nil {
buf.WriteString(entrySegmentFullSeparator + " " + e.Path.String() + " ")
}
- buf.WriteString(entrySegmentLocationPrefix + strconv.FormatUint(e.Location, 16) + string(entrySegmentLocationSuffix))
+ buf.WriteString(entrySegmentLocationPrefix +
+ strconv.FormatUint(e.Location, 16) +
+ string(entrySegmentLocationSuffix))
return buf.String()
}
@@ -180,12 +187,12 @@ type Decoder struct {
// NewDecoder returns a new decoder that reads from r.
//
-// The decoder introduces its own buffering and may read
-// data from r beyond the [Entry] values requested.
+// The decoder introduces its own buffering and may read data from r beyond the
+// [Entry] values requested.
func NewDecoder(r io.Reader) *Decoder { return &Decoder{s: bufio.NewScanner(r)} }
-// Scan advances the [Decoder] to the next [Entry] and
-// stores the result in the value pointed to by v.
+// Scan advances the [Decoder] to the next [Entry] and stores the result in the
+// value pointed to by v.
func (d *Decoder) Scan(v *Entry) bool {
if d.s == nil || d.err != nil || d.depleted {
return false
@@ -215,8 +222,8 @@ func (d *Decoder) Scan(v *Entry) bool {
return d.err == nil
}
-// Err returns the first non-EOF error that was encountered
-// by the underlying [bufio.Scanner] or [Entry].
+// Err returns the first non-EOF error that was encountered by the underlying
+// [bufio.Scanner] or [Entry].
func (d *Decoder) Err() error {
if d.err != nil || d.s == nil {
return d.err
@@ -224,8 +231,8 @@ func (d *Decoder) Err() error {
return d.s.Err()
}
-// Decode reads from the input stream until there are no more entries
-// and returns the results in a slice.
+// Decode reads from the input stream until there are no more entries and
+// returns the results in a slice.
func (d *Decoder) Decode() ([]*Entry, error) {
var entries []*Entry
@@ -238,4 +245,6 @@ func (d *Decoder) Decode() ([]*Entry, error) {
}
// Parse returns a slice of addresses to [Entry] decoded from p.
-func Parse(p []byte) ([]*Entry, error) { return NewDecoder(bytes.NewReader(p)).Decode() }
+func Parse(p []byte) ([]*Entry, error) {
+ return NewDecoder(bytes.NewReader(p)).Decode()
+}