[PATCH] Fix the stop trace logic to not attempt to stop it twice
authorJens Axboe <axboe@linux>
Fri, 2 Sep 2005 11:47:23 +0000 (13:47 +0200)
committerJens Axboe <axboe@linux>
Fri, 2 Sep 2005 11:47:23 +0000 (13:47 +0200)
blktrace.c

index 78cdc8568e7c67f77865758d4f53fcc94158ca24..c568d0f72a1c0e81a51d511b5ee5fc844493d7f2 100644 (file)
@@ -173,10 +173,13 @@ static int start_trace(char *dev)
 
 static void stop_trace(void)
 {
-       if (ioctl(devfd, BLKSTOPTRACE) < 0)
-               perror("BLKSTOPTRACE");
+       if (trace_started) {
+               if (ioctl(devfd, BLKSTOPTRACE) < 0)
+                       perror("BLKSTOPTRACE");
 
-       close(devfd);
+               close(devfd);
+               trace_started = 0;
+       }
 }
 
 static void extract_data(struct thread_information *tip,
@@ -352,12 +355,6 @@ void handle_sigint(int sig)
        done = 1;
 }
 
-void stop_trace_on_exit(void)
-{
-       if (trace_started)
-               stop_trace();
-}
-
 int main(int argc, char *argv[])
 {
        static char default_relay_path[] = "/relay";
@@ -447,7 +444,7 @@ int main(int argc, char *argv[])
        signal(SIGHUP, handle_sigint);
        signal(SIGTERM, handle_sigint);
 
-       atexit(stop_trace_on_exit);
+       atexit(stop_trace);
 
        while (!is_done())
                sleep(1);