*
* Return 0 on success or else a negative value.
*/
-static int utils_stream_file_name(char *path,
+LTTNG_HIDDEN
+int utils_stream_file_name(char *path,
const char *path_name, const char *file_name,
uint64_t size, uint64_t count,
const char *suffix)
return ret;
}
+LTTNG_HIDDEN
+void utils_stream_file_rotation_get_new_count(uint64_t count,
+ uint64_t *new_count, bool *should_unlink)
+{
+ if (count > 0) {
+ /*
+ * In tracefile rotation, for the relay daemon we need
+ * to unlink the old file if present, because it may
+ * still be open in reading by the live thread, and we
+ * need to ensure that we do not overwrite the content
+ * between get_index and get_packet. Since we have no
+ * way to verify integrity of the data content compared
+ * to the associated index, we need to ensure the reader
+ * has exclusive access to the file content, and that
+ * the open of the data file is performed in get_index.
+ * Unlinking the old file rather than overwriting it
+ * achieves this.
+ */
+ if (new_count) {
+ *new_count = (*new_count + 1) % count;
+ }
+ *should_unlink = true;
+ } else {
+ if (new_count) {
+ (*new_count)++;
+ }
+ *should_unlink = false;
+ }
+}
+
/*
* Change the output tracefile according to the given size and count The
* new_count pointer is set during this operation.
int *stream_fd)
{
int ret;
+ bool should_unlink;
assert(stream_fd);
+ utils_stream_file_rotation_get_new_count(count, new_count,
+ &should_unlink);
+
ret = close(out_fd);
if (ret < 0) {
PERROR("Closing tracefile");
}
*stream_fd = -1;
- if (count > 0) {
- /*
- * In tracefile rotation, for the relay daemon we need
- * to unlink the old file if present, because it may
- * still be open in reading by the live thread, and we
- * need to ensure that we do not overwrite the content
- * between get_index and get_packet. Since we have no
- * way to verify integrity of the data content compared
- * to the associated index, we need to ensure the reader
- * has exclusive access to the file content, and that
- * the open of the data file is performed in get_index.
- * Unlinking the old file rather than overwriting it
- * achieves this.
- */
- if (new_count) {
- *new_count = (*new_count + 1) % count;
- }
+ if (should_unlink) {
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 {
- if (new_count) {
- (*new_count)++;
- }
}
ret = utils_create_stream_file(path_name, file_name, size,