do {
ret = write(wpipe, "!", 1);
} while (ret < 0 && errno == EINTR);
- if (ret < 0) {
+ if (ret < 0 || ret != 1) {
PERROR("write poll pipe");
}
sizeof(struct relay_command));
} while (ret < 0 && errno == EINTR);
free(relay_cmd);
- if (ret < 0) {
+ if (ret < 0 || ret != sizeof(struct relay_command)) {
PERROR("write cmd pipe");
goto error;
}
}
}
+/*
+ * Get stream from stream id.
+ * Need to be called with RCU read-side lock held.
+ */
+static
+struct relay_stream *relay_stream_from_stream_id(uint64_t stream_id,
+ struct lttng_ht *streams_ht)
+{
+ struct lttng_ht_node_ulong *node;
+ struct lttng_ht_iter iter;
+ struct relay_stream *ret;
+
+ lttng_ht_lookup(streams_ht,
+ (void *)((unsigned long) stream_id),
+ &iter);
+ node = lttng_ht_iter_get_node_ulong(&iter);
+ if (node == NULL) {
+ DBG("Relay stream %" PRIu64 " not found", stream_id);
+ ret = NULL;
+ goto end;
+ }
+
+ ret = caa_container_of(node, struct relay_stream, stream_n);
+
+end:
+ return ret;
+}
+
static
void deferred_free_stream(struct rcu_head *head)
{
send_ret = cmd->sock->ops->sendmsg(cmd->sock, &reply, sizeof(reply), 0);
if (send_ret < 0) {
ERR("Relayd sending session id");
+ ret = send_ret;
}
return ret;
goto end_no_session;
}
- /* FIXME : use data_size for something ? */
ret = cmd->sock->ops->recvmsg(cmd->sock, &stream_info,
sizeof(struct lttcomm_relayd_add_stream), 0);
if (ret < sizeof(struct lttcomm_relayd_add_stream)) {
sizeof(struct lttcomm_relayd_status_stream), 0);
if (send_ret < 0) {
ERR("Relay sending stream id");
+ ret = send_ret;
}
rcu_read_unlock();
struct lttcomm_relayd_generic_reply reply;
struct relay_stream *stream;
int ret, send_ret;
- struct lttng_ht_node_ulong *node;
struct lttng_ht_iter iter;
DBG("Close stream received");
}
rcu_read_lock();
- lttng_ht_lookup(streams_ht,
- (void *)((unsigned long) be64toh(stream_info.stream_id)),
- &iter);
- node = lttng_ht_iter_get_node_ulong(&iter);
- if (node == NULL) {
- DBG("Relay stream %" PRIu64 " not found", be64toh(stream_info.stream_id));
- ret = -1;
- goto end_unlock;
- }
-
- stream = caa_container_of(node, struct relay_stream, stream_n);
+ stream = relay_stream_from_stream_id(be64toh(stream_info.stream_id),
+ streams_ht);
if (!stream) {
ret = -1;
goto end_unlock;
if (delret < 0) {
PERROR("close stream");
}
+ iter.iter.node = &stream->stream_n.node;
delret = lttng_ht_del(streams_ht, &iter);
assert(!delret);
call_rcu(&stream->rcu_node,
sizeof(struct lttcomm_relayd_generic_reply), 0);
if (send_ret < 0) {
ERR("Relay sending stream id");
+ ret = send_ret;
}
end_no_session:
return ret;
}
-/*
- * Get stream from stream id.
- * Need to be called with RCU read-side lock held.
- */
-static
-struct relay_stream *relay_stream_from_stream_id(uint64_t stream_id,
- struct lttng_ht *streams_ht)
-{
- struct lttng_ht_node_ulong *node;
- struct lttng_ht_iter iter;
- struct relay_stream *ret;
-
- lttng_ht_lookup(streams_ht,
- (void *)((unsigned long) stream_id),
- &iter);
- node = lttng_ht_iter_get_node_ulong(&iter);
- if (node == NULL) {
- DBG("Relay stream %" PRIu64 " not found", stream_id);
- ret = NULL;
- goto end;
- }
-
- ret = caa_container_of(node, struct relay_stream, stream_n);
-
-end:
- return ret;
-}
-
/*
* Append padding to the file pointed by the file descriptor fd.
*/
do {
ret = write(fd, zeros, size);
} while (ret < 0 && errno == EINTR);
- if (ret < 0) {
+ if (ret < 0 || ret != size) {
PERROR("write padding to file");
}
ret = write(metadata_stream->fd, metadata_struct->payload,
payload_size);
} while (ret < 0 && errno == EINTR);
- if (ret < payload_size) {
+ if (ret < 0 || ret != payload_size) {
ERR("Relay error writing metadata on file");
ret = -1;
goto end_unlock;
struct lttcomm_relayd_generic_reply reply;
struct relay_stream *stream;
int ret;
- struct lttng_ht_node_ulong *node;
- struct lttng_ht_iter iter;
uint64_t last_net_seq_num, stream_id;
DBG("Data pending command received");
last_net_seq_num = be64toh(msg.last_net_seq_num);
rcu_read_lock();
- lttng_ht_lookup(streams_ht, (void *)((unsigned long) stream_id), &iter);
- node = lttng_ht_iter_get_node_ulong(&iter);
- if (node == NULL) {
- DBG("Relay stream %" PRIu64 " not found", stream_id);
+ stream = relay_stream_from_stream_id(stream_id, streams_ht);
+ if (stream == NULL) {
ret = -1;
goto end_unlock;
}
- stream = caa_container_of(node, struct relay_stream, stream_n);
- assert(stream);
-
DBG("Data pending for stream id %" PRIu64 " prev_seq %" PRIu64
" and last_seq %" PRIu64, stream_id, stream->prev_seq,
last_net_seq_num);
do {
ret = write(stream->fd, data_buffer, data_size);
} while (ret < 0 && errno == EINTR);
- if (ret < data_size) {
+ if (ret < 0 || ret != data_size) {
ERR("Relay error writing data to file");
ret = -1;
goto end_unlock;