Browse Source

Merge pull request #1769 from AVAtarMod/sigtstp-patch-1

Add SIGTSTP, SIGCONT support
pull/1771/head
orignal 2 years ago committed by GitHub
parent
commit
3539ee9be6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 45
      daemon/UnixDaemon.cpp
  2. 16
      libi2pd/Config.cpp

45
daemon/UnixDaemon.cpp

@ -24,6 +24,7 @@
#include "Tunnel.h" #include "Tunnel.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "ClientContext.h" #include "ClientContext.h"
#include "Transports.h"
void handle_signal(int sig) void handle_signal(int sig)
{ {
@ -54,7 +55,15 @@ void handle_signal(int sig)
case SIGPIPE: case SIGPIPE:
LogPrint(eLogInfo, "SIGPIPE received"); LogPrint(eLogInfo, "SIGPIPE received");
break; break;
} case SIGTSTP:
LogPrint(eLogInfo, "Daemon: Got SIGTSTP, disconnecting from network...");
i2p::transport::transports.SetOnline(false);
break;
case SIGCONT:
LogPrint(eLogInfo, "Daemon: Got SIGCONT, restoring connection to network...");
i2p::transport::transports.SetOnline(true);
break;
}
} }
namespace i2p namespace i2p
@ -171,19 +180,27 @@ namespace i2p
} }
gracefulShutdownInterval = 0; // not specified gracefulShutdownInterval = 0; // not specified
// Signal handler // handle signal TSTP
struct sigaction sa; bool handleTSTP; i2p::config::GetOption("unix.handle_sigtstp", handleTSTP);
sa.sa_handler = handle_signal;
sigemptyset(&sa.sa_mask); // Signal handler
sa.sa_flags = SA_RESTART; struct sigaction sa;
sigaction(SIGHUP, &sa, 0); sa.sa_handler = handle_signal;
sigaction(SIGUSR1, &sa, 0); sigemptyset(&sa.sa_mask);
sigaction(SIGABRT, &sa, 0); sa.sa_flags = SA_RESTART;
sigaction(SIGTERM, &sa, 0); sigaction(SIGHUP, &sa, 0);
sigaction(SIGINT, &sa, 0); sigaction(SIGUSR1, &sa, 0);
sigaction(SIGPIPE, &sa, 0); sigaction(SIGABRT, &sa, 0);
sigaction(SIGTERM, &sa, 0);
return Daemon_Singleton::start(); sigaction(SIGINT, &sa, 0);
sigaction(SIGPIPE, &sa, 0);
if (handleTSTP)
{
sigaction(SIGTSTP, &sa, 0);
sigaction(SIGCONT, &sa, 0);
}
return Daemon_Singleton::start();
} }
bool DaemonLinux::stop() bool DaemonLinux::stop()

16
libi2pd/Config.cpp

@ -311,6 +311,19 @@ namespace config {
("meshnets.yggaddress", value<std::string>()->default_value(""), "Yggdrasil address to publish") ("meshnets.yggaddress", value<std::string>()->default_value(""), "Yggdrasil address to publish")
; ;
#ifdef __linux__
options_description unix_specific("UNIX-specific options");
unix_specific.add_options()
("unix.handle_sigtstp", bool_switch()->default_value(false),
"Switch to offline mode if received signal TSTP (SIGTSTP)"
"(you can send it by pressing CTRL+Z in terminal or with"
" help commapnd kill and others, a.e pkill, if i2pd in "
"daemon mode). If you need to switch to online mode, send"
" signal CONT (SIGCONT)")
;
#endif
m_OptionsDesc m_OptionsDesc
.add(general) .add(general)
.add(limits) .add(limits)
@ -334,6 +347,9 @@ namespace config {
.add(persist) .add(persist)
.add(cpuext) .add(cpuext)
.add(meshnets) .add(meshnets)
#ifdef __linux__
.add(unix_specific)
#endif
; ;
} }

Loading…
Cancel
Save