mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
use system folders if run as service
This commit is contained in:
parent
2cd8d0c0b7
commit
02c51b0980
14
Daemon.cpp
14
Daemon.cpp
|
@ -39,6 +39,14 @@ namespace i2p
|
||||||
delete &d;
|
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[])
|
bool Daemon_Singleton::init(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
@ -76,11 +84,11 @@ namespace i2p
|
||||||
{
|
{
|
||||||
if (isDaemon)
|
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
|
#ifndef _WIN32
|
||||||
logfile_path.append("/debug.log");
|
logfile_path.append("/i2pd.log");
|
||||||
#else
|
#else
|
||||||
logfile_path.append("\\debug.log");
|
logfile_path.append("\\i2pd.log");
|
||||||
#endif
|
#endif
|
||||||
StartLog (logfile_path);
|
StartLog (logfile_path);
|
||||||
}
|
}
|
||||||
|
|
2
Daemon.h
2
Daemon.h
|
@ -28,6 +28,8 @@ namespace i2p
|
||||||
Daemon_Singleton();
|
Daemon_Singleton();
|
||||||
virtual ~Daemon_Singleton();
|
virtual ~Daemon_Singleton();
|
||||||
|
|
||||||
|
bool IsService () const;
|
||||||
|
|
||||||
// d-pointer for httpServer, httpProxy, etc.
|
// d-pointer for httpServer, httpProxy, etc.
|
||||||
class Daemon_Singleton_Private;
|
class Daemon_Singleton_Private;
|
||||||
Daemon_Singleton_Private &d;
|
Daemon_Singleton_Private &d;
|
||||||
|
|
|
@ -74,7 +74,7 @@ namespace i2p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pidfile
|
// Pidfile
|
||||||
pidfile = i2p::util::filesystem::GetDataDir().string();
|
pidfile = IsService () ? "/var/run" : i2p::util::filesystem::GetDataDir().string();
|
||||||
pidfile.append("/i2pd.pid");
|
pidfile.append("/i2pd.pid");
|
||||||
pidFilehandle = open(pidfile.c_str(), O_RDWR | O_CREAT, 0600);
|
pidFilehandle = open(pidfile.c_str(), O_RDWR | O_CREAT, 0600);
|
||||||
if (pidFilehandle == -1)
|
if (pidFilehandle == -1)
|
||||||
|
|
|
@ -49,6 +49,7 @@ Options
|
||||||
* --httpport= - The http port to listen on
|
* --httpport= - The http port to listen on
|
||||||
* --log= - Enable or disable logging to file. 1 for yes, 0 for no.
|
* --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.
|
* --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.
|
* --unreachable= - 1 if router is declared as unreachable and works through introducers.
|
||||||
* --httpproxyport= - The port to listen on (HTTP Proxy)
|
* --httpproxyport= - The port to listen on (HTTP Proxy)
|
||||||
* --socksproxyport= - The port to listen on (SOCKS Proxy)
|
* --socksproxyport= - The port to listen on (SOCKS Proxy)
|
||||||
|
|
4
util.cpp
4
util.cpp
|
@ -168,13 +168,15 @@ namespace filesystem
|
||||||
// Windows < Vista: C:\Documents and Settings\Username\Application Data\i2pd
|
// Windows < Vista: C:\Documents and Settings\Username\Application Data\i2pd
|
||||||
// Windows >= Vista: C:\Users\Username\AppData\Roaming\i2pd
|
// Windows >= Vista: C:\Users\Username\AppData\Roaming\i2pd
|
||||||
// Mac: ~/Library/Application Support/i2pd
|
// Mac: ~/Library/Application Support/i2pd
|
||||||
// Unix: ~/.i2pd
|
// Unix: ~/.i2pd or /var/lib/i2pd is system=1
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// Windows
|
// Windows
|
||||||
char localAppData[MAX_PATH];
|
char localAppData[MAX_PATH];
|
||||||
SHGetFolderPath(NULL, CSIDL_APPDATA, 0, NULL, localAppData);
|
SHGetFolderPath(NULL, CSIDL_APPDATA, 0, NULL, localAppData);
|
||||||
return boost::filesystem::path(std::string(localAppData) + "\\i2pd");
|
return boost::filesystem::path(std::string(localAppData) + "\\i2pd");
|
||||||
#else
|
#else
|
||||||
|
if (i2p::util::config::GetArg("-service", 0)) // use system folder
|
||||||
|
return boost::filesystem::path("/var/lib/i2pd");
|
||||||
boost::filesystem::path pathRet;
|
boost::filesystem::path pathRet;
|
||||||
char* pszHome = getenv("HOME");
|
char* pszHome = getenv("HOME");
|
||||||
if (pszHome == NULL || strlen(pszHome) == 0)
|
if (pszHome == NULL || strlen(pszHome) == 0)
|
||||||
|
|
Loading…
Reference in a new issue