--- /dev/null
+#ifndef __SIGHANDLER_H_
+#define __SIGHANDLER_H_
+
+#include<signal.h>
+#include<stdio.h>
+#include<stdlib.h>
+
+#include<log.h>
+
+#define SIGHANDLER_MESSAGE_GRACEFUL_SHUTDOWN "shutdown requested; exiting...\n"
+#define SIGHANDLER_MESSAGE_SHUTDOWN_COMPLETE "shutdown complete.\n"
+
+int signal_handler();
+
+#endif
{0,0,0,0}
};
-static int signal_handler();
-
int init(int argc, char **argv) {
int c;
return 1;
}
-
-static void handle_interrupt() {
- /*
- * call exit explicitly will call functions registered
- * with atexit and do appropriate cleanup.
- */
- exit(EXIT_FAILURE);
-}
-
-static int signal_handler() {
- struct sigaction action;
-
- action.sa_handler = &handle_interrupt;
- action.sa_flags = SA_RESETHAND;
- if(sigaction(SIGINT,&action,NULL)!=0) {
- perror("sigaction");
- return -1;
- }
-
- return 1;
-}
--- /dev/null
+#include<sighandler.h>
+
+static void handle_interrupt();
+static void shutdown_success();
+
+static void handle_interrupt() {
+ log_info(SIGHANDLER_MESSAGE_GRACEFUL_SHUTDOWN);
+ /*
+ * call exit explicitly will call functions registered
+ * with atexit and do appropriate cleanup.
+ */
+ exit(EXIT_SUCCESS);
+}
+
+static void shutdown_success() {
+ log_info(SIGHANDLER_MESSAGE_SHUTDOWN_COMPLETE);
+}
+
+int signal_handler() {
+ struct sigaction action;
+
+ action.sa_handler = &handle_interrupt;
+ action.sa_flags = SA_RESETHAND;
+ sigemptyset(&action.sa_mask);
+
+ if(sigaction(SIGINT,&action,NULL)!=0) {
+ perror("sigaction");
+ return -1;
+ }
+
+ if(0!=atexit(&shutdown_success)) {
+ perror("atexit");
+ return -1;
+ }
+
+ return 1;
+}