Move signal handling into common utils code.
authorMilan Broz <gmazyland@gmail.com>
Tue, 11 Dec 2012 14:40:42 +0000 (15:40 +0100)
committerMilan Broz <gmazyland@gmail.com>
Tue, 11 Dec 2012 14:40:42 +0000 (15:40 +0100)
src/cryptsetup.h
src/cryptsetup_reencrypt.c
src/utils_tools.c

index 2c82d76..3bc288e 100644 (file)
@@ -70,6 +70,10 @@ void usage(poptContext popt_context, int exitcode, const char *error, const char
 void dbg_version_and_cmd(int argc, const char **argv);
 int translate_errno(int r);
 
+extern volatile int quit;
+void set_int_block(int block);
+void set_int_handler(void);
+
 /* Log */
 #define log_dbg(x...) clogger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
 #define log_std(x...) clogger(NULL, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
index 2dc2a8e..0e0e91f 100644 (file)
@@ -23,7 +23,6 @@
 #include <sys/time.h>
 #include <linux/fs.h>
 #include <arpa/inet.h>
-#include <signal.h>
 
 #define PACKAGE_REENC "crypt_reencrypt"
 
@@ -56,8 +55,6 @@ static uint64_t opt_device_size = 0;
 
 static const char **action_argv;
 
-static volatile int quit = 0;
-
 #define MAX_SLOT 8
 struct reenc_ctx {
        char *device;
@@ -107,32 +104,6 @@ static void _quiet_log(int level, const char *msg, void *usrptr)
        tool_log(level, msg, usrptr);
 }
 
-static void int_handler(int sig __attribute__((__unused__)))
-{
-       quit++;
-}
-
-static void set_int_block(int block)
-{
-       sigset_t signals_open;
-
-       sigemptyset(&signals_open);
-       sigaddset(&signals_open, SIGINT);
-       sigaddset(&signals_open, SIGTERM);
-       sigprocmask(block ? SIG_SETMASK : SIG_UNBLOCK, &signals_open, NULL);
-}
-
-static void set_int_handler(void)
-{
-       struct sigaction sigaction_open;
-
-       memset(&sigaction_open, 0, sizeof(struct sigaction));
-       sigaction_open.sa_handler = int_handler;
-       sigaction(SIGINT, &sigaction_open, 0);
-       sigaction(SIGTERM, &sigaction_open, 0);
-       set_int_block(0);
-}
-
 /* The difference in seconds between two times in "timeval" format. */
 static double time_diff(struct timeval start, struct timeval end)
 {
index 01ded12..035e3fc 100644 (file)
  */
 
 #include "cryptsetup.h"
+#include <signal.h>
 
 int opt_verbose = 0;
 int opt_debug = 0;
 int opt_batch_mode = 0;
 
+/* interrupt handling */
+volatile int quit = 0;
+
+static void int_handler(int sig __attribute__((__unused__)))
+{
+       quit++;
+}
+
+void set_int_block(int block)
+{
+       sigset_t signals_open;
+
+       sigemptyset(&signals_open);
+       sigaddset(&signals_open, SIGINT);
+       sigaddset(&signals_open, SIGTERM);
+       sigprocmask(block ? SIG_SETMASK : SIG_UNBLOCK, &signals_open, NULL);
+}
+
+void set_int_handler(void)
+{
+       struct sigaction sigaction_open;
+
+       memset(&sigaction_open, 0, sizeof(struct sigaction));
+       sigaction_open.sa_handler = int_handler;
+       sigaction(SIGINT, &sigaction_open, 0);
+       sigaction(SIGTERM, &sigaction_open, 0);
+       set_int_block(0);
+}
+
 __attribute__((format(printf, 5, 6)))
 void clogger(struct crypt_device *cd, int level, const char *file, int line,
             const char *format, ...)