Skip to content

Commit

Permalink
chroot: add newlines at the end of printed error messages
Browse files Browse the repository at this point in the history
If we print an error message to stderr, end it with a newline.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
  • Loading branch information
nalind committed Sep 24, 2024
1 parent 509de30 commit 2ff91b8
Showing 1 changed file with 8 additions and 8 deletions.
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)
}
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

0 comments on commit 2ff91b8

Please sign in to comment.