Fix: truncate the metadata file in shm-path
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index cc26e6dae004baeab4177f3589a0e837e7deba34..ae0a56ac67e0d249953ec39d28718323484dbbad 100644 (file)
@@ -1333,16 +1333,6 @@ int cmd_enable_channel(struct ltt_session *session,
                attr->attr.switch_timer_interval = 0;
        }
 
-       /*
-        * The ringbuffer (both in user space and kernel) behave badly in overwrite
-        * mode and with less than 2 subbuf so block it right away and send back an
-        * invalid attribute error.
-        */
-       if (attr->attr.overwrite && attr->attr.num_subbuf < 2) {
-               ret = LTTNG_ERR_INVALID;
-               goto error;
-       }
-
        switch (domain->type) {
        case LTTNG_DOMAIN_KERNEL:
        {
@@ -3362,14 +3352,14 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
                if (lttng_strncpy(list[idx].name, output->name,
                                sizeof(list[idx].name))) {
                        ret = -LTTNG_ERR_INVALID;
-                       goto error;
+                       goto error_unlock;
                }
                if (output->consumer->type == CONSUMER_DST_LOCAL) {
                        if (lttng_strncpy(list[idx].ctrl_url,
                                        output->consumer->dst.trace_path,
                                        sizeof(list[idx].ctrl_url))) {
                                ret = -LTTNG_ERR_INVALID;
-                               goto error;
+                               goto error_unlock;
                        }
                } else {
                        /* Control URI. */
@@ -3377,7 +3367,7 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
                                        list[idx].ctrl_url, sizeof(list[idx].ctrl_url));
                        if (ret < 0) {
                                ret = -LTTNG_ERR_NOMEM;
-                               goto error;
+                               goto error_unlock;
                        }
 
                        /* Data URI. */
@@ -3385,7 +3375,7 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
                                        list[idx].data_url, sizeof(list[idx].data_url));
                        if (ret < 0) {
                                ret = -LTTNG_ERR_NOMEM;
-                               goto error;
+                               goto error_unlock;
                        }
                }
                idx++;
@@ -3394,9 +3384,10 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
        *outputs = list;
        list = NULL;
        ret = session->snapshot.nb_output;
+error_unlock:
+       rcu_read_unlock();
 error:
        free(list);
-       rcu_read_unlock();
        return ret;
 }
 
@@ -3445,6 +3436,27 @@ end:
        return ret;
 }
 
+static
+int clear_metadata_file(int fd)
+{
+       int ret;
+
+       ret = lseek(fd, 0, SEEK_SET);
+       if (ret < 0) {
+               PERROR("lseek");
+               goto end;
+       }
+
+       ret = ftruncate(fd, 0);
+       if (ret < 0) {
+               PERROR("ftruncate");
+               goto end;
+       }
+
+end:
+       return ret;
+}
+
 static
 int ust_metadata_regenerate(struct ltt_ust_session *usess)
 {
@@ -3466,6 +3478,15 @@ int ust_metadata_regenerate(struct ltt_ust_session *usess)
                memset(registry->metadata, 0, registry->metadata_alloc_len);
                registry->metadata_len = 0;
                registry->metadata_version++;
+               if (registry->metadata_fd > 0) {
+                       /* Clear the metadata file's content. */
+                       ret = clear_metadata_file(registry->metadata_fd);
+                       if (ret) {
+                               pthread_mutex_unlock(&registry->lock);
+                               goto end;
+                       }
+               }
+
                ret = ust_metadata_session_statedump(registry, NULL,
                                registry->major, registry->minor);
                if (ret) {
This page took 0.024076 seconds and 4 git commands to generate.