diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-05-04T12·15+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-05-04T12·15+0000 |
commit | 256eeab7112da2d5fe1629ffb8b86640a894ee6d (patch) | |
tree | d173bcf930f86c296793a0cd20c7c83900c0bd18 /src/libmain/shared.cc | |
parent | fd927c5d25f1518dcbf99a57223f46fe098d9011 (diff) |
* Allow the location of the store etc. to be specified using
environment variables. * Started adding some automatic tests. * Do a `make check' when building RPMs.
Diffstat (limited to 'src/libmain/shared.cc')
-rw-r--r-- | src/libmain/shared.cc | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 42f17cf4edea..fce42710610e 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -46,27 +46,34 @@ void checkStoreNotSymlink(Path path) } +static string getEnv(const string & key, const string & def = "") +{ + char * value = getenv(key.c_str()); + return value ? string(value) : def; +} + + /* Initialize and reorder arguments, then call the actual argument processor. */ static void initAndRun(int argc, char * * argv) { - char * root = getenv("NIX_ROOT"); - - if (root) { - if (chroot(root) != 0) + string root = getEnv("NIX_ROOT"); + if (root != "") { + if (chroot(root.c_str()) != 0) throw SysError(format("changing root to `%1%'") % root); } /* Setup Nix paths. */ - nixStore = canonPath(NIX_STORE_DIR); - nixDataDir = canonPath(NIX_DATA_DIR); - nixLogDir = canonPath(NIX_LOG_DIR); - nixStateDir = canonPath(NIX_STATE_DIR); - nixDBPath = canonPath(NIX_STATE_DIR) + "/db"; + nixStore = getEnv("NIX_STORE_DIR", canonPath(NIX_STORE_DIR)); + nixDataDir = getEnv("NIX_DATA_DIR", canonPath(NIX_DATA_DIR)); + nixLogDir = getEnv("NIX_LOG_DIR", canonPath(NIX_LOG_DIR)); + nixStateDir = getEnv("NIX_STATE_DIR", canonPath(NIX_STATE_DIR)); + nixDBPath = getEnv("NIX_DB_DIR", nixStateDir + "/db"); /* Check that the store directory and its parent are not symlinks. */ - checkStoreNotSymlink(nixStore); + if (getEnv("NIX_IGNORE_SYMLINK_STORE") != "1") + checkStoreNotSymlink(nixStore); /* Catch SIGINT. */ struct sigaction act, oact; @@ -77,8 +84,8 @@ static void initAndRun(int argc, char * * argv) throw SysError("installing handler for SIGINT"); /* Process the NIX_LOG_TYPE environment variable. */ - char * lt = getenv("NIX_LOG_TYPE"); - if (lt) setLogType(lt); + string lt = getEnv("NIX_LOG_TYPE"); + if (lt != "") setLogType(lt); /* Put the arguments in a vector. */ Strings args, remaining; |