File: shutdown.go

package info (click to toggle)
golang-collectd 0.5.0%2Bgit20240104.26404de-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 468 kB
  • sloc: ansic: 324; sh: 7; makefile: 3
file content (65 lines) | stat: -rw-r--r-- 1,492 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package fake

// #cgo CPPFLAGS: -DHAVE_CONFIG_H
// #cgo LDFLAGS: -ldl
// #include <stdlib.h>
// #include "plugin.h"
//
// typedef struct {
//   const char *name;
//   plugin_shutdown_cb callback;
// } shutdown_callback_t;
// static shutdown_callback_t *shutdown_callbacks = NULL;
// static size_t shutdown_callbacks_num = 0;
//
// int plugin_register_shutdown(const char *name, plugin_shutdown_cb callback) {
//   shutdown_callback_t *ptr =
//       realloc(shutdown_callbacks,
//               (shutdown_callbacks_num + 1) * sizeof(*shutdown_callbacks));
//   if (ptr == NULL) {
//     return ENOMEM;
//   }
//   shutdown_callbacks = ptr;
//   shutdown_callbacks[shutdown_callbacks_num] = (shutdown_callback_t){
//       .name = name,
//       .callback = callback,
//   };
//   shutdown_callbacks_num++;
//
//   return 0;
// }
//
// int plugin_shutdown_all(void) {
//   int ret = 0;
//   for (size_t i = 0; i < shutdown_callbacks_num; i++) {
//     int err = shutdown_callbacks[i].callback();
//     if (err != 0) {
//       ret = err;
//     }
//   }
//   return ret;
// }
//
// void reset_shutdown(void) {
//   free(shutdown_callbacks);
//   shutdown_callbacks = NULL;
//   shutdown_callbacks_num = 0;
// }
import "C"

import (
	"fmt"
)

// ShutdownAll calls all registered shutdown callbacks.
func ShutdownAll() error {
	status, err := C.plugin_shutdown_all()
	if err != nil {
		return err
	}
	if status != 0 {
		return fmt.Errorf("plugin_shutdown_all() = %d", status)
	}

	return nil
}