struct lttng_consumer_stream *stream, unsigned long len)
{
unsigned long mmap_offset;
- ssize_t ret = 0;
+ ssize_t ret = 0, written = 0;
off_t orig_offset = stream->out_fd_offset;
int fd = stream->wait_fd;
int outfd = stream->out_fd;
if (ret != 0) {
errno = -ret;
perror("kernctl_get_mmap_read_offset");
+ written = ret;
goto end;
}
while (len > 0) {
ret = write(outfd, stream->mmap_base + mmap_offset, len);
- if (ret >= len) {
- len = 0;
- } else if (ret < 0) {
- errno = -ret;
+ if (ret < 0) {
+ if (errno == EINTR) {
+ /* restart the interrupted system call */
+ continue;
+ } else {
+ perror("Error in file write");
+ if (written == 0) {
+ written = ret;
+ }
+ goto end;
+ }
+ } else if (ret > len) {
perror("Error in file write");
+ written += ret;
goto end;
+ } else {
+ len -= ret;
+ mmap_offset += ret;
}
/* This won't block, but will start writeout asynchronously */
lttng_sync_file_range(outfd, stream->out_fd_offset, ret,
SYNC_FILE_RANGE_WRITE);
stream->out_fd_offset += ret;
+ written += ret;
}
-
lttng_consumer_sync_trace_file(stream, orig_offset);
-
- goto end;
-
end:
- return ret;
+ return written;
}
/*
struct lttng_consumer_local_data *ctx,
struct lttng_consumer_stream *stream, unsigned long len)
{
- ssize_t ret = 0;
+ ssize_t ret = 0, written = 0;
loff_t offset = 0;
off_t orig_offset = stream->out_fd_offset;
int fd = stream->wait_fd;
SPLICE_F_MOVE | SPLICE_F_MORE);
DBG("splice chan to pipe ret %zd", ret);
if (ret < 0) {
- errno = -ret;
perror("Error in relay splice");
+ if (written == 0) {
+ written = ret;
+ }
+ ret = errno;
goto splice_error;
}
SPLICE_F_MOVE | SPLICE_F_MORE);
DBG("splice pipe to file %zd", ret);
if (ret < 0) {
- errno = -ret;
perror("Error in file splice");
+ if (written == 0) {
+ written = ret;
+ }
+ ret = errno;
+ goto splice_error;
+ }
+ if (ret > len) {
+ errno = EINVAL;
+ perror("Wrote more data than requested");
+ written += ret;
+ ret = errno;
goto splice_error;
}
len -= ret;
lttng_sync_file_range(outfd, stream->out_fd_offset, ret,
SYNC_FILE_RANGE_WRITE);
stream->out_fd_offset += ret;
+ written += ret;
}
lttng_consumer_sync_trace_file(stream, orig_offset);
splice_error:
/* send the appropriate error description to sessiond */
- switch(ret) {
+ switch (ret) {
case EBADF:
lttng_consumer_send_error(ctx, CONSUMERD_SPLICE_EBADF);
break;
}
end:
- return ret;
+ return written;
}
/*
/* splice the subbuffer to the tracefile */
ret = lttng_consumer_on_read_subbuffer_splice(ctx, stream, len);
- if (ret < 0) {
+ if (ret != len) {
/*
* display the error but continue processing to try
* to release the subbuffer
*/
ERR("Error splicing to tracefile");
}
+
break;
case LTTNG_EVENT_MMAP:
/* read the used subbuffer size */
}
/* write the subbuffer to the tracefile */
ret = lttng_consumer_on_read_subbuffer_mmap(ctx, stream, len);
- if (ret < 0) {
+ if (ret != len) {
/*
* display the error but continue processing to try
* to release the subbuffer
struct lttng_consumer_stream *stream, unsigned long len)
{
unsigned long mmap_offset;
- long ret = 0;
+ long ret = 0, written = 0;
off_t orig_offset = stream->out_fd_offset;
int outfd = stream->out_fd;
if (ret != 0) {
errno = -ret;
PERROR("ustctl_get_mmap_read_offset");
+ written = ret;
goto end;
}
while (len > 0) {
ret = write(outfd, stream->mmap_base + mmap_offset, len);
- if (ret >= len) {
- len = 0;
- } else if (ret < 0) {
- errno = -ret;
+ if (ret < 0) {
+ if (errno == EINTR) {
+ /* restart the interrupted system call */
+ continue;
+ } else {
+ PERROR("Error in file write");
+ if (written == 0) {
+ written = ret;
+ }
+ goto end;
+ }
+ } else if (ret > len) {
PERROR("Error in file write");
+ written += ret;
goto end;
+ } else {
+ len -= ret;
+ mmap_offset += ret;
}
/* This won't block, but will start writeout asynchronously */
lttng_sync_file_range(outfd, stream->out_fd_offset, ret,
SYNC_FILE_RANGE_WRITE);
stream->out_fd_offset += ret;
+ written += ret;
}
-
lttng_consumer_sync_trace_file(stream, orig_offset);
-
- goto end;
-
end:
- return ret;
+ return written;
}
/*
assert(err == 0);
/* write the subbuffer to the tracefile */
ret = lttng_consumer_on_read_subbuffer_mmap(ctx, stream, len);
- if (ret < 0) {
+ if (ret != len) {
/*
* display the error but continue processing to try
* to release the subbuffer