Introduce LTTNG_RELAYD_WORKING_DIRECTORY environment variable
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 22 May 2018 17:48:07 +0000 (13:48 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 22 Oct 2019 19:01:29 +0000 (15:01 -0400)
LTTNG_RELAYD_WORKING_DIRECTORY is equivalent to the --working-directory
command line options.

Note: when using --working-directory, the command line option always
overwrite the environment configuration, LTTNG_RELAYD_WORKING_DIRECTORY
in this case.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-relayd/main.c
src/common/defaults.h
tests/regression/tools/working-directory/test_relayd_working_directory

index ad97a0b9b9871e395ed055860b853b93f55b5e78..5f72c32a906f700ec14009766d056ead3e49b375 100644 (file)
@@ -406,6 +406,23 @@ end:
        return ret;
 }
 
        return ret;
 }
 
+static int parse_env_options(void)
+{
+       int ret = 0;
+       char *value = NULL;
+
+       value = lttng_secure_getenv(DEFAULT_LTTNG_RELAYD_WORKING_DIRECTORY_ENV);
+       if (value) {
+               opt_working_directory = strdup(value);
+               if (!opt_working_directory) {
+                       ERR("Failed to allocate working directory string (\"%s\")",
+                                       value);
+                       ret = -1;
+               }
+       }
+       return ret;
+}
+
 static int set_options(int argc, char **argv)
 {
        int c, ret = 0, option_index = 0, retval = 0;
 static int set_options(int argc, char **argv)
 {
        int c, ret = 0, option_index = 0, retval = 0;
@@ -3686,7 +3703,17 @@ int main(int argc, char **argv)
        int ret = 0, retval = 0;
        void *status;
 
        int ret = 0, retval = 0;
        void *status;
 
-       /* Parse arguments */
+       /* Parse environment variables */
+       ret = parse_env_options();
+       if (ret) {
+               retval = -1;
+               goto exit_options;
+       }
+
+       /*
+        * Parse arguments.
+        * Command line arguments overwrite environment.
+        */
        progname = argv[0];
        if (set_options(argc, argv)) {
                retval = -1;
        progname = argv[0];
        if (set_options(argc, argv)) {
                retval = -1;
index 183e315183356c1ebca2f5a8d4f65beea7dbc1b2..1545d0a748374a8cda77c8de361031184c642db3 100644 (file)
 #define DEFAULT_LTTNG_RELAYD_TCP_KEEP_ALIVE_PROBE_INTERVAL_ENV "LTTNG_RELAYD_TCP_KEEP_ALIVE_PROBE_INTERVAL"
 #define DEFAULT_LTTNG_RELAYD_TCP_KEEP_ALIVE_ABORT_THRESHOLD_ENV "LTTNG_RELAYD_TCP_KEEP_ALIVE_ABORT_THRESHOLD"
 
 #define DEFAULT_LTTNG_RELAYD_TCP_KEEP_ALIVE_PROBE_INTERVAL_ENV "LTTNG_RELAYD_TCP_KEEP_ALIVE_PROBE_INTERVAL"
 #define DEFAULT_LTTNG_RELAYD_TCP_KEEP_ALIVE_ABORT_THRESHOLD_ENV "LTTNG_RELAYD_TCP_KEEP_ALIVE_ABORT_THRESHOLD"
 
+#define DEFAULT_LTTNG_RELAYD_WORKING_DIRECTORY_ENV "LTTNG_RELAYD_WORKING_DIRECTORY"
+
 /*
  * Name of the intermediate directory used to rename the trace chunk of a
  * session's first rotation.
 /*
  * Name of the intermediate directory used to rename the trace chunk of a
  * session's first rotation.
index 13e816d8a1d476309779ffdc44f0ae44258256c1..8a261af213631662da28b1643e7c8b6eef305d77 100755 (executable)
@@ -22,11 +22,10 @@ TESTDIR=$CURDIR/../../../
 
 DIR=$(readlink -f "$TESTDIR")
 
 
 DIR=$(readlink -f "$TESTDIR")
 
-NUM_TESTS=27
+NUM_TESTS=35
 
 source $TESTDIR/utils/utils.sh
 
 
 source $TESTDIR/utils/utils.sh
 
-
 #MUST set TESTDIR before calling those functions
 plan_tests $NUM_TESTS
 
 #MUST set TESTDIR before calling those functions
 plan_tests $NUM_TESTS
 
@@ -223,6 +222,58 @@ function test_relayd_failure()
        rm -rf "$working_dir"
 }
 
        rm -rf "$working_dir"
 }
 
+function test_relayd_env()
+{
+       local working_dir
+       local cwd
+       local pid
+
+       working_dir=$(mktemp -d)
+
+       diag "Test lttng-relayd change working directory from env. variable"
+
+       export LTTNG_RELAYD_WORKING_DIRECTORY=${working_dir}
+       start_lttng_relayd_opt 1 "-b" ""
+
+       pid=$(pgrep "$RELAYD_MATCH")
+       ok $? "Found lttng-relayd"
+
+       cwd=$(readlink "/proc/$pid/cwd")
+
+       is "$cwd" "$working_dir" "Working directory changed"
+
+       stop_lttng_relayd
+       rm -rf "$working_dir"
+       unset LTTNG_RELAYD_WORKING_DIRECTORY
+}
+
+function test_relayd_cmdline_overwrite_env()
+{
+       local working_dir_env
+       local working_dir_cmdline
+       local cwd
+       local pid
+
+       working_dir_env=$(mktemp -d)
+       working_dir_cmdline=$(mktemp -d)
+
+       diag "Test lttng-relayd change working directory command line overwrite env variable"
+
+       export LTTNG_RELAYD_WORKING_DIRECTORY=${working_dir_env}
+       start_lttng_relayd_opt 1 "-b" "--working-dir ${working_dir_cmdline}"
+
+       pid=$(pgrep "$RELAYD_MATCH")
+       ok $? "Found lttng-relayd"
+
+       cwd=$(readlink "/proc/$pid/cwd")
+
+       is "$cwd" "$working_dir_cmdline" "Working directory is the one from command line"
+
+       stop_lttng_relayd
+       rm -rf "$working_dir_env" "$working_dir_cmdline"
+       unset LTTNG_RELAYD_WORKING_DIRECTORY
+}
+
 TESTS=(
        test_relayd
        test_relayd_daemon
 TESTS=(
        test_relayd
        test_relayd_daemon
@@ -231,6 +282,8 @@ TESTS=(
        test_relayd_background_no_working_dir
        test_relayd_debug_permission
        test_relayd_failure
        test_relayd_background_no_working_dir
        test_relayd_debug_permission
        test_relayd_failure
+       test_relayd_env
+       test_relayd_cmdline_overwrite_env
 )
 
 for fct_test in "${TESTS[@]}";
 )
 
 for fct_test in "${TESTS[@]}";
This page took 0.038945 seconds and 4 git commands to generate.