Commit 8598d4d0 authored by Filippos Giannakos's avatar Filippos Giannakos

xseg-tool: Handle keyboard interrupt

parent 3caca46d
...@@ -25,6 +25,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -25,6 +25,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <sys/types.h> #include <sys/types.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <time.h>
#include <xseg/xhash.h> #include <xseg/xhash.h>
#include <xseg/xobj.h> #include <xseg/xobj.h>
...@@ -97,6 +100,42 @@ uint64_t reqs; ...@@ -97,6 +100,42 @@ uint64_t reqs;
xport sport = NoPort; xport sport = NoPort;
void *sd; void *sd;
time_t previous_intr = 0;
void handler(int signal)
{
int r;
time_t t = time(NULL);
if (previous_intr && t - previous_intr < 2) {
exit(1);
}
char *msg = "You should not interrupt this program, as this may cause "
"irreversible segment corruption\n."
"If you really want to terminate this program, hit "
"Ctrl-C again withing 2 seconds\n";
write(2, msg, strlen(msg));
previous_intr = t;
}
int install_signal_handler()
{
int r;
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = handler;
r = sigaction(SIGINT, &sa, NULL);
if (r < 0)
return -errno;
return 0;
}
static void init_local_signal() static void init_local_signal()
{ {
...@@ -1986,6 +2025,8 @@ int main(int argc, char **argv) ...@@ -1986,6 +2025,8 @@ int main(int argc, char **argv)
return -1; return -1;
} }
install_signal_handler();
for (i = 2; i < argc; i++) { for (i = 2; i < argc; i++) {
if (!strcmp(argv[i], "create")) { if (!strcmp(argv[i], "create")) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment