diff --git a/Daemon.cpp b/Daemon.cpp index 0b93732f..d03d6528 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -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); } diff --git a/Daemon.h b/Daemon.h index f8f98467..bfbdcaa0 100644 --- a/Daemon.h +++ b/Daemon.h @@ -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; diff --git a/DaemonLinux.cpp b/DaemonLinux.cpp index 530eb077..48a05031 100644 --- a/DaemonLinux.cpp +++ b/DaemonLinux.cpp @@ -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) diff --git a/README.md b/README.md index 8a2266ba..695986e9 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/util.cpp b/util.cpp index abbee790..cec68979 100644 --- a/util.cpp +++ b/util.cpp @@ -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)