From 286b0e08bf52ee3eda3d8f73366a786337a7a4bd Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Wed, 18 Apr 2012 14:25:27 -0700 Subject: [PATCH] minor portability enhancements missed some headers, use sigaction() instead of signal() --- as-dcpu16.c | 1 + vm-dcpu16.c | 19 +++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/as-dcpu16.c b/as-dcpu16.c index 063741d..820b837 100644 --- a/as-dcpu16.c +++ b/as-dcpu16.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/vm-dcpu16.c b/vm-dcpu16.c index d60c340..537452a 100644 --- a/vm-dcpu16.c +++ b/vm-dcpu16.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include #include #include @@ -326,14 +328,17 @@ COMMAND_HELP(step) { COMMAND_IMPL(run) { - sig_t osig; + struct sigaction act; (void)arg_count, (void)arg_vector; running_ = 1; - /* install our new interrupt signal handler */ - if ( (osig = signal(SIGINT, sigint_handler_)) == SIG_ERR ) { - fprintf(stderr, "%s():%s\n", "signal", strerror(errno)); + memset(&act, 0, sizeof act); + act.sa_handler = sigint_handler_; + act.sa_flags = SA_RESETHAND; + + if (sigaction(SIGINT, &act, NULL)) { + fprintf(stderr, "%s():%s\n", "sigaction", strerror(errno)); return -1; } @@ -347,12 +352,6 @@ COMMAND_IMPL(run) { } } - /* restore the old interrupt signal handler */ - if (signal(SIGINT, osig) == SIG_ERR) { - fprintf(stderr, "%s():%s\n", "signal", strerror(errno)); - return -1; - } - printf("interrupted...\n"); return 0; -- 2.43.2