Move signal handling into common utils code.

This commit is contained in:
Milan Broz
2012-12-11 15:40:42 +01:00
parent d742e01a32
commit 710aad20d3
3 changed files with 34 additions and 29 deletions

View 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)
{