Skip to content

Commit

Permalink
feat: display sockets in process tree
Browse files Browse the repository at this point in the history
This is now supported with the `--sockets` flag.

Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
  • Loading branch information
snprajwal committed Jul 28, 2023
1 parent 8e4f577 commit ea92e09
Show file tree
Hide file tree
Showing 72 changed files with 1,123 additions and 479 deletions.
28 changes: 24 additions & 4 deletions checkpointctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
psTreeCmd bool
psTreeEnv bool
files bool
sockets bool
showAll bool
)

Expand Down Expand Up @@ -123,6 +124,12 @@ func setupInspect() *cobra.Command {
false,
"Display the open file descriptors for processes in the container checkpoint",
)
flags.BoolVar(
&sockets,
"sockets",
false,
"Display the open sockets for processes in the container checkpoint",
)
flags.BoolVar(
&showAll,
"all",
Expand All @@ -145,6 +152,7 @@ func inspect(cmd *cobra.Command, args []string) error {
mounts = true
psTree = true
files = true
sockets = true
}

requiredFiles := []string{metadata.SpecDumpFile, metadata.ConfigDumpFile}
Expand All @@ -165,12 +173,24 @@ func inspect(cmd *cobra.Command, args []string) error {
psTree = true
requiredFiles = append(
requiredFiles,
// Unpack files.img, fs-*.img, ids-*.img, fdinfo-*.img
filepath.Join(metadata.CheckpointDirectory, "files.img"),
// fs-*.img
filepath.Join(metadata.CheckpointDirectory, "fs-"),
// ids-*.img
filepath.Join(metadata.CheckpointDirectory, "ids-"),
// fdinfo-*.img
filepath.Join(metadata.CheckpointDirectory, "fdinfo-"),
)
}

if sockets {
// Enable displaying process tree, even if it is not passed.
// This is necessary to attach the sockets to the processes
// that opened them and display this in the tree.
psTree = true
requiredFiles = append(
requiredFiles,
// Unpack files.img, ids-*.img, fdinfo-*.img
filepath.Join(metadata.CheckpointDirectory, "files.img"),
filepath.Join(metadata.CheckpointDirectory, "ids-"),
filepath.Join(metadata.CheckpointDirectory, "fdinfo-"),
)
}
Expand All @@ -190,8 +210,8 @@ func inspect(cmd *cobra.Command, args []string) error {
if psTree {
requiredFiles = append(
requiredFiles,
// Unpack pstree.img, core-*.img
filepath.Join(metadata.CheckpointDirectory, "pstree.img"),
// core-*.img
filepath.Join(metadata.CheckpointDirectory, "core-"),
)
}
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ require (
github.com/ulikunitz/xz v0.5.11 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)

replace github.com/checkpoint-restore/go-criu/v6 => github.com/snprajwal/go-criu/v6 v6.0.0-20230728185933-81f1b7c9e43c
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/checkpoint-restore/go-criu/v6 v6.3.1-0.20230705155226-f8745d1ee56a h1:I9EbXzk/kRIcXDGk9VAdYjGTicrok3Bu3WZ+SOJ3K2E=
github.com/checkpoint-restore/go-criu/v6 v6.3.1-0.20230705155226-f8745d1ee56a/go.mod h1:uuIaCJCnWcRzK88xoScsiKHpwBlF8uChRbyhi/BZiZg=
github.com/containers/storage v1.48.0 h1:wiPs8J2xiFoOEAhxHDRtP6A90Jzj57VqzLRXOqeizns=
github.com/containers/storage v1.48.0/go.mod h1:pRp3lkRo2qodb/ltpnudoXggrviRmaCmU5a5GhTBae0=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down Expand Up @@ -32,6 +30,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/snprajwal/go-criu/v6 v6.0.0-20230728185933-81f1b7c9e43c h1:K3P4KGwYOY+qI7XOgbAIIrcSIVXImKKuaYUqUjntUl4=
github.com/snprajwal/go-criu/v6 v6.0.0-20230728185933-81f1b7c9e43c/go.mod h1:3eG5SDBmX8R3iY7kAnrj11UrR7DgmHFiJy+ygS9mlNo=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand All @@ -53,8 +53,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
36 changes: 36 additions & 0 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ func renderTreeView(tasks []task) error {
addFdsToTree(tree, fds)
}

if sockets {
c := crit.New(nil, nil, filepath.Join(task.outputDir, "checkpoint"), false, false)
fds, err := c.ExploreSk()
if err != nil {
return fmt.Errorf("failed to get sockets: %w", err)
}

addSkToTree(tree, fds)
}

if mounts {
addMountsToTree(tree, info.specDump)
}
Expand Down Expand Up @@ -187,6 +197,32 @@ func addFdsToTree(tree treeprint.Tree, fds []*crit.Fd) {
}
}

func addSkToTree(tree treeprint.Tree, sks []*crit.Sk) {
var node treeprint.Tree
for _, sk := range sks {
node = tree.FindByMeta(sk.PId)
// If FindByMeta returns nil, then the node with
// the PID has been pruned while building the tree.
// Hence, skip all associated sockets.
if node == nil {
continue
}
for _, socket := range sk.Sockets {
node.AddMetaBranch(
fmt.Sprintf("%s (%s)", socket.Type, socket.Protocol),
fmt.Sprintf(
"%s:%d -> %s:%d [%s]",
socket.SrcAddr,
socket.SrcPort,
socket.DestAddr,
socket.DestPort,
socket.State,
),
)
}
}
}

// Recursively updates the Comm field of the psTree struct with the command line arguments
// from process memory pages
func updatePsTreeCommToCmdline(checkpointOutputDir string, psTree *crit.PsTree) error {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ea92e09

Please sign in to comment.