/*
* Fill lttng_channel array of all channels.
*/
-static void list_lttng_channels(enum lttng_domain_type domain,
+static ssize_t list_lttng_channels(enum lttng_domain_type domain,
struct ltt_session *session, struct lttng_channel *channels,
struct lttcomm_channel_extended *chan_exts)
{
- int i = 0, ret;
+ int i = 0, ret = 0;
struct ltt_kernel_channel *kchan;
DBG("Listing channels for session %s", session->name);
}
end:
- return;
+ if (ret < 0) {
+ return -LTTNG_ERR_FATAL;
+ } else {
+ return LTTNG_OK;
+ }
}
static void increment_extended_len(const char *filter_expression,
/*
* Connect to the relayd using URI and send the socket to the right consumer.
+ *
+ * The consumer socket lock must be held by the caller.
*/
static int send_consumer_relayd_socket(enum lttng_domain_type domain,
unsigned int session_id, struct lttng_uri *relayd_uri,
/* Connect to relayd and make version check if uri is the control. */
ret = create_connect_relayd(relayd_uri, &rsock, consumer);
if (ret != LTTNG_OK) {
- goto error;
+ goto relayd_comm_error;
}
assert(rsock);
*/
close_sock:
- (void) relayd_close(rsock);
- free(rsock);
-
-error:
if (ret != LTTNG_OK) {
/*
* The consumer output for this session should not be used anymore
*/
consumer->enabled = 0;
}
+ (void) relayd_close(rsock);
+ free(rsock);
+
+relayd_comm_error:
return ret;
}
* Send both relayd sockets to a specific consumer and domain. This is a
* helper function to facilitate sending the information to the consumer for a
* session.
+ *
+ * The consumer socket lock must be held by the caller.
*/
static int send_consumer_relayd_sockets(enum lttng_domain_type domain,
unsigned int session_id, struct consumer_output *consumer,
channel_exts = ((void *) *channels) +
(nb_chan * sizeof(struct lttng_channel));
- list_lttng_channels(domain, session, *channels, channel_exts);
+ ret = list_lttng_channels(domain, session, *channels, channel_exts);
+ if (ret != LTTNG_OK) {
+ free(*channels);
+ *channels = NULL;
+ goto end;
+ }
} else {
*channels = NULL;
}
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_regenerate_metadata(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(®istry->lock);
+ goto end;
+ }
+ }
+
ret = ust_metadata_session_statedump(registry, NULL,
registry->major, registry->minor);
if (ret) {