use system folders if run as service

pull/102/head
orignal 10 years ago
parent 2cd8d0c0b7
commit 02c51b0980

@ -39,6 +39,14 @@ namespace i2p
delete &d;
};
bool Daemon_Singleton::IsService () const
{
#ifndef _WIN32
return i2p::util::config::GetArg("-service", 0);
#else
return false;
#endif
}
bool Daemon_Singleton::init(int argc, char* argv[])
{
@ -76,11 +84,11 @@ namespace i2p
{
if (isDaemon)
{
std::string logfile_path = i2p::util::filesystem::GetDataDir().string();
std::string logfile_path = IsService () ? "/var/log" : i2p::util::filesystem::GetDataDir().string();
#ifndef _WIN32
logfile_path.append("/debug.log");
logfile_path.append("/i2pd.log");
#else
logfile_path.append("\\debug.log");
logfile_path.append("\\i2pd.log");
#endif
StartLog (logfile_path);
}

@ -28,6 +28,8 @@ namespace i2p
Daemon_Singleton();
virtual ~Daemon_Singleton();
bool IsService () const;
// d-pointer for httpServer, httpProxy, etc.
class Daemon_Singleton_Private;
Daemon_Singleton_Private &d;

@ -74,7 +74,7 @@ namespace i2p
}
// Pidfile
pidfile = i2p::util::filesystem::GetDataDir().string();
pidfile = IsService () ? "/var/run" : i2p::util::filesystem::GetDataDir().string();
pidfile.append("/i2pd.pid");
pidFilehandle = open(pidfile.c_str(), O_RDWR | O_CREAT, 0600);
if (pidFilehandle == -1)

@ -49,6 +49,7 @@ Options
* --httpport= - The http port to listen on
* --log= - Enable or disable logging to file. 1 for yes, 0 for no.
* --daemon= - Enable or disable daemon mode. 1 for yes, 0 for no.
* --service= - 1 if uses system folders (/var/run/i2pd.pid, /var/log/i2pd.log, /var/lib/i2pd).
* --unreachable= - 1 if router is declared as unreachable and works through introducers.
* --httpproxyport= - The port to listen on (HTTP Proxy)
* --socksproxyport= - The port to listen on (SOCKS Proxy)

@ -168,13 +168,15 @@ namespace filesystem
// Windows < Vista: C:\Documents and Settings\Username\Application Data\i2pd
// Windows >= Vista: C:\Users\Username\AppData\Roaming\i2pd
// Mac: ~/Library/Application Support/i2pd
// Unix: ~/.i2pd
// Unix: ~/.i2pd or /var/lib/i2pd is system=1
#ifdef WIN32
// Windows
char localAppData[MAX_PATH];
SHGetFolderPath(NULL, CSIDL_APPDATA, 0, NULL, localAppData);
return boost::filesystem::path(std::string(localAppData) + "\\i2pd");
#else
if (i2p::util::config::GetArg("-service", 0)) // use system folder
return boost::filesystem::path("/var/lib/i2pd");
boost::filesystem::path pathRet;
char* pszHome = getenv("HOME");
if (pszHome == NULL || strlen(pszHome) == 0)

Loading…
Cancel
Save