+ * TODO: Eventually, this signal handler setup should be done at the
+ * plugin manager level, rather than within this plugin. Beware, we are
+ * not cleaning up the signal handler after plugin execution.
+ */
+static
+int setup_sighandler(void)
+{
+ struct sigaction sa;
+ sigset_t sigset;
+ int ret;
+
+ if ((ret = sigemptyset(&sigset)) < 0) {
+ perror("sigemptyset");
+ return ret;
+ }
+ sa.sa_handler = sighandler;
+ sa.sa_mask = sigset;
+ sa.sa_flags = 0;
+ if ((ret = sigaction(SIGTERM, &sa, NULL)) < 0) {
+ perror("sigaction");
+ return ret;
+ }
+ if ((ret = sigaction(SIGINT, &sa, NULL)) < 0) {
+ perror("sigaction");
+ return ret;
+ }
+ return 0;
+}
+
+/*
+ * hostname parameter needs to hold MAXNAMLEN chars.