#include <stdio.h>
#include <unistd.h>
#include <string.h>
+#include <strings.h>
+#include <signal.h>
#include <errno.h>
#include <assert.h>
#include <sysexits.h>
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;
}
}
}
- /* 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;