mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-15 04:40:05 +01:00
Move signal handling into common utils code.
This commit is contained in:
@@ -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);
|
void dbg_version_and_cmd(int argc, const char **argv);
|
||||||
int translate_errno(int r);
|
int translate_errno(int r);
|
||||||
|
|
||||||
|
extern volatile int quit;
|
||||||
|
void set_int_block(int block);
|
||||||
|
void set_int_handler(void);
|
||||||
|
|
||||||
/* Log */
|
/* Log */
|
||||||
#define log_dbg(x...) clogger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
|
#define log_dbg(x...) clogger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
|
||||||
#define log_std(x...) clogger(NULL, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
|
#define log_std(x...) clogger(NULL, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#define PACKAGE_REENC "crypt_reencrypt"
|
#define PACKAGE_REENC "crypt_reencrypt"
|
||||||
|
|
||||||
@@ -56,8 +55,6 @@ static uint64_t opt_device_size = 0;
|
|||||||
|
|
||||||
static const char **action_argv;
|
static const char **action_argv;
|
||||||
|
|
||||||
static volatile int quit = 0;
|
|
||||||
|
|
||||||
#define MAX_SLOT 8
|
#define MAX_SLOT 8
|
||||||
struct reenc_ctx {
|
struct reenc_ctx {
|
||||||
char *device;
|
char *device;
|
||||||
@@ -107,32 +104,6 @@ static void _quiet_log(int level, const char *msg, void *usrptr)
|
|||||||
tool_log(level, msg, 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. */
|
/* The difference in seconds between two times in "timeval" format. */
|
||||||
static double time_diff(struct timeval start, struct timeval end)
|
static double time_diff(struct timeval start, struct timeval end)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,11 +20,41 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cryptsetup.h"
|
#include "cryptsetup.h"
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
int opt_verbose = 0;
|
int opt_verbose = 0;
|
||||||
int opt_debug = 0;
|
int opt_debug = 0;
|
||||||
int opt_batch_mode = 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)))
|
__attribute__((format(printf, 5, 6)))
|
||||||
void clogger(struct crypt_device *cd, int level, const char *file, int line,
|
void clogger(struct crypt_device *cd, int level, const char *file, int line,
|
||||||
const char *format, ...)
|
const char *format, ...)
|
||||||
|
|||||||
Reference in New Issue
Block a user