diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -38,7 +38,8 @@ gArgs.AddArg("-version", "Print version and exit", false, OptionsCategory::OPTIONS); gArgs.AddArg("-conf=", - strprintf(_("Specify configuration file (default: %s)"), + strprintf(_("Specify configuration file. Relative paths will " + "be prefixed by datadir location. (default: %s)"), BITCOIN_CONF_FILENAME), false, OptionsCategory::OPTIONS); gArgs.AddArg("-datadir=", _("Specify data directory"), false, diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -374,7 +374,8 @@ DEFAULT_BLOCKSONLY), true, OptionsCategory::OPTIONS); gArgs.AddArg("-conf=", - strprintf(_("Specify configuration file (default: %s)"), + strprintf(_("Specify configuration file. Relative paths will " + "be prefixed by datadir location. (default: %s)"), BITCOIN_CONF_FILENAME), false, OptionsCategory::OPTIONS); gArgs.AddArg("-datadir=", _("Specify data directory"), false, @@ -393,8 +394,8 @@ gArgs.AddArg( "-debuglogfile=", strprintf( - _("Specify location of debug log file: this can be an absolute " - "path or a path relative to the data directory (default: %s)"), + _("Specify location of debug log file. Relative paths will be " + "prefixed by a net-specific datadir location. (default: %s)"), DEFAULT_DEBUGLOGFILE), false, OptionsCategory::OPTIONS); gArgs.AddArg("-feefilter", @@ -460,7 +461,9 @@ #ifndef WIN32 gArgs.AddArg( "-pid=", - strprintf(_("Specify pid file (default: %s)"), BITCOIN_PID_FILENAME), + strprintf(_("Specify pid file. Relative paths will be prefixed by a " + "net-specific datadir location. (default: %s)"), + BITCOIN_PID_FILENAME), false, OptionsCategory::OPTIONS); #endif gArgs.AddArg( @@ -934,9 +937,11 @@ "::1 i.e., localhost, or if -rpcallowip has been specified, 0.0.0.0 " "and :: i.e., all addresses)"), false, OptionsCategory::RPC); - gArgs.AddArg("-rpccookiefile=", - _("Location of the auth cookie (default: data dir)"), false, - OptionsCategory::RPC); + gArgs.AddArg( + "-rpccookiefile=", + _("Location of the auth cookie. Relative paths will be prefixed by a " + "net-specific datadir location. (default: data dir)"), + false, OptionsCategory::RPC); gArgs.AddArg("-rpcuser=", _("Username for JSON-RPC connections"), false, OptionsCategory::RPC); gArgs.AddArg("-rpcpassword=", _("Password for JSON-RPC connections"), diff --git a/src/logging.cpp b/src/logging.cpp --- a/src/logging.cpp +++ b/src/logging.cpp @@ -36,11 +36,7 @@ fs::path BCLog::Logger::GetDebugLogPath() { fs::path logfile(gArgs.GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE)); - if (logfile.is_absolute()) { - return logfile; - } else { - return GetDataDir() / logfile; - } + return AbsPathForConfigVal(logfile); } bool BCLog::Logger::OpenDebugLog() { diff --git a/src/rpc/protocol.cpp b/src/rpc/protocol.cpp --- a/src/rpc/protocol.cpp +++ b/src/rpc/protocol.cpp @@ -72,11 +72,7 @@ if (temp) { arg += ".tmp"; } - fs::path path(arg); - if (!path.is_complete()) { - path = GetDataDir() / path; - } - return path; + return AbsPathForConfigVal(fs::path(arg)); } bool GenerateAuthCookie(std::string *cookie_out) { diff --git a/src/util.h b/src/util.h --- a/src/util.h +++ b/src/util.h @@ -99,6 +99,16 @@ #endif void runCommand(const std::string &strCommand); +/** + * Most paths passed as configuration arguments are treated as relative to + * the datadir if they are not absolute. + * + * @param path The path to be conditionally prefixed with datadir. + * @param net_specific Forwarded to GetDataDir(). + * @return The normalized path. + */ +fs::path AbsPathForConfigVal(const fs::path &path, bool net_specific = true); + inline bool IsSwitchChar(char c) { #ifdef WIN32 return c == '-' || c == '/'; diff --git a/src/util.cpp b/src/util.cpp --- a/src/util.cpp +++ b/src/util.cpp @@ -7,6 +7,7 @@ #include #endif +#include #include #include @@ -894,12 +895,7 @@ } fs::path GetConfigFile(const std::string &confPath) { - fs::path pathConfigFile(confPath); - if (!pathConfigFile.is_complete()) { - pathConfigFile = GetDataDir(false) / pathConfigFile; - } - - return pathConfigFile; + return AbsPathForConfigVal(fs::path(confPath), false); } static std::string TrimString(const std::string &str, @@ -1043,11 +1039,8 @@ #ifndef WIN32 fs::path GetPidFile() { - fs::path pathPidFile(gArgs.GetArg("-pid", BITCOIN_PID_FILENAME)); - if (!pathPidFile.is_complete()) { - pathPidFile = GetDataDir() / pathPidFile; - } - return pathPidFile; + return AbsPathForConfigVal( + fs::path(gArgs.GetArg("-pid", BITCOIN_PID_FILENAME))); } void CreatePidFile(const fs::path &path, pid_t pid) { @@ -1314,3 +1307,7 @@ int64_t GetStartupTime() { return nStartupTime; } + +fs::path AbsPathForConfigVal(const fs::path &path, bool net_specific) { + return fs::absolute(path, GetDataDir(net_specific)); +}