#define _GNU_SOURCE
#include <assert.h>
-#include <fcntl.h>
#include <poll.h>
#include <pthread.h>
#include <stdlib.h>
/*
* Mmap the ring buffer, read it and write the data to the tracefile.
*
- * Returns the number of bytes written
+ * Returns the number of bytes written, else negative value on error.
*/
-int lttng_ustconsumer_on_read_subbuffer_mmap(
+ssize_t lttng_ustconsumer_on_read_subbuffer_mmap(
struct lttng_consumer_local_data *ctx,
struct lttng_consumer_stream *stream, unsigned long len)
{
ret = ustctl_get_mmap_read_offset(stream->chan->handle,
stream->buf, &mmap_offset);
if (ret != 0) {
- ret = -errno;
+ errno = -ret;
perror("ustctl_get_mmap_read_offset");
goto end;
}
if (ret >= len) {
len = 0;
} else if (ret < 0) {
- ret = -errno;
+ errno = -ret;
perror("Error in file write");
goto end;
}
*
* Returns the number of bytes spliced.
*/
-int lttng_ustconsumer_on_read_subbuffer_splice(
+ssize_t lttng_ustconsumer_on_read_subbuffer_splice(
struct lttng_consumer_local_data *ctx,
struct lttng_consumer_stream *stream, unsigned long len)
{
ret = ustctl_snapshot(stream->chan->handle, stream->buf);
if (ret != 0) {
- ret = errno;
+ errno = -ret;
perror("Getting sub-buffer snapshot.");
}
ret = ustctl_snapshot_get_produced(stream->chan->handle,
stream->buf, pos);
if (ret != 0) {
- ret = errno;
+ errno = -ret;
perror("kernctl_snapshot_get_produced");
}
if (!stream->hangup_flush_done) {
do {
readlen = read(stream->wait_fd, &dummy, 1);
- } while (readlen == -1 && errno == -EINTR);
+ } while (readlen == -1 && errno == EINTR);
if (readlen == -1) {
ret = readlen;
goto end;