Setup the cancel signal handler.
This commit is contained in:
parent
f0e5edc50b
commit
28d8759294
@ -27,6 +27,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <signal.h>
|
||||||
#ifdef HAVE_GETOPT_H
|
#ifdef HAVE_GETOPT_H
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#endif
|
#endif
|
||||||
@ -50,6 +51,8 @@ static const dctool_command_t *g_commands[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static volatile sig_atomic_t g_cancel = 0;
|
||||||
|
|
||||||
const dctool_command_t *
|
const dctool_command_t *
|
||||||
dctool_command_find (const char *name)
|
dctool_command_find (const char *name)
|
||||||
{
|
{
|
||||||
@ -67,6 +70,23 @@ dctool_command_find (const char *name)
|
|||||||
return g_commands[i];
|
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
|
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)
|
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;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup the cancel signal handler.
|
||||||
|
signal (SIGINT, sighandler);
|
||||||
|
|
||||||
// Initialize the logfile.
|
// Initialize the logfile.
|
||||||
message_set_logfile (logfile);
|
message_set_logfile (logfile);
|
||||||
|
|
||||||
|
|||||||
@ -42,6 +42,9 @@ typedef struct dctool_command_t {
|
|||||||
const char *usage;
|
const char *usage;
|
||||||
} dctool_command_t;
|
} dctool_command_t;
|
||||||
|
|
||||||
|
int
|
||||||
|
dctool_cancel_cb (void *userdata);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user