X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Fmain.c;h=ad97a0b9b9871e395ed055860b853b93f55b5e78;hp=2836c489ce9647325dc5a8da7d25d18ba0c684b1;hb=ce9ee1fb2847b1603c4382c82aef95121f0e3d07;hpb=a1e4ab8b82429320c5f962038c0f28b874f8ea6f diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 2836c489c..ad97a0b9b 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -96,7 +96,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, opt_print_version; /* @@ -184,6 +184,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, }, }; @@ -311,6 +312,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 opt_working_directory"); + goto end; + } + } + break; + case 'v': /* Verbose level can increase using multiple -v */ if (arg) { @@ -541,8 +556,8 @@ static void relayd_cleanup(void) if (sessions_ht) lttng_ht_destroy(sessions_ht); - /* free the dynamically allocated opt_output_path */ free(opt_output_path); + free(opt_working_directory); /* Close thread quit pipes */ utils_close_pipe(thread_quit_pipe); @@ -3729,6 +3744,14 @@ int main(int argc, char **argv) } } + if (opt_working_directory) { + ret = utils_change_working_directory(opt_working_directory); + if (ret) { + /* All errors are already logged. */ + goto exit_options; + } + } + sessiond_trace_chunk_registry = sessiond_trace_chunk_registry_create(); if (!sessiond_trace_chunk_registry) { ERR("Failed to initialize session daemon trace chunk registry");