Move stream file rotation functions to utils
[lttng-tools.git] / src / common / ust-consumer / ust-consumer.c
index 431b94626736d042d92db89db0774e7e941cc3e7..bc0f585385814f1ba25be632f2a21fbd04232de9 100644 (file)
@@ -38,6 +38,7 @@
 #include <common/compat/fcntl.h>
 #include <common/consumer-metadata-cache.h>
 #include <common/consumer-timer.h>
+#include <common/utils.h>
 
 #include "ust-consumer.h"
 
@@ -112,13 +113,14 @@ error:
  */
 static struct lttng_consumer_channel *allocate_channel(uint64_t session_id,
                const char *pathname, const char *name, uid_t uid, gid_t gid,
-               int relayd_id, uint64_t key, enum lttng_event_output output)
+               int relayd_id, uint64_t key, enum lttng_event_output output,
+               uint64_t tracefile_size, uint64_t tracefile_count)
 {
        assert(pathname);
        assert(name);
 
        return consumer_allocate_channel(key, session_id, pathname, name, uid, gid,
-                       relayd_id, output);
+                       relayd_id, output, tracefile_size, tracefile_count);
 }
 
 /*
@@ -848,7 +850,9 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                                msg.u.ask_channel.pathname, msg.u.ask_channel.name,
                                msg.u.ask_channel.uid, msg.u.ask_channel.gid,
                                msg.u.ask_channel.relayd_id, msg.u.ask_channel.key,
-                               (enum lttng_event_output) msg.u.ask_channel.output);
+                               (enum lttng_event_output) msg.u.ask_channel.output,
+                               msg.u.ask_channel.tracefile_size,
+                               msg.u.ask_channel.tracefile_count);
                if (!channel) {
                        goto end_channel_error;
                }
@@ -1280,35 +1284,25 @@ end:
 
 /*
  * Called when a stream is created.
+ *
+ * Return 0 on success or else a negative value.
  */
 int lttng_ustconsumer_on_recv_stream(struct lttng_consumer_stream *stream)
 {
        int ret;
-       char full_path[PATH_MAX];
-
-       /* Opening the tracefile in write mode */
-       if (stream->net_seq_idx != (uint64_t) -1ULL) {
-               goto end;
-       }
-
-       ret = snprintf(full_path, sizeof(full_path), "%s/%s",
-                       stream->chan->pathname, stream->name);
-       if (ret < 0) {
-               PERROR("snprintf on_recv_stream");
-               goto error;
-       }
 
-       ret = run_as_open(full_path, O_WRONLY | O_CREAT | O_TRUNC,
-                       S_IRWXU | S_IRWXG | S_IRWXO, stream->uid, stream->gid);
-       if (ret < 0) {
-               PERROR("open stream path %s", full_path);
-               goto error;
+       /* Don't create anything if this is set for streaming. */
+       if (stream->net_seq_idx == (uint64_t) -1ULL) {
+               ret = utils_create_stream_file(stream->chan->pathname, stream->name,
+                               stream->chan->tracefile_size, stream->tracefile_count_current,
+                               stream->uid, stream->gid);
+               if (ret < 0) {
+                       goto error;
+               }
+               stream->out_fd = ret;
+               stream->tracefile_size_current = 0;
        }
-       stream->out_fd = ret;
-
-end:
-       /* we return 0 to let the library handle the FD internally */
-       return 0;
+       ret = 0;
 
 error:
        return ret;
This page took 0.023859 seconds and 4 git commands to generate.