diff options
author | Keir Fraser <keir@xensource.com> | 2007-10-02 13:19:25 +0100 |
---|---|---|
committer | Keir Fraser <keir@xensource.com> | 2007-10-02 13:19:25 +0100 |
commit | 9d6b92ef1a42c3ae7763827eb42a18c25c2bf3eb (patch) | |
tree | d68529180446a466e24ef40cb7be678c130cc6d6 /tools/xenstat | |
parent | b0746b2995b8fe790a6272fc0beeb335695f803e (diff) | |
download | xen-9d6b92ef1a42c3ae7763827eb42a18c25c2bf3eb.tar.gz xen-9d6b92ef1a42c3ae7763827eb42a18c25c2bf3eb.tar.bz2 xen-9d6b92ef1a42c3ae7763827eb42a18c25c2bf3eb.zip |
xentop: Flush batch output on SIGTERM or SIGINT.
Signed-off-by: INAKOSHI Hiroya <inakoshi.hiroya@jp.fujitsu.com>
Diffstat (limited to 'tools/xenstat')
-rw-r--r-- | tools/xenstat/xentop/xentop.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/tools/xenstat/xentop/xentop.c b/tools/xenstat/xentop/xentop.c index 755e322f56..bc703ffae2 100644 --- a/tools/xenstat/xentop/xentop.c +++ b/tools/xenstat/xentop/xentop.c @@ -28,6 +28,7 @@ #include <sys/time.h> #include <time.h> #include <unistd.h> +#include <signal.h> #if defined(__linux__) #include <linux/kdev_t.h> #endif @@ -1011,6 +1012,13 @@ static void top(void) free(domains); } +static int signal_exit; + +void signal_exit_handler(int sig) +{ + signal_exit = 1; +} + int main(int argc, char **argv) { int opt, optind = 0; @@ -1102,14 +1110,22 @@ int main(int argc, char **argv) ch = getch(); } while (handle_key(ch)); } else { - do { - gettimeofday(&curtime, NULL); - top(); - oldtime = curtime; - if ((!loop) && !(--iterations)) - break; - sleep(delay); - } while (1); + struct sigaction sa = { + .sa_handler = signal_exit_handler, + .sa_flags = 0 + }; + sigemptyset(&sa.sa_mask); + sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); + + do { + gettimeofday(&curtime, NULL); + top(); + oldtime = curtime; + if ((!loop) && !(--iterations)) + break; + sleep(delay); + } while (!signal_exit); } /* Cleanup occurs in cleanup(), so no work to do here. */ |