Override default SPA config location via environment

When using zdb with non-default SPA config file it is not convenient
to add -U <non-default-config-file-path> all the time. This commit
introduces support for setting/overriding SPA config location via
environment variable 'SPA_CONFIG_PATH'.

If -U flag is specified in the command line it will override any other
value as usual.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1545
This commit is contained in:
Cyril Plisko 2013-06-24 09:45:20 +03:00 committed by Brian Behlendorf
parent 20c17b96c9
commit 64d7b6cf75

View File

@ -3059,12 +3059,22 @@ main(int argc, char **argv)
nvlist_t *policy = NULL; nvlist_t *policy = NULL;
uint64_t max_txg = UINT64_MAX; uint64_t max_txg = UINT64_MAX;
int rewind = ZPOOL_NEVER_REWIND; int rewind = ZPOOL_NEVER_REWIND;
char *spa_config_path_env;
(void) setrlimit(RLIMIT_NOFILE, &rl); (void) setrlimit(RLIMIT_NOFILE, &rl);
(void) enable_extended_FILE_stdio(-1, -1); (void) enable_extended_FILE_stdio(-1, -1);
dprintf_setup(&argc, argv); dprintf_setup(&argc, argv);
/*
* If there is an environment variable SPA_CONFIG_PATH it overrides
* default spa_config_path setting. If -U flag is specified it will
* override this environment variable settings once again.
*/
spa_config_path_env = getenv("SPA_CONFIG_PATH");
if (spa_config_path_env != NULL)
spa_config_path = spa_config_path_env;
while ((c = getopt(argc, argv, "bcdhilmM:suCDRSAFLXevp:t:U:P")) != -1) { while ((c = getopt(argc, argv, "bcdhilmM:suCDRSAFLXevp:t:U:P")) != -1) {
switch (c) { switch (c) {
case 'b': case 'b':