Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParentMain/nsenter: do not fail if getwd errors #3329

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions pkg/rootlessutil/parent_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,31 @@ func ParentMain(hostGatewayIP string) error {
detachNetNSMode := detachedNetNSPath != ""
log.L.Debugf("RootlessKit detach-netns mode: %v", detachNetNSMode)

wd, err := os.Getwd()
if err != nil {
return err
}

// FIXME: remove dependency on `nsenter` binary
arg0, err := exec.LookPath("nsenter")
if err != nil {
return err
}
// args are compatible with both util-linux nsenter and busybox nsenter
args := []string{
"-r/", // root dir (busybox nsenter wants this to be explicitly specified),
"-w" + wd, // work dir
"--preserve-credentials",
"-r/", // root dir (busybox nsenter wants this to be explicitly specified),
}

// Only append wd if we do have a working dir
// - https://github.com/rootless-containers/usernetes/pull/327
// - https://github.com/containerd/nerdctl/issues/3328
wd, err := os.Getwd()
if err != nil {
log.L.WithError(err).Warn("unable to determine working directory")
} else {
args = append(args, "-w"+wd)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we may even set the working directory after nsenter with --wdns

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To what path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah - you mean, in case getwd does NOT error, right?

Honestly, I would rather focus efforts on re-exec-ing instead of tweaking nsenter.

}
apostasie marked this conversation as resolved.
Show resolved Hide resolved

args = append(args, "--preserve-credentials",
"-m", "-U",
"-t", strconv.Itoa(childPid),
"-F", // no fork
}
)
if !detachNetNSMode {
args = append(args, "-n")
}
Expand Down
Loading