summaryrefslogtreecommitdiffstats
path: root/devices/devices.go
diff options
context:
space:
mode:
Diffstat (limited to 'devices/devices.go')
-rw-r--r--devices/devices.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/devices/devices.go b/devices/devices.go
new file mode 100644
index 0000000..91a8815
--- /dev/null
+++ b/devices/devices.go
@@ -0,0 +1,26 @@
+package devices
+
+import "log"
+
+var shutdownFuncs []func() error
+
+// RegisterShutdown stores a function to be called by gotop on exit, allowing
+// extensions to properly release resources. Extensions should register a
+// shutdown function IFF the extension is using resources that need to be
+// released. The returned error will be logged, but no other action will be
+// taken.
+func RegisterShutdown(f func() error) {
+ shutdownFuncs = append(shutdownFuncs, f)
+}
+
+// Shutdown will be called by the `main()` function if gotop is exited
+// cleanly. It will call all of the registered shutdown functions of devices,
+// logging all errors but otherwise not responding to them.
+func Shutdown() {
+ for _, f := range shutdownFuncs {
+ err := f()
+ if err != nil {
+ log.Print(err)
+ }
+ }
+}