github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/recovery/permissiverecoverer.go (about)

     1  // Copyright 2017-2019 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package recovery
     6  
     7  import (
     8  	"log"
     9  	"os/exec"
    10  )
    11  
    12  // PermissiveRecoverer properties
    13  // RecoveryCommand: unix command with absolute file path
    14  type PermissiveRecoverer struct {
    15  	RecoveryCommand string
    16  }
    17  
    18  // Recover logs error message in panic mode.
    19  // Can jump into a shell for later debugging.
    20  func (pr PermissiveRecoverer) Recover(message string) error {
    21  	log.Print(message)
    22  
    23  	if pr.RecoveryCommand != "" {
    24  		cmd := exec.Command(pr.RecoveryCommand)
    25  		if err := cmd.Run(); err != nil {
    26  			return err
    27  		}
    28  	}
    29  
    30  	return nil
    31  }