X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust-ctl%2Fustctl.c;fp=liblttng-ust-ctl%2Fustctl.c;h=28dee5e9cdf80118113f53522dc296460f66b1af;hb=3ef94b0eba0a0ed8c8552e0284d4084f98be475f;hp=0361f184e342619031ec51d837c509743c7bab77;hpb=b67140581fe01aec0c91954f2193b1f4f5dd8c22;p=lttng-ust.git diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c index 0361f184..28dee5e9 100644 --- a/liblttng-ust-ctl/ustctl.c +++ b/liblttng-ust-ctl/ustctl.c @@ -1054,6 +1054,40 @@ end: return ret; } +/* + * Write at most one packet in the channel. + * Returns the number of bytes written on success, < 0 on error. + */ +ssize_t ustctl_write_one_packet_to_channel( + struct ustctl_consumer_channel *channel, + const char *metadata_str, /* NOT null-terminated */ + size_t len) /* metadata length */ +{ + struct lttng_ust_lib_ring_buffer_ctx ctx; + struct lttng_channel *chan = channel->chan; + const char *str = metadata_str; + ssize_t reserve_len; + int ret; + + reserve_len = min_t(ssize_t, + chan->ops->packet_avail_size(chan->chan, chan->handle), + len); + lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, reserve_len, + sizeof(char), -1, chan->handle); + ret = chan->ops->event_reserve(&ctx, 0); + if (ret != 0) { + DBG("LTTng: event reservation failed"); + assert(ret < 0); + reserve_len = ret; + goto end; + } + chan->ops->event_write(&ctx, str, reserve_len); + chan->ops->event_commit(&ctx); + +end: + return reserve_len; +} + int ustctl_channel_close_wait_fd(struct ustctl_consumer_channel *consumer_chan) { struct channel *chan;