Backport: Add --working-directory options to lttng-relayd
[lttng-tools.git] / src / bin / lttng-relayd / main.c
index 43498017dd0b41cbbafe908dbb69e1287c57d066..7f0b413bcbb789b83422255aad252e71c3b8e0d5 100644 (file)
@@ -83,7 +83,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;
 
 /*
@@ -169,6 +169,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, },
 };
 
@@ -279,6 +280,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) {
@@ -3191,6 +3206,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) {
This page took 0.02549 seconds and 5 git commands to generate.