#define _GNU_SOURCE
#include <assert.h>
-#include <fcntl.h>
#include <poll.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <lttng/ust-ctl.h>
#include <common/common.h>
#include <common/sessiond-comm/sessiond-comm.h>
+#include <common/compat/fcntl.h>
#include "ust-consumer.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;
- perror("ustctl_get_mmap_read_offset");
+ errno = -ret;
+ PERROR("ustctl_get_mmap_read_offset");
goto end;
}
while (len > 0) {
if (ret >= len) {
len = 0;
} else if (ret < 0) {
- ret = -errno;
- perror("Error in file write");
+ errno = -ret;
+ PERROR("Error in file write");
goto end;
}
/* This won't block, but will start writeout asynchronously */
- sync_file_range(outfd, stream->out_fd_offset, ret,
+ lttng_sync_file_range(outfd, stream->out_fd_offset, ret,
SYNC_FILE_RANGE_WRITE);
stream->out_fd_offset += ret;
}
*
* 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;
- perror("Getting sub-buffer snapshot.");
+ errno = -ret;
+ PERROR("Getting sub-buffer snapshot.");
}
return ret;
ret = ustctl_snapshot_get_produced(stream->chan->handle,
stream->buf, pos);
if (ret != 0) {
- ret = errno;
- perror("kernctl_snapshot_get_produced");
+ errno = -ret;
+ PERROR("kernctl_snapshot_get_produced");
}
return ret;
/* signal the poll thread */
ret = write(ctx->consumer_poll_pipe[1], "4", 1);
if (ret < 0) {
- perror("write consumer poll");
+ PERROR("write consumer poll");
}
end_nosignal:
return 0;
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;
stream->uid, stream->gid);
if (ret < 0) {
ERR("Opening %s", stream->path_name);
- perror("open");
+ PERROR("open");
goto error;
}
stream->out_fd = ret;