Add --working-directory options to lttng-relayd
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Wed, 16 May 2018 22:24:01 +0000 (18:24 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 31 May 2018 19:54:04 +0000 (15:54 -0400)
Base version

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
src/bin/lttng-relayd/main.c
src/common/utils.c
src/common/utils.h

index cb4643b76f792b3555de1a65174cdf0d73410a06..96a0bd5f6063b899f38c000a84ddda6766887b87 100644 (file)
@@ -92,7 +92,7 @@ enum relay_connection_status {
 };
 
 /* command line options */
-char *opt_output_path;
+char *opt_output_path, *opt_working_directory;
 static int opt_daemon, opt_background;
 
 /*
@@ -179,6 +179,7 @@ static struct option long_options[] = {
        { "verbose", 0, 0, 'v', },
        { "config", 1, 0, 'f' },
        { "version", 0, 0, 'V' },
+       { "working-directory", 1, 0, 'w', },
        { NULL, 0, 0, 0, },
 };
 
@@ -289,6 +290,20 @@ static int set_option(int opt, const char *arg, const char *optname)
                        }
                }
                break;
+       case 'w':
+               if (lttng_is_setuid_setgid()) {
+                       WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
+                               "-w, --working-directory");
+               } else {
+                       ret = asprintf(&opt_working_directory, "%s", arg);
+                       if (ret < 0) {
+                               ret = -errno;
+                               PERROR("asprintf working_directory");
+                               goto end;
+                       }
+               }
+               break;
+
        case 'v':
                /* Verbose level can increase using multiple -v */
                if (arg) {
@@ -3952,6 +3967,15 @@ int main(int argc, char **argv)
                }
        }
 
+
+       if (opt_working_directory) {
+               ret = utils_change_working_dir(opt_working_directory);
+               if (ret) {
+                       ERR("Changing working directory");
+                       goto exit_options;
+               }
+       }
+
        /* Initialize thread health monitoring */
        health_relayd = health_app_create(NR_HEALTH_RELAYD_TYPES);
        if (!health_relayd) {
index 7d018b53b1b9430cfb427761f9d4b4a4573e0334..7243a5d94b3cbdd091831103649529a8bbac1ab9 100644 (file)
@@ -1545,3 +1545,33 @@ int utils_show_help(int section, const char *page_name,
 end:
        return ret;
 }
+
+LTTNG_HIDDEN
+int utils_change_working_dir(const char *path)
+{
+       int ret;
+
+       assert(path);
+
+       ret = chdir(path);
+       if (ret) {
+               PERROR("Failed to change working directory: %s", path);
+               goto end;
+       }
+
+       /* Check for write access */
+       if (access(path, W_OK)) {
+               if (errno == EACCES) {
+                       /*
+                        * Do not treat this as an error since the permission
+                        * might change in the lifetime of the process
+                        */
+                       DBG("Working directory is not writable: %s", path);
+               } else {
+                       PERROR("access");
+               }
+       }
+
+end:
+       return ret;
+}
index 9293b1d0ac03d44bf6bc052cb95af1a8fdbf7641..42850a9d622866f0ed4ecb7a5a7229a575ad7ba8 100644 (file)
@@ -60,5 +60,6 @@ int utils_create_lock_file(const char *filepath);
 int utils_recursive_rmdir(const char *path);
 int utils_truncate_stream_file(int fd, off_t length);
 int utils_show_help(int section, const char *page_name, const char *help_msg);
+int utils_change_working_dir(const char *path);
 
 #endif /* _COMMON_UTILS_H */
This page took 0.030855 seconds and 5 git commands to generate.