Skip to content
This repository was archived by the owner on Nov 14, 2021. It is now read-only.

Commit e609364

Browse files
committed
update Makefile, add delta test folder
1 parent 134c5f7 commit e609364

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ all: build
2121

2222
.PHONY: build
2323
build: $(GO_SRC)
24-
$(GO_BUILD) -buildmode=pie -o $(BUILD_DIR)/$(NAME) $(PROJECT)/sample
24+
$(GO_BUILD) -buildmode=pie -o $(BUILD_DIR)/$(NAME) $(PROJECT)/delta
2525

2626
.PHONY: clean
2727
clean:

delta/delta.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"os"
7+
"strings"
8+
"text/tabwriter"
9+
10+
"github.com/gepis/ps"
11+
"github.com/sirupsen/logrus"
12+
)
13+
14+
func main() {
15+
var (
16+
descriptors []string
17+
pidsList []string
18+
data [][]string
19+
err error
20+
21+
pids = flag.String("pids", "", "comma separated list of process IDs to retrieve")
22+
format = flag.String("format", "", "ps(1) AIX format comma-separated string")
23+
list = flag.Bool("list", false, "list all supported descriptors")
24+
join = flag.Bool("join", false, "join namespace of provided pids (containers)")
25+
fillMappings = flag.Bool("fill-mappings", false, "fill the UID and GID mappings with the current user namespace")
26+
)
27+
28+
flag.Parse()
29+
30+
if *fillMappings && !*join {
31+
fmt.Fprintln(os.Stderr, "-fill-mappings requires -join")
32+
os.Exit(1)
33+
}
34+
35+
if *list {
36+
fmt.Println(strings.Join(ps.ListDescriptors(), ", "))
37+
return
38+
}
39+
40+
if *format != "" {
41+
descriptors = strings.Split(*format, ",")
42+
}
43+
44+
if *pids != "" {
45+
pidsList = strings.Split(*pids, ",")
46+
}
47+
48+
if len(pidsList) > 0 {
49+
opts := ps.JoinNamespaceOpts{FillMappings: *fillMappings}
50+
51+
if *join {
52+
data, err = ps.JoinNamespaceAndProcessInfoByPidsWithOptions(pidsList, descriptors, &opts)
53+
} else {
54+
data, err = ps.ProcessInfoByPids(pidsList, descriptors)
55+
}
56+
57+
if err != nil {
58+
logrus.Panic(err)
59+
}
60+
} else {
61+
data, err = ps.ProcessInfo(descriptors)
62+
if err != nil {
63+
logrus.Panic(err)
64+
}
65+
}
66+
67+
tw := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
68+
for _, d := range data {
69+
fmt.Fprintln(tw, strings.Join(d, "\t"))
70+
}
71+
72+
tw.Flush()
73+
}

0 commit comments

Comments
 (0)