+/*
+ * Regenerate the metadata for a session.
+ * Return 0 on success, a negative error code on error.
+ */
+int lttng_regenerate_metadata(const char *session_name)
+{
+ int ret;
+ struct lttcomm_session_msg lsm;
+
+ if (!session_name) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ memset(&lsm, 0, sizeof(lsm));
+ lsm.cmd_type = LTTNG_REGENERATE_METADATA;
+
+ lttng_ctl_copy_string(lsm.session.name, session_name,
+ sizeof(lsm.session.name));
+
+ ret = lttng_ctl_ask_sessiond(&lsm, NULL);
+ if (ret < 0) {
+ goto end;
+ }
+
+ ret = 0;
+end:
+ return ret;
+}
+
+/*
+ * Deprecated, replaced by lttng_regenerate_metadata.
+ */
+int lttng_metadata_regenerate(const char *session_name)
+{
+ return lttng_regenerate_metadata(session_name);
+}
+
+/*
+ * Regenerate the statedump of a session.
+ * Return 0 on success, a negative error code on error.
+ */
+int lttng_regenerate_statedump(const char *session_name)
+{
+ int ret;
+ struct lttcomm_session_msg lsm;
+
+ if (!session_name) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ memset(&lsm, 0, sizeof(lsm));
+ lsm.cmd_type = LTTNG_REGENERATE_STATEDUMP;
+
+ lttng_ctl_copy_string(lsm.session.name, session_name,
+ sizeof(lsm.session.name));
+
+ ret = lttng_ctl_ask_sessiond(&lsm, NULL);
+ if (ret < 0) {
+ goto end;
+ }
+
+ ret = 0;
+end:
+ return ret;
+}
+
+int lttng_register_trigger(struct lttng_trigger *trigger)
+{
+ int ret;
+ struct lttcomm_session_msg lsm;
+ struct lttng_dynamic_buffer buffer;
+
+ lttng_dynamic_buffer_init(&buffer);
+ if (!trigger) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ if (!lttng_trigger_validate(trigger)) {
+ ret = -LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+
+ ret = lttng_trigger_serialize(trigger, &buffer);
+ if (ret < 0) {
+ ret = -LTTNG_ERR_UNK;
+ goto end;
+ }
+
+ memset(&lsm, 0, sizeof(lsm));
+ lsm.cmd_type = LTTNG_REGISTER_TRIGGER;
+ lsm.u.trigger.length = (uint32_t) buffer.size;
+ ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, buffer.data,
+ buffer.size, NULL);
+end:
+ lttng_dynamic_buffer_reset(&buffer);
+ return ret;
+}
+
+int lttng_unregister_trigger(struct lttng_trigger *trigger)
+{
+ int ret;
+ struct lttcomm_session_msg lsm;
+ struct lttng_dynamic_buffer buffer;
+
+ lttng_dynamic_buffer_init(&buffer);
+ if (!trigger) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ if (!lttng_trigger_validate(trigger)) {
+ ret = -LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+
+ ret = lttng_trigger_serialize(trigger, &buffer);
+ if (ret < 0) {
+ ret = -LTTNG_ERR_UNK;
+ goto end;
+ }
+
+ memset(&lsm, 0, sizeof(lsm));
+ lsm.cmd_type = LTTNG_UNREGISTER_TRIGGER;
+ lsm.u.trigger.length = (uint32_t) buffer.size;
+ ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, buffer.data,
+ buffer.size, NULL);
+end:
+ lttng_dynamic_buffer_reset(&buffer);
+ return ret;
+}
+
+int lttng_session_get_current_archive_location(const char *session_name,
+ char **chunk_path)
+{
+ struct lttcomm_session_msg lsm;
+ struct lttng_session_get_current_output_return *output_return = NULL;
+ int ret;
+ size_t path_len;
+
+ memset(&lsm, 0, sizeof(lsm));
+ lsm.cmd_type = LTTNG_SESSION_GET_CURRENT_OUTPUT;
+ ret = lttng_strncpy(lsm.session.name, session_name,
+ sizeof(lsm.session.name));
+ if (ret) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ ret = lttng_ctl_ask_sessiond(&lsm, (void **) &output_return);
+ if (ret < 0) {
+ ret = -1;
+ goto end;
+ }
+
+ path_len = lttng_strnlen(output_return->path,
+ sizeof(output_return->path));
+ if (path_len == 0 || path_len == sizeof(output_return->path)) {
+ ret = -LTTNG_ERR_NO_SESSION_OUTPUT;
+ goto end;
+ }
+
+ *chunk_path = zmalloc(path_len + 1);
+ if (!*chunk_path) {
+ ret = -1;
+ goto end;
+ }
+ memcpy(*chunk_path, output_return->path, path_len);
+
+ ret = 0;
+
+end:
+ free(output_return);
+ return ret;
+}
+