mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
QT doesn't depend on Linux daemon anymore
This commit is contained in:
parent
ff38a3bbfe
commit
70e502e55d
25
Daemon.h
25
Daemon.h
|
@ -3,10 +3,12 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#if defined(QT_GUI)
|
||||||
#define Daemon i2p::util::DaemonWin32::Instance()
|
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define Daemon i2p::util::DaemonLinux::Instance()
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
|
@ -36,7 +38,21 @@ namespace i2p
|
||||||
Daemon_Singleton_Private &d;
|
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
|
class DaemonWin32 : public Daemon_Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -52,6 +68,7 @@ namespace i2p
|
||||||
void run ();
|
void run ();
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
|
#define Daemon i2p::util::DaemonLinux::Instance()
|
||||||
class DaemonLinux : public Daemon_Singleton
|
class DaemonLinux : public Daemon_Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -74,11 +74,9 @@ namespace i2p
|
||||||
}
|
}
|
||||||
|
|
||||||
// point std{in,out,err} descriptors to /dev/null
|
// point std{in,out,err} descriptors to /dev/null
|
||||||
#ifndef ANDROID
|
|
||||||
stdin = freopen("/dev/null", "r", stdin);
|
stdin = freopen("/dev/null", "r", stdin);
|
||||||
stdout = freopen("/dev/null", "w", stdout);
|
stdout = freopen("/dev/null", "w", stdout);
|
||||||
stderr = freopen("/dev/null", "w", stderr);
|
stderr = freopen("/dev/null", "w", stderr);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pidfile
|
// Pidfile
|
||||||
|
@ -94,12 +92,7 @@ namespace i2p
|
||||||
LogPrint(eLogError, "Daemon: could not create pid file ", pidfile, ": ", strerror(errno));
|
LogPrint(eLogError, "Daemon: could not create pid file ", pidfile, ": ", strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#ifndef ANDROID
|
|
||||||
if (lockf(pidFH, F_TLOCK, 0) != 0)
|
if (lockf(pidFH, F_TLOCK, 0) != 0)
|
||||||
#else
|
|
||||||
//TODO ANDROID actually need to read man for this, blindly took a solution from <https://forum.qt.io/topic/27872/qtjsondb-build-failed-for-android/2>. -anon5
|
|
||||||
if (fcntl(pidFH, 1, 0) < 0)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
LogPrint(eLogError, "Daemon: could not lock pid file ", pidfile, ": ", strerror(errno));
|
LogPrint(eLogError, "Daemon: could not lock pid file ", pidfile, ": ", strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -365,7 +365,7 @@ namespace http {
|
||||||
s << " <a href=\"/?cmd=" << HTTP_COMMAND_STOP_ACCEPTING_TUNNELS << "\">Stop accepting tunnels</a><br>\r\n";
|
s << " <a href=\"/?cmd=" << HTTP_COMMAND_STOP_ACCEPTING_TUNNELS << "\">Stop accepting tunnels</a><br>\r\n";
|
||||||
else
|
else
|
||||||
s << " <a href=\"/?cmd=" << HTTP_COMMAND_START_ACCEPTING_TUNNELS << "\">Start accepting tunnels</a><br>\r\n";
|
s << " <a href=\"/?cmd=" << HTTP_COMMAND_START_ACCEPTING_TUNNELS << "\">Start accepting tunnels</a><br>\r\n";
|
||||||
#ifndef WIN32
|
#if (!defined(WIN32) && !defined(QT_GUI_LIB))
|
||||||
if (Daemon.gracefullShutdownInterval) {
|
if (Daemon.gracefullShutdownInterval) {
|
||||||
s << " <a href=\"/?cmd=" << HTTP_COMMAND_SHUTDOWN_CANCEL << "\">Cancel gracefull shutdown (";
|
s << " <a href=\"/?cmd=" << HTTP_COMMAND_SHUTDOWN_CANCEL << "\">Cancel gracefull shutdown (";
|
||||||
s << Daemon.gracefullShutdownInterval;
|
s << Daemon.gracefullShutdownInterval;
|
||||||
|
@ -678,12 +678,12 @@ namespace http {
|
||||||
i2p::context.SetAcceptsTunnels (false);
|
i2p::context.SetAcceptsTunnels (false);
|
||||||
else if (cmd == HTTP_COMMAND_SHUTDOWN_START) {
|
else if (cmd == HTTP_COMMAND_SHUTDOWN_START) {
|
||||||
i2p::context.SetAcceptsTunnels (false);
|
i2p::context.SetAcceptsTunnels (false);
|
||||||
#ifndef WIN32
|
#if (!defined(WIN32) && !defined(QT_GUI_LIB))
|
||||||
Daemon.gracefullShutdownInterval = 10*60;
|
Daemon.gracefullShutdownInterval = 10*60;
|
||||||
#endif
|
#endif
|
||||||
} else if (cmd == HTTP_COMMAND_SHUTDOWN_CANCEL) {
|
} else if (cmd == HTTP_COMMAND_SHUTDOWN_CANCEL) {
|
||||||
i2p::context.SetAcceptsTunnels (true);
|
i2p::context.SetAcceptsTunnels (true);
|
||||||
#ifndef WIN32
|
#if (!defined(WIN32) && !defined(QT_GUI_LIB))
|
||||||
Daemon.gracefullShutdownInterval = 0;
|
Daemon.gracefullShutdownInterval = 0;
|
||||||
#endif
|
#endif
|
||||||
} else if (cmd == HTTP_COMMAND_SHUTDOWN_NOW) {
|
} else if (cmd == HTTP_COMMAND_SHUTDOWN_NOW) {
|
||||||
|
|
|
@ -22,8 +22,6 @@ SOURCES += main.cpp\
|
||||||
../../BOB.cpp \
|
../../BOB.cpp \
|
||||||
../../ClientContext.cpp \
|
../../ClientContext.cpp \
|
||||||
../../Crypto.cpp \
|
../../Crypto.cpp \
|
||||||
../../DaemonLinux.cpp \
|
|
||||||
../../DaemonWin32.cpp \
|
|
||||||
../../Datagram.cpp \
|
../../Datagram.cpp \
|
||||||
../../Destination.cpp \
|
../../Destination.cpp \
|
||||||
../../Family.cpp \
|
../../Family.cpp \
|
||||||
|
|
|
@ -3,31 +3,20 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "../../Daemon.h"
|
#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[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
if (DaemonQT::Instance ().init(argc, argv))
|
if (Daemon.init(argc, argv))
|
||||||
{
|
{
|
||||||
if (DaemonQT::Instance ().start())
|
if (Daemon.start())
|
||||||
{
|
{
|
||||||
w.show();
|
w.show();
|
||||||
ret = a.exec();
|
ret = a.exec();
|
||||||
}
|
}
|
||||||
DaemonQT::Instance ().stop();
|
Daemon.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in a new issue