From 4b156be15e3ad96adb5495758ee4327142fe5cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Wei=C3=9Fe?= Date: Tue, 5 Apr 2022 16:50:51 +0200 Subject: [PATCH] Add kernel panic util function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Weiße --- internal/utils/utils.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 internal/utils/utils.go diff --git a/internal/utils/utils.go b/internal/utils/utils.go new file mode 100644 index 000000000..9da6757c2 --- /dev/null +++ b/internal/utils/utils.go @@ -0,0 +1,17 @@ +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.Println(err) + _ = os.WriteFile("/proc/sys/kernel/sysrq", []byte("1"), 0o644) + _ = os.WriteFile("/proc/sysrq-trigger", []byte("c"), 0o644) + panic(err) +}