Setup the cancel signal handler.

This commit is contained in:
Jef Driesen 2015-12-28 08:21:34 +01:00
parent f0e5edc50b
commit 28d8759294
2 changed files with 26 additions and 0 deletions

View File

@ -27,6 +27,7 @@
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
@ -50,6 +51,8 @@ static const dctool_command_t *g_commands[] = {
NULL
};
static volatile sig_atomic_t g_cancel = 0;
const dctool_command_t *
dctool_command_find (const char *name)
{
@ -67,6 +70,23 @@ dctool_command_find (const char *name)
return g_commands[i];
}
int
dctool_cancel_cb (void *userdata)
{
return g_cancel;
}
static void
sighandler (int signum)
{
#ifndef _WIN32
// Restore the default signal handler.
signal (signum, SIG_DFL);
#endif
g_cancel = 1;
}
static void
logfunc (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *msg, void *userdata)
{
@ -182,6 +202,9 @@ main (int argc, char *argv[])
return EXIT_FAILURE;
}
// Setup the cancel signal handler.
signal (SIGINT, sighandler);
// Initialize the logfile.
message_set_logfile (logfile);

View File

@ -42,6 +42,9 @@ typedef struct dctool_command_t {
const char *usage;
} dctool_command_t;
int
dctool_cancel_cb (void *userdata);
#ifdef __cplusplus
}
#endif /* __cplusplus */