From: Jens Axboe Date: Thu, 1 Sep 2005 14:43:36 +0000 (+0200) Subject: [PATCH] Always make sure we stop the trace properly X-Git-Tag: blktrace-0.99~223 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=830fd65c783b5548d1ef736b1a2c0640a281a67d;p=blktrace.git [PATCH] Always make sure we stop the trace properly --- diff --git a/CHANGELOG b/CHANGELOG index caa066c..4680ae2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ - Added seconds.nanosecond output format for time - Converted to comply with time stamps comparable on each CPU - Fix oops on tracing dm/md and other stacked devices + - Always make sure we stop the trace properly 20050830: - Added argument parsing - Added action mask set up diff --git a/blktrace.c b/blktrace.c index b2e753a..6888d80 100644 --- a/blktrace.c +++ b/blktrace.c @@ -111,6 +111,7 @@ static struct thread_information *thread_information; static char *buts_name_p; static char *dev; static int act_mask = ~0; +static int trace_started; inline int compare_mask_map(struct mask_map *mmp, char *string) { @@ -155,6 +156,7 @@ static int start_trace(char *dev) return 1; } + trace_started = 1; buts_name_p = strdup(buts.name); return 0; } @@ -338,6 +340,12 @@ void handle_sigint(int sig) done = 1; } +void stop_trace_on_exit(void) +{ + if (trace_started) + stop_trace(); +} + int main(int argc, char *argv[]) { struct stat st; @@ -400,7 +408,6 @@ int main(int argc, char *argv[]) if (start_trace(dev)) { fprintf(stderr, "Failed to start trace on %s\n", dev); - stop_trace(); return 3; } @@ -419,6 +426,8 @@ int main(int argc, char *argv[]) signal(SIGHUP, handle_sigint); signal(SIGTERM, handle_sigint); + atexit(stop_trace_on_exit); + while (!is_done()) sleep(1);