diff --git a/internal/utils/utils.go b/internal/utils/utils.go deleted file mode 100644 index 695f7b4c2..000000000 --- a/internal/utils/utils.go +++ /dev/null @@ -1,17 +0,0 @@ -package utils - -import ( - "fmt" - "os" -) - -// KernelPanic prints the error and triggers a kernel panic. -// -// This function WILL cause a system crash! -// DO NOT call it in any code that may be covered by automatic or manual tests. -func KernelPanic(err error) { - fmt.Fprint(os.Stderr, err) - _ = os.WriteFile("/proc/sys/kernel/sysrq", []byte("1"), 0o644) - _ = os.WriteFile("/proc/sysrq-trigger", []byte("c"), 0o644) - panic(err) -} diff --git a/state/cmd/main.go b/state/cmd/main.go index 6884beaf1..5b1a3e898 100644 --- a/state/cmd/main.go +++ b/state/cmd/main.go @@ -17,7 +17,6 @@ import ( azurecloud "github.com/edgelesssys/constellation/coordinator/cloudprovider/azure" gcpcloud "github.com/edgelesssys/constellation/coordinator/cloudprovider/gcp" "github.com/edgelesssys/constellation/coordinator/core" - "github.com/edgelesssys/constellation/internal/utils" "github.com/edgelesssys/constellation/state/keyservice" "github.com/edgelesssys/constellation/state/mapper" "github.com/edgelesssys/constellation/state/setup" @@ -48,7 +47,7 @@ func main() { diskPath, diskPathErr = filepath.EvalSymlinks(azureStateDiskPath) metadata, err = azurecloud.NewMetadata(context.Background()) if err != nil { - utils.KernelPanic(err) + exit(err) } issuer = azure.NewIssuer() @@ -57,7 +56,7 @@ func main() { issuer = gcp.NewIssuer() gcpClient, err := gcpcloud.NewClient(context.Background()) if err != nil { - utils.KernelPanic(err) + exit(err) } metadata = gcpcloud.New(gcpClient) @@ -71,13 +70,13 @@ func main() { diskPathErr = fmt.Errorf("csp %q is not supported by Constellation", *csp) } if diskPathErr != nil { - utils.KernelPanic(fmt.Errorf("unable to determine state disk path: %w", diskPathErr)) + exit(fmt.Errorf("unable to determine state disk path: %w", diskPathErr)) } // initialize device mapper mapper, err := mapper.New(diskPath) if err != nil { - utils.KernelPanic(err) + exit(err) } defer mapper.Close() @@ -96,8 +95,13 @@ func main() { } else { err = setupManger.PrepareNewDisk() } - - if err != nil { - utils.KernelPanic(err) - } + exit(err) +} + +func exit(err error) { + if err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + os.Exit(1) + } + os.Exit(0) }