diff options
author | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2011-12-12 18:08:27 +0100 |
---|---|---|
committer | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2011-12-12 18:08:27 +0100 |
commit | 4be7a59b5a5253e90a299b56eb188c8b970c07b5 (patch) | |
tree | 880cbf5cc18a486d77da1905f0580574b8e3438b /cli.c | |
parent | 6169da95761fbf0851033d106f0506b9632ce0c9 (diff) | |
download | pcitool-4be7a59b5a5253e90a299b56eb188c8b970c07b5.tar.gz pcitool-4be7a59b5a5253e90a299b56eb188c8b970c07b5.tar.bz2 pcitool-4be7a59b5a5253e90a299b56eb188c8b970c07b5.tar.xz pcitool-4be7a59b5a5253e90a299b56eb188c8b970c07b5.zip |
Handle SIGINT signal in pcitool
Diffstat (limited to 'cli.c')
-rw-r--r-- | cli.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -18,6 +18,7 @@ #include <sys/types.h> #include <dirent.h> #include <pthread.h> +#include <signal.h> #include <getopt.h> @@ -284,6 +285,14 @@ argv[0]); exit(0); } +static int StopFlag = 0; + +static void signal_exit_handler(int signo) { + if (++StopFlag > 2) + exit(-1); +} + + void Error(const char *format, ...) { va_list ap; @@ -1314,6 +1323,11 @@ void *Monitor(void *user) { } while (ctx->run_flag) { + if (StopFlag) { + pcilib_stop(ctx->handle, PCILIB_EVENT_FLAG_STOP_ONLY); + break; + } + if (timeout) { if (pcilib_calc_time_to_deadline(&deadline) == 0) { memcpy(&deadline, (struct timeval*)&ctx->last_frame, sizeof(struct timeval)); @@ -2501,6 +2515,8 @@ int main(int argc, char **argv) { } } + signal(SIGINT, signal_exit_handler); + if (output) { ofile = fopen(output, "a+"); if (!ofile) { |