Fix: don't start the relayd with a wrong --output dir
[lttng-tools.git] / src / bin / lttng-relayd / main.c
index 9a2b3bda7c010e9c8da7ad7a7b0345c9e4697d03..3b9f6708a3685e61e0a6918e94732046a9b9151f 100644 (file)
@@ -105,12 +105,12 @@ static
 void usage(void)
 {
        fprintf(stderr, "Usage: %s OPTIONS\n\nOptions:\n", progname);
-       fprintf(stderr, "  -h, --help                         Display this usage.\n");
-       fprintf(stderr, "  -d, --daemonize                    Start as a daemon.\n");
-       fprintf(stderr, "  -C, --control-port                 Control port listening (URI)\n");
-       fprintf(stderr, "  -D, --data-port                    Data port listening (URI)\n");
-       fprintf(stderr, "  -o, --output                       Output path for traces (PATH)\n");
-       fprintf(stderr, "  -v, --verbose                      Verbose mode. Activate DBG() macro.\n");
+       fprintf(stderr, "  -h, --help                Display this usage.\n");
+       fprintf(stderr, "  -d, --daemonize           Start as a daemon.\n");
+       fprintf(stderr, "  -C, --control-port URL    Control port listening.\n");
+       fprintf(stderr, "  -D, --data-port URL       Data port listening.\n");
+       fprintf(stderr, "  -o, --output PATH         Output path for traces. Must use an absolute path.\n");
+       fprintf(stderr, "  -v, --verbose             Verbose mode. Activate DBG() macro.\n");
 }
 
 static
@@ -863,8 +863,12 @@ int relay_add_stream(struct lttcomm_relayd_hdr *recv_hdr,
                goto end;
        }
 
+       /*
+        * No need to use run_as API here because whatever we receives, the relayd
+        * uses its own credentials for the stream files.
+        */
        ret = utils_create_stream_file(stream->path_name, stream->channel_name,
-                       stream->tracefile_size, 0, getuid(), getgid());
+                       stream->tracefile_size, 0, -1, -1);
        if (ret < 0) {
                ERR("Create output file");
                goto end;
@@ -1625,13 +1629,15 @@ int relay_process_data(struct relay_command *cmd, struct lttng_ht *streams_ht)
                        stream->tracefile_size) {
                ret = utils_rotate_stream_file(stream->path_name,
                                stream->channel_name, stream->tracefile_size,
-                               stream->tracefile_count, getuid(), getgid(),
+                               stream->tracefile_count, -1, -1,
                                stream->fd, &(stream->tracefile_count_current));
                if (ret < 0) {
                        ERR("Rotating output file");
                        goto end;
                }
                stream->fd = ret;
+               /* Reset current size because we just perform a stream rotation. */
+               stream->tracefile_size_current = 0;
        }
        stream->tracefile_size_current += data_size;
        do {
@@ -2065,6 +2071,11 @@ int main(int argc, char **argv)
 
        /* Try to create directory if -o, --output is specified. */
        if (opt_output_path) {
+               if (*opt_output_path != '/') {
+                       ERR("Please specify an absolute path for -o, --output PATH");
+                       goto exit;
+               }
+
                ret = utils_mkdir_recursive(opt_output_path, S_IRWXU | S_IRWXG);
                if (ret < 0) {
                        ERR("Unable to create %s", opt_output_path);
This page took 0.02711 seconds and 5 git commands to generate.