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

chroot: add newlines at the end of printed error messages #5753

Merged
merged 1 commit into from
Oct 23, 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
16 changes: 8 additions & 8 deletions chroot/run_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ func runUsingChroot(spec *specs.Spec, bundlePath string, ctty *os.File, stdin io
BundlePath: bundlePath,
})
if conferr != nil {
fmt.Fprintf(os.Stderr, "error re-encoding configuration for %q", runUsingChrootExecCommand)
fmt.Fprintf(os.Stderr, "error re-encoding configuration for %q\n", runUsingChrootExecCommand)
os.Exit(1)
}

Expand Down Expand Up @@ -567,7 +567,7 @@ func runUsingChroot(spec *specs.Spec, bundlePath string, ctty *os.File, stdin io
}
}
}
fmt.Fprintf(os.Stderr, "process exited with error: %v", err)
fmt.Fprintf(os.Stderr, "process exited with error: %v\n", err)
os.Exit(1)
}

Expand Down Expand Up @@ -695,23 +695,23 @@ func runUsingChrootExecMain() {
}
logrus.Debugf("setting supplemental groups")
if err = syscall.Setgroups(gids); err != nil {
fmt.Fprintf(os.Stderr, "error setting supplemental groups list: %v", err)
fmt.Fprintf(os.Stderr, "error setting supplemental groups list: %v\n", err)
os.Exit(1)
}
} else {
setgroups, _ := os.ReadFile("/proc/self/setgroups")
if strings.Trim(string(setgroups), "\n") != "deny" {
logrus.Debugf("clearing supplemental groups")
if err = syscall.Setgroups([]int{}); err != nil {
fmt.Fprintf(os.Stderr, "error clearing supplemental groups list: %v", err)
fmt.Fprintf(os.Stderr, "error clearing supplemental groups list: %v\n", err)
os.Exit(1)
}
}
}

logrus.Debugf("setting gid")
if err = unix.Setresgid(int(user.GID), int(user.GID), int(user.GID)); err != nil {
fmt.Fprintf(os.Stderr, "error setting GID: %v", err)
fmt.Fprintf(os.Stderr, "error setting GID: %v\n", err)
os.Exit(1)
}

Expand All @@ -732,7 +732,7 @@ func runUsingChrootExecMain() {

logrus.Debugf("setting uid")
if err = unix.Setresuid(int(user.UID), int(user.UID), int(user.UID)); err != nil {
fmt.Fprintf(os.Stderr, "error setting UID: %v", err)
fmt.Fprintf(os.Stderr, "error setting UID: %v\n", err)
os.Exit(1)
}

Expand All @@ -745,7 +745,7 @@ func runUsingChrootExecMain() {
logrus.Debugf("Running %#v (PATH = %q)", cmd, os.Getenv("PATH"))
interrupted := make(chan os.Signal, 100)
if err = cmd.Start(); err != nil {
fmt.Fprintf(os.Stderr, "process failed to start with error: %v", err)
fmt.Fprintf(os.Stderr, "process failed to start with error: %v\n", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is ~unrelated and pre-existing — the documentation of cmd.Wait() says

The command must have been started by Cmd.Start.

and reading the code ~confirms that .Start must have succeeded. So, shouldn’t this exit immediately?

}
go func() {
for range interrupted {
Expand All @@ -772,7 +772,7 @@ func runUsingChrootExecMain() {
}
}
}
fmt.Fprintf(os.Stderr, "process exited with error: %v", err)
fmt.Fprintf(os.Stderr, "process exited with error: %v\n", err)
os.Exit(1)
}
}
Expand Down
Loading