Fix: no need to use run_as_open in the relayd
authorDavid Goulet <dgoulet@efficios.com>
Mon, 29 Apr 2013 17:08:36 +0000 (13:08 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 29 Apr 2013 17:08:36 +0000 (13:08 -0400)
The utils create stream file function is changed to handle uid and gid
set to -1 meaning that it now does not use the run_as_open() call which
is costly in performance and will instead use open().

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-relayd/main.c
src/common/utils.c

index 9a2b3bda7c010e9c8da7ad7a7b0345c9e4697d03..156fc83ee6d534599bbb6d44a1b747099eeb08c2 100644 (file)
@@ -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,7 +1629,7 @@ 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");
index 54eed80bde14ad83228a090ce45638b0bba6c082..1c2b95d3e7d5d3e427bc4c20f59ba4483062dea9 100644 (file)
@@ -313,7 +313,7 @@ LTTNG_HIDDEN
 int utils_create_stream_file(char *path_name, char *file_name, uint64_t size,
                uint64_t count, int uid, int gid)
 {
-       int ret, out_fd;
+       int ret, out_fd, flags, mode;
        char full_path[PATH_MAX], *path_name_id = NULL, *path;
 
        assert(path_name);
@@ -341,9 +341,15 @@ int utils_create_stream_file(char *path_name, char *file_name, uint64_t size,
                path = full_path;
        }
 
+       flags = O_WRONLY | O_CREAT | O_TRUNC;
        /* Open with 660 mode */
-       out_fd = run_as_open(path, O_WRONLY | O_CREAT | O_TRUNC,
-                       S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, uid, gid);
+       mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
+
+       if (uid < 0 || gid < 0) {
+               out_fd = open(path, flags, mode);
+       } else {
+               out_fd = run_as_open(path, flags, mode, uid, gid);
+       }
        if (out_fd < 0) {
                PERROR("open stream path %s", path);
                goto error_open;
This page took 0.027799 seconds and 4 git commands to generate.