[RESEND,v3,5/7] config: check for CRIU_CONFIG_FILE environment variable

Submitted by Adrian Reber on July 10, 2018, 9:39 a.m.

Details

Message ID 1531215570-27770-5-git-send-email-adrian@lisas.de
State New
Series "Series without cover letter"
Headers show

Commit Message

Adrian Reber July 10, 2018, 9:39 a.m.
From: Adrian Reber <areber@redhat.com>

To be able to influence, especially via RPC, that another configuration
file should be used, this introduces the environment variable
CRIU_CONFIG_FILE.

If set, the file it points to will be used instead of the default
configuration files and also instead of the configuration file specified
via the command-line.

CRIU now first checks for CRIU_CONFIG_FILE and uses that, if that is not
set it looks for '--config FILEPATH' and uses that, if that is not set
it uses the default configuration files.

The idea behind this option is that now it is possible for an RPC client
to set CRIU_CONFIG_FILE and also set the RPC option
opts.prefer_config_file to tell CRIU to prefer the options from a
non-default configuration file over the options set via RPC.

Signed-off-by: Adrian Reber <areber@redhat.com>
---
 criu/config.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/config.c b/criu/config.c
index f3bf35b..d764832 100644
--- a/criu/config.c
+++ b/criu/config.c
@@ -157,6 +157,7 @@  int init_config(int argc, char **argv, int *global_cfg_argc, int *user_cfg_argc,
 {
 	bool no_default_config = false;
 	char *cfg_file = NULL;
+	char *cfg_from_env = getenv("CRIU_CONFIG_FILE");
 	int i;
 
 	/*
@@ -188,6 +189,14 @@  int init_config(int argc, char **argv, int *global_cfg_argc, int *user_cfg_argc,
 		}
 	}
 
+	/*
+	 * If the environment variable CRIU_CONFIG_FILE is set it
+	 * will overwrite the configuration file set via '--config'.
+	 */
+
+	if (cfg_from_env)
+		cfg_file = cfg_from_env;
+
 	init_configuration(argc, argv, no_default_config, cfg_file);
 	if (global_conf != NULL)
 		*global_cfg_argc = count_elements(global_conf);