Protect the abort_flag on reset and always close on rotate
authorJulien Desfossez <jdesfossez@efficios.com>
Fri, 15 Nov 2013 01:49:57 +0000 (20:49 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Fri, 15 Nov 2013 15:16:31 +0000 (10:16 -0500)
Fixes CID 1128897 and a case where the read_fd might not be closed when
the abort flag is set.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-relayd/live.c

index 480c459ce6a49724f54d1b6ef71c0b5a6d458a1b..a2fd09e32812fc322ac9299fa16f558ad39637ad 100644 (file)
@@ -802,26 +802,22 @@ int rotate_viewer_stream(struct relay_viewer_stream *viewer_stream,
        }
        viewer_stream->tracefile_count_current = tracefile_id;
 
-       if (viewer_stream->abort_flag == 0) {
-               if (viewer_stream->index_read_fd > 0) {
-                       ret = close(viewer_stream->index_read_fd);
-                       if (ret < 0) {
-                               PERROR("close index file %d",
-                                               viewer_stream->index_read_fd);
-                       }
-                       viewer_stream->index_read_fd = -1;
-               }
-               if (viewer_stream->read_fd > 0) {
-                       ret = close(viewer_stream->read_fd);
-                       if (ret < 0) {
-                               PERROR("close tracefile %d",
-                                               viewer_stream->read_fd);
-                       }
-                       viewer_stream->read_fd = -1;
-               }
-       } else {
-               viewer_stream->abort_flag = 0;
+       ret = close(viewer_stream->index_read_fd);
+       if (ret < 0) {
+               PERROR("close index file %d",
+                               viewer_stream->index_read_fd);
+       }
+       viewer_stream->index_read_fd = -1;
+       ret = close(viewer_stream->read_fd);
+       if (ret < 0) {
+               PERROR("close tracefile %d",
+                               viewer_stream->read_fd);
        }
+       viewer_stream->read_fd = -1;
+
+       pthread_mutex_lock(&viewer_stream->overwrite_lock);
+       viewer_stream->abort_flag = 0;
+       pthread_mutex_unlock(&viewer_stream->overwrite_lock);
 
        viewer_stream->index_read_fd = -1;
        viewer_stream->read_fd = -1;
This page took 0.027385 seconds and 5 git commands to generate.