Skip to content

Commit

Permalink
fix: cleanup ip netns output before processing
Browse files Browse the repository at this point in the history
  • Loading branch information
bertschneider committed Feb 17, 2025
1 parent bbf4385 commit 1632d75
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion go/action_kit_commons/runc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"slices"
"sort"
"strconv"
Expand All @@ -31,6 +32,8 @@ type BackgroundState struct {
}

var netNsDir = "/var/run/netns"
var netNsOutputCleanup = regexp.MustCompile(`\s*\(id: \d+\)$`)

var executeListNamespaces = executeListNamespaceLsns
var executeRefreshNamespace = executeRefreshNamespaceLsns
var errorNsNotFound = errors.New("namespace not found")
Expand Down Expand Up @@ -506,7 +509,8 @@ func lookupNamedNetworkNamespace(ctx context.Context, targetInode uint64) (strin
lines := strings.Split(sout.String(), "\n")
for _, line := range lines {
if line != "" {
path := fmt.Sprintf("%s/%s", netNsDir, strings.TrimSpace(line))
netNsName := netNsOutputCleanup.ReplaceAllString(line, "")
path := fmt.Sprintf("%s/%s", netNsDir, strings.TrimSpace(netNsName))
inodes, err := executeReadInodes(ctx, path)
if err != nil {
// Ignore error, as named network namespace could have been removed.
Expand Down

0 comments on commit 1632d75

Please sign in to comment.