Fix: syscall event rule: emission sites not compared in is_equal
[lttng-tools.git] / src / bin / lttng-sessiond / save.cpp
index bef38e61934b554f1564788411fb8346580cdbb0..b4ca4c080fdd8f119a98a2fe31682be6d9cec42e 100644 (file)
 #include <common/defaults.hpp>
 #include <common/error.hpp>
 #include <common/runas.hpp>
+#include <common/urcu.hpp>
 #include <common/utils.hpp>
 
 #include <lttng/save-internal.hpp>
 
+#include <fcntl.h>
 #include <inttypes.h>
 #include <string.h>
 #include <unistd.h>
@@ -101,7 +103,7 @@ static int save_kernel_channel_attributes(struct config_writer *writer,
        }
 
        if (attr->extended.ptr) {
-               struct lttng_channel_extended *ext = NULL;
+               struct lttng_channel_extended *ext = nullptr;
 
                ext = (struct lttng_channel_extended *) attr->extended.ptr;
                ret = config_writer_write_element_unsigned_int(
@@ -129,7 +131,7 @@ static int save_ust_channel_attributes(struct config_writer *writer,
                                       struct lttng_ust_abi_channel_attr *attr)
 {
        int ret;
-       struct ltt_ust_channel *channel = NULL;
+       struct ltt_ust_channel *channel = nullptr;
 
        ret = config_writer_write_element_string(writer,
                                                 config_element_overwrite_mode,
@@ -233,7 +235,7 @@ get_kernel_instrumentation_string(enum lttng_kernel_abi_instrumentation instrume
                instrumentation_string = config_event_type_syscall;
                break;
        default:
-               instrumentation_string = NULL;
+               instrumentation_string = nullptr;
        }
 
        return instrumentation_string;
@@ -353,7 +355,7 @@ static const char *get_kernel_context_type_string(enum lttng_kernel_abi_context_
                context_type_string = config_event_context_vsgid;
                break;
        default:
-               context_type_string = NULL;
+               context_type_string = nullptr;
        }
 
        return context_type_string;
@@ -430,7 +432,7 @@ static const char *get_ust_context_type_string(enum lttng_ust_abi_context_type c
                 * are stored as a node of type event_perf_context_type.
                 */
        default:
-               context_type_string = NULL;
+               context_type_string = nullptr;
                break;
        }
 
@@ -452,7 +454,7 @@ static const char *get_buffer_type_string(enum lttng_buffer_type buffer_type)
                buffer_type_string = config_buffer_type_global;
                break;
        default:
-               buffer_type_string = NULL;
+               buffer_type_string = nullptr;
        }
 
        return buffer_type_string;
@@ -473,7 +475,7 @@ static const char *get_loglevel_type_string(enum lttng_ust_abi_loglevel_type log
                loglevel_type_string = config_loglevel_type_single;
                break;
        default:
-               loglevel_type_string = NULL;
+               loglevel_type_string = nullptr;
        }
 
        return loglevel_type_string;
@@ -522,15 +524,14 @@ static int save_kernel_kprobe_event(struct config_writer *writer, struct ltt_ker
                 */
                addr = event->event->u.kprobe.addr;
                offset = event->event->u.kprobe.offset;
-               symbol_name = addr ? NULL : event->event->u.kprobe.symbol_name;
+               symbol_name = addr ? nullptr : event->event->u.kprobe.symbol_name;
                break;
        case LTTNG_KERNEL_ABI_KRETPROBE:
                addr = event->event->u.kretprobe.addr;
                offset = event->event->u.kretprobe.offset;
-               symbol_name = addr ? NULL : event->event->u.kretprobe.symbol_name;
+               symbol_name = addr ? nullptr : event->event->u.kretprobe.symbol_name;
                break;
        default:
-               LTTNG_ASSERT(1);
                ERR("Unsupported kernel instrumentation type.");
                ret = LTTNG_ERR_INVALID;
                goto end;
@@ -1106,21 +1107,22 @@ static int save_ust_events(struct config_writer *writer, struct lttng_ht *events
                goto end;
        }
 
-       rcu_read_lock();
-       cds_lfht_for_each_entry (events->ht, &iter.iter, node, node) {
-               event = lttng::utils::container_of(node, &ltt_ust_event::node);
+       {
+               lttng::urcu::read_lock_guard read_lock;
 
-               if (event->internal) {
-                       /* Internal events must not be exposed to clients */
-                       continue;
-               }
-               ret = save_ust_event(writer, event);
-               if (ret != LTTNG_OK) {
-                       rcu_read_unlock();
-                       goto end;
+               cds_lfht_for_each_entry (events->ht, &iter.iter, node, node) {
+                       event = lttng::utils::container_of(node, &ltt_ust_event::node);
+
+                       if (event->internal) {
+                               /* Internal events must not be exposed to clients */
+                               continue;
+                       }
+                       ret = save_ust_event(writer, event);
+                       if (ret != LTTNG_OK) {
+                               goto end;
+                       }
                }
        }
-       rcu_read_unlock();
 
        /* /events */
        ret = config_writer_close_element(writer);
@@ -1186,32 +1188,32 @@ static int save_agent_events(struct config_writer *writer, struct agent *agent)
                goto end;
        }
 
-       rcu_read_lock();
-       cds_lfht_for_each_entry (agent->events->ht, &iter.iter, node, node) {
-               struct agent_event *agent_event;
-               struct ltt_ust_event fake_event;
-
-               memset(&fake_event, 0, sizeof(fake_event));
-               agent_event = lttng::utils::container_of(node, &agent_event::node);
-
-               /*
-                * Initialize a fake ust event to reuse the same serialization
-                * function since UST and agent events contain the same info
-                * (and one could wonder why they don't reuse the same
-                * structures...).
-                */
-               ret = init_ust_event_from_agent_event(&fake_event, agent_event);
-               if (ret != LTTNG_OK) {
-                       rcu_read_unlock();
-                       goto end;
-               }
-               ret = save_ust_event(writer, &fake_event);
-               if (ret != LTTNG_OK) {
-                       rcu_read_unlock();
-                       goto end;
+       {
+               lttng::urcu::read_lock_guard read_lock;
+
+               cds_lfht_for_each_entry (agent->events->ht, &iter.iter, node, node) {
+                       struct agent_event *agent_event;
+                       struct ltt_ust_event fake_event;
+
+                       memset(&fake_event, 0, sizeof(fake_event));
+                       agent_event = lttng::utils::container_of(node, &agent_event::node);
+
+                       /*
+                        * Initialize a fake ust event to reuse the same serialization
+                        * function since UST and agent events contain the same info
+                        * (and one could wonder why they don't reuse the same
+                        * structures...).
+                        */
+                       ret = init_ust_event_from_agent_event(&fake_event, agent_event);
+                       if (ret != LTTNG_OK) {
+                               goto end;
+                       }
+                       ret = save_ust_event(writer, &fake_event);
+                       if (ret != LTTNG_OK) {
+                               goto end;
+                       }
                }
        }
-       rcu_read_unlock();
 
        /* /events */
        ret = config_writer_close_element(writer);
@@ -1629,7 +1631,7 @@ static int save_ust_channel(struct config_writer *writer,
                        goto end;
                }
        } else {
-               struct agent *agent = NULL;
+               struct agent *agent = nullptr;
 
                agent = trace_ust_find_agent(session, ust_chan->domain);
                if (!agent) {
@@ -1752,7 +1754,7 @@ static int save_process_attr_tracker(struct config_writer *writer,
        const char *element_id_tracker, *element_target_id, *element_id;
        const struct process_attr_tracker *tracker;
        enum lttng_tracking_policy tracking_policy;
-       struct lttng_process_attr_values *values = NULL;
+       struct lttng_process_attr_values *values = nullptr;
 
        switch (process_attr) {
        case LTTNG_PROCESS_ATTR_PROCESS_ID:
@@ -1844,7 +1846,7 @@ static int save_process_attr_tracker(struct config_writer *writer,
 
                for (i = 0; i < count; i++) {
                        unsigned int integral_value = UINT_MAX;
-                       const char *name = NULL;
+                       const char *name = nullptr;
                        const struct process_attr_value *value =
                                lttng_process_attr_tracker_values_get_at_index(values, i);
 
@@ -2035,19 +2037,20 @@ static int save_ust_domain(struct config_writer *writer,
                goto end;
        }
 
-       rcu_read_lock();
-       cds_lfht_for_each_entry (
-               session->ust_session->domain_global.channels->ht, &iter.iter, node, node) {
-               ust_chan = lttng::utils::container_of(node, &ltt_ust_channel::node);
-               if (domain == ust_chan->domain) {
-                       ret = save_ust_channel(writer, ust_chan, session->ust_session);
-                       if (ret != LTTNG_OK) {
-                               rcu_read_unlock();
-                               goto end;
+       {
+               lttng::urcu::read_lock_guard read_lock;
+
+               cds_lfht_for_each_entry (
+                       session->ust_session->domain_global.channels->ht, &iter.iter, node, node) {
+                       ust_chan = lttng::utils::container_of(node, &ltt_ust_channel::node);
+                       if (domain == ust_chan->domain) {
+                               ret = save_ust_channel(writer, ust_chan, session->ust_session);
+                               if (ret != LTTNG_OK) {
+                                       goto end;
+                               }
                        }
                }
        }
-       rcu_read_unlock();
 
        /* /channels */
        ret = config_writer_close_element(writer);
@@ -2315,40 +2318,43 @@ static int save_snapshot_outputs(struct config_writer *writer, struct snapshot *
                goto end;
        }
 
-       rcu_read_lock();
-       cds_lfht_for_each_entry (snapshot->output_ht->ht, &iter.iter, output, node.node) {
-               ret = config_writer_open_element(writer, config_element_output);
-               if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
-                       goto end_unlock;
-               }
+       {
+               lttng::urcu::read_lock_guard read_lock;
 
-               ret = config_writer_write_element_string(writer, config_element_name, output->name);
-               if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
-                       goto end_unlock;
-               }
+               cds_lfht_for_each_entry (snapshot->output_ht->ht, &iter.iter, output, node.node) {
+                       ret = config_writer_open_element(writer, config_element_output);
+                       if (ret) {
+                               ret = LTTNG_ERR_SAVE_IO_FAIL;
+                               goto end_unlock;
+                       }
 
-               ret = config_writer_write_element_unsigned_int(
-                       writer, config_element_max_size, output->max_size);
-               if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
-                       goto end_unlock;
-               }
+                       ret = config_writer_write_element_string(
+                               writer, config_element_name, output->name);
+                       if (ret) {
+                               ret = LTTNG_ERR_SAVE_IO_FAIL;
+                               goto end_unlock;
+                       }
 
-               ret = save_consumer_output(writer, output->consumer);
-               if (ret != LTTNG_OK) {
-                       goto end_unlock;
-               }
+                       ret = config_writer_write_element_unsigned_int(
+                               writer, config_element_max_size, output->max_size);
+                       if (ret) {
+                               ret = LTTNG_ERR_SAVE_IO_FAIL;
+                               goto end_unlock;
+                       }
 
-               /* /output */
-               ret = config_writer_close_element(writer);
-               if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
-                       goto end_unlock;
+                       ret = save_consumer_output(writer, output->consumer);
+                       if (ret != LTTNG_OK) {
+                               goto end_unlock;
+                       }
+
+                       /* /output */
+                       ret = config_writer_close_element(writer);
+                       if (ret) {
+                               ret = LTTNG_ERR_SAVE_IO_FAIL;
+                               goto end_unlock;
+                       }
                }
        }
-       rcu_read_unlock();
 
        /* /snapshot_outputs */
        ret = config_writer_close_element(writer);
@@ -2361,7 +2367,6 @@ static int save_snapshot_outputs(struct config_writer *writer, struct snapshot *
 end:
        return ret;
 end_unlock:
-       rcu_read_unlock();
        return ret;
 }
 
@@ -2499,7 +2504,7 @@ static int save_session(struct ltt_session *session,
        int ret, fd = -1;
        char config_file_path[LTTNG_PATH_MAX];
        size_t len;
-       struct config_writer *writer = NULL;
+       struct config_writer *writer = nullptr;
        size_t session_name_len;
        const char *provided_path;
        int file_open_flags = O_CREAT | O_WRONLY | O_TRUNC;
This page took 0.02753 seconds and 4 git commands to generate.