Skip to content

Commit

Permalink
libct/StartInitialization: rename returned error
Browse files Browse the repository at this point in the history
This makes the code more straightforward about when are we using it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Aug 5, 2022
1 parent 3ea88ba commit e377e20
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions libcontainer/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ type initConfig struct {
// StartInitialization loads a container by opening the pipe fd from the parent
// to read the configuration and state. This is a low level implementation
// detail of the reexec and should not be consumed externally.
func StartInitialization() (err error) {
func StartInitialization() (retErr error) {
var err error

// Set up logging.
level := int(logrus.DebugLevel) // default to debug
// Passing log level is optional; currently libcontainer/integration does not do it.
Expand Down Expand Up @@ -115,12 +117,12 @@ func StartInitialization() (err error) {
defer func() {
// We have an error during the initialization of the container's init,
// send it back to the parent process in the form of an initError.
if werr := writeSync(pipe, procError); werr != nil {
fmt.Fprintln(os.Stderr, err)
if err := writeSync(pipe, procError); err != nil {
fmt.Fprintln(os.Stderr, retErr)
return
}
if werr := utils.WriteJSON(pipe, &initError{Message: err.Error()}); werr != nil {
fmt.Fprintln(os.Stderr, err)
if err := utils.WriteJSON(pipe, &initError{Message: retErr.Error()}); err != nil {
fmt.Fprintln(os.Stderr, retErr)
return
}
}()
Expand Down Expand Up @@ -157,11 +159,11 @@ func StartInitialization() (err error) {
os.Clearenv()

defer func() {
if e := recover(); e != nil {
if ee, ok := e.(error); ok {
err = fmt.Errorf("panic from initialization: %w, %s", ee, debug.Stack())
if err := recover(); err != nil {
if err2, ok := err.(error); ok {
retErr = fmt.Errorf("panic from initialization: %w, %s", err2, debug.Stack())
} else {
err = fmt.Errorf("panic from initialization: %v, %s", e, debug.Stack())
retErr = fmt.Errorf("panic from initialization: %v, %s", err, debug.Stack())
}
}
}()
Expand Down

0 comments on commit e377e20

Please sign in to comment.