libust: Fix multiple fd close during fork v2
[ust.git] / libust / tracectl.c
index 25f84ccd0f033f2ec4ec38f40a589dae6cb05bc2..f720244530c9f60b77f5978875f712a5ea69658a 100644 (file)
@@ -100,11 +100,11 @@ static void print_markers(FILE *fp)
 
        while (iter.marker) {
                fprintf(fp, "marker: %s/%s %d \"%s\" %p\n",
-                       iter.marker->channel,
-                       iter.marker->name,
-                       (int)imv_read(iter.marker->state),
-                       iter.marker->format,
-                       iter.marker->location);
+                       (*iter.marker)->channel,
+                       (*iter.marker)->name,
+                       (int)imv_read((*iter.marker)->state),
+                       (*iter.marker)->format,
+                       (*iter.marker)->location);
                marker_iter_next(&iter);
        }
        unlock_markers();
@@ -119,7 +119,7 @@ static void print_trace_events(FILE *fp)
        trace_event_iter_start(&iter);
 
        while (iter.trace_event) {
-               fprintf(fp, "trace_event: %s\n", iter.trace_event->name);
+               fprintf(fp, "trace_event: %s\n", (*iter.trace_event)->name);
                trace_event_iter_next(&iter);
        }
        unlock_trace_events();
@@ -1314,8 +1314,8 @@ static void __attribute__((constructor)) init()
 
                DBG("now iterating on markers already registered");
                while (iter.marker) {
-                       DBG("now iterating on marker %s", iter.marker->name);
-                       auto_probe_connect(iter.marker);
+                       DBG("now iterating on marker %s", (*iter.marker)->name);
+                       auto_probe_connect(*iter.marker);
                        marker_iter_next(&iter);
                }
        }
@@ -1569,6 +1569,7 @@ static void ust_fork(void)
 {
        struct ust_buffer *buf, *buf_tmp;
        struct ustcomm_sock *sock, *sock_tmp;
+       struct ust_trace *trace, *trace_tmp;
        int result;
 
        /* FIXME: technically, the locks could have been taken before the fork */
@@ -1580,8 +1581,14 @@ static void ust_fork(void)
        /* break lock if necessary */
        ltt_unlock_traces();
 
-       ltt_trace_stop("auto");
-       ltt_trace_destroy("auto", 1);
+       /*
+        * FIXME: This could be prettier, we loop over the list twice and
+        * following good locking practice should lock around the loop
+        */
+       cds_list_for_each_entry_safe(trace, trace_tmp, &ltt_traces.head, list) {
+               ltt_trace_stop(trace->trace_name);
+       }
+
        /* Delete all active connections, but leave them in the epoll set */
        cds_list_for_each_entry_safe(sock, sock_tmp, &ust_socks, list) {
                ustcomm_del_sock(sock, 1);
@@ -1590,17 +1597,17 @@ static void ust_fork(void)
        /* Delete all blocked consumers */
        cds_list_for_each_entry_safe(buf, buf_tmp, &open_buffers_list,
                                 open_buffers_list) {
-               result = close(buf->data_ready_fd_read);
-               if (result == -1) {
-                       PERROR("close");
-               }
-               result = close(buf->data_ready_fd_write);
-               if (result == -1) {
-                       PERROR("close");
-               }
                cds_list_del(&buf->open_buffers_list);
        }
 
+       /*
+        * FIXME: This could be prettier, we loop over the list twice and
+        * following good locking practice should lock around the loop
+        */
+       cds_list_for_each_entry_safe(trace, trace_tmp, &ltt_traces.head, list) {
+               ltt_trace_destroy(trace->trace_name, 1);
+       }
+
        /* Clean up the listener socket and epoll, keeping the scoket file */
        ustcomm_del_named_sock(listen_sock, 1);
        close(epoll_fd);
This page took 0.0266960000000001 seconds and 4 git commands to generate.