X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Futils.c;h=d71d92446ce71e14177e26005797211c4f7f0730;hp=6e772671451aec4e90e9943dd4c78eddd087c083;hb=93ec662e687dc15a3601704a1e0c96c51ad228c9;hpb=b31610f2294a6a827fa2d0d19d71199567db8dc5 diff --git a/src/common/utils.c b/src/common/utils.c index 6e7726714..d71d92446 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -843,7 +843,6 @@ int utils_rotate_stream_file(char *path_name, char *file_name, uint64_t size, { int ret; - assert(new_count); assert(stream_fd); ret = close(out_fd); @@ -866,18 +865,22 @@ int utils_rotate_stream_file(char *path_name, char *file_name, uint64_t size, * Unlinking the old file rather than overwriting it * achieves this. */ - *new_count = (*new_count + 1) % count; - ret = utils_unlink_stream_file(path_name, file_name, - size, *new_count, uid, gid, 0); + if (new_count) { + *new_count = (*new_count + 1) % count; + } + ret = utils_unlink_stream_file(path_name, file_name, size, + new_count ? *new_count : 0, uid, gid, 0); if (ret < 0 && errno != ENOENT) { goto error; } } else { - (*new_count)++; + if (new_count) { + (*new_count)++; + } } - ret = utils_create_stream_file(path_name, file_name, size, *new_count, - uid, gid, 0); + ret = utils_create_stream_file(path_name, file_name, size, + new_count ? *new_count : 0, uid, gid, 0); if (ret < 0) { goto error; } @@ -1322,3 +1325,23 @@ end: } return ret; } + +LTTNG_HIDDEN +int utils_truncate_stream_file(int fd, off_t length) +{ + int ret; + + ret = ftruncate(fd, length); + if (ret < 0) { + PERROR("ftruncate"); + goto end; + } + ret = lseek(fd, length, SEEK_SET); + if (ret < 0) { + PERROR("lseek"); + goto end; + } + +end: + return ret; +}