[PATCH] Always make sure we stop the trace properly
authorJens Axboe <axboe@nelson>
Thu, 1 Sep 2005 14:43:36 +0000 (16:43 +0200)
committerJens Axboe <axboe@nelson>
Thu, 1 Sep 2005 14:43:36 +0000 (16:43 +0200)
CHANGELOG
blktrace.c

index caa066c456c10b51676f12ed9985349710a9541f..4680ae25f0fac95de74938c7f9e04a4c8f88da4c 100644 (file)
--- 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
index b2e753abf5dc567031c0b254c0fa65f886e07d09..6888d80b00b7a1f3129c63c74949746bad5443ac 100644 (file)
@@ -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);