mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-15 04:40:05 +01:00
Properly cleanup on interrupt in api-test.
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <libdevmapper.h>
|
#include <libdevmapper.h>
|
||||||
@@ -86,6 +87,8 @@ static int _debug = 0;
|
|||||||
static int _verbose = 1;
|
static int _verbose = 1;
|
||||||
static int _fips_mode = 0;
|
static int _fips_mode = 0;
|
||||||
|
|
||||||
|
static int _quit = 0;
|
||||||
|
|
||||||
static char global_log[4096];
|
static char global_log[4096];
|
||||||
static int global_lines = 0;
|
static int global_lines = 0;
|
||||||
|
|
||||||
@@ -520,6 +523,12 @@ static void xlog(const char *msg, const char *tst, const char *func, int line, c
|
|||||||
else
|
else
|
||||||
printf(" [%s,%s:%d] %s\n", msg, func, line, tst);
|
printf(" [%s,%s:%d] %s\n", msg, func, line, tst);
|
||||||
}
|
}
|
||||||
|
if (_quit) {
|
||||||
|
if (_verbose)
|
||||||
|
printf("Interrupted by a signal.\n");
|
||||||
|
_cleanup();
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* crypt_device context must be "cd" to parse error properly here */
|
/* crypt_device context must be "cd" to parse error properly here */
|
||||||
@@ -1849,8 +1858,14 @@ static void NonFIPSAlg(void)
|
|||||||
crypt_free(cd);
|
crypt_free(cd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void int_handler(int sig __attribute__((__unused__)))
|
||||||
|
{
|
||||||
|
_quit++;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
struct sigaction sa = { .sa_handler = int_handler };
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (getuid() != 0) {
|
if (getuid() != 0) {
|
||||||
@@ -1865,6 +1880,10 @@ int main(int argc, char *argv[])
|
|||||||
_debug = _verbose = 1;
|
_debug = _verbose = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Handle interrupt properly */
|
||||||
|
sigaction(SIGINT, &sa, NULL);
|
||||||
|
sigaction(SIGTERM, &sa, NULL);
|
||||||
|
|
||||||
_cleanup();
|
_cleanup();
|
||||||
if (_setup())
|
if (_setup())
|
||||||
goto out;
|
goto out;
|
||||||
|
|||||||
Reference in New Issue
Block a user