diff --git a/Daemon.h b/Daemon.h index 6b154ee4..9f040683 100644 --- a/Daemon.h +++ b/Daemon.h @@ -3,10 +3,12 @@ #include -#ifdef _WIN32 -#define Daemon i2p::util::DaemonWin32::Instance() +#if defined(QT_GUI) + +#elif defined(_WIN32) + #else -#define Daemon i2p::util::DaemonLinux::Instance() + #endif namespace i2p @@ -36,7 +38,21 @@ namespace i2p Daemon_Singleton_Private &d; }; -#ifdef _WIN32 +#if defined(QT_GUI_LIB) // check if QT +#define Daemon i2p::util::DaemonQT::Instance() + class DaemonQT: public i2p::util::Daemon_Singleton + { + public: + + static DaemonQT& Instance() + { + static DaemonQT instance; + return instance; + } + }; + +#elif defined(_WIN32) +#define Daemon i2p::util::DaemonWin32::Instance() class DaemonWin32 : public Daemon_Singleton { public: @@ -52,6 +68,7 @@ namespace i2p void run (); }; #else +#define Daemon i2p::util::DaemonLinux::Instance() class DaemonLinux : public Daemon_Singleton { public: diff --git a/DaemonLinux.cpp b/DaemonLinux.cpp index 4aceff07..118fc5f5 100644 --- a/DaemonLinux.cpp +++ b/DaemonLinux.cpp @@ -74,11 +74,9 @@ namespace i2p } // point std{in,out,err} descriptors to /dev/null -#ifndef ANDROID stdin = freopen("/dev/null", "r", stdin); stdout = freopen("/dev/null", "w", stdout); stderr = freopen("/dev/null", "w", stderr); -#endif } // Pidfile @@ -94,12 +92,7 @@ namespace i2p LogPrint(eLogError, "Daemon: could not create pid file ", pidfile, ": ", strerror(errno)); return false; } -#ifndef ANDROID if (lockf(pidFH, F_TLOCK, 0) != 0) -#else - //TODO ANDROID actually need to read man for this, blindly took a solution from . -anon5 - if (fcntl(pidFH, 1, 0) < 0) -#endif { LogPrint(eLogError, "Daemon: could not lock pid file ", pidfile, ": ", strerror(errno)); return false; diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 5263c53d..dc504c58 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -365,7 +365,7 @@ namespace http { s << " Stop accepting tunnels
\r\n"; else s << " Start accepting tunnels
\r\n"; -#ifndef WIN32 +#if (!defined(WIN32) && !defined(QT_GUI_LIB)) if (Daemon.gracefullShutdownInterval) { s << " Cancel gracefull shutdown ("; s << Daemon.gracefullShutdownInterval; @@ -678,12 +678,12 @@ namespace http { i2p::context.SetAcceptsTunnels (false); else if (cmd == HTTP_COMMAND_SHUTDOWN_START) { i2p::context.SetAcceptsTunnels (false); -#ifndef WIN32 +#if (!defined(WIN32) && !defined(QT_GUI_LIB)) Daemon.gracefullShutdownInterval = 10*60; #endif } else if (cmd == HTTP_COMMAND_SHUTDOWN_CANCEL) { i2p::context.SetAcceptsTunnels (true); -#ifndef WIN32 +#if (!defined(WIN32) && !defined(QT_GUI_LIB)) Daemon.gracefullShutdownInterval = 0; #endif } else if (cmd == HTTP_COMMAND_SHUTDOWN_NOW) { diff --git a/qt/i2pd_qt/i2pd_qt.pro b/qt/i2pd_qt/i2pd_qt.pro index d1480522..cbde47b3 100644 --- a/qt/i2pd_qt/i2pd_qt.pro +++ b/qt/i2pd_qt/i2pd_qt.pro @@ -22,8 +22,6 @@ SOURCES += main.cpp\ ../../BOB.cpp \ ../../ClientContext.cpp \ ../../Crypto.cpp \ - ../../DaemonLinux.cpp \ - ../../DaemonWin32.cpp \ ../../Datagram.cpp \ ../../Destination.cpp \ ../../Family.cpp \ diff --git a/qt/i2pd_qt/main.cpp b/qt/i2pd_qt/main.cpp index e7978bfe..d00a7dbf 100644 --- a/qt/i2pd_qt/main.cpp +++ b/qt/i2pd_qt/main.cpp @@ -3,31 +3,20 @@ #include #include "../../Daemon.h" -class DaemonQT: public i2p::util::Daemon_Singleton -{ - public: - - static DaemonQT& Instance() - { - static DaemonQT instance; - return instance; - } -}; - int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; int ret = -1; - if (DaemonQT::Instance ().init(argc, argv)) + if (Daemon.init(argc, argv)) { - if (DaemonQT::Instance ().start()) + if (Daemon.start()) { w.show(); ret = a.exec(); } - DaemonQT::Instance ().stop(); + Daemon.stop(); } return ret;