mirror of https://github.com/aria2/aria2
Set sa_mask when setting signal handler
parent
8e3ae3b76c
commit
61665d2c26
|
@ -129,6 +129,7 @@ void MultiUrlRequestInfo::printMessageForContinue()
|
|||
error_code::Value MultiUrlRequestInfo::execute()
|
||||
{
|
||||
error_code::Value returnValue = error_code::FINISHED;
|
||||
sigset_t mask;
|
||||
try {
|
||||
SharedHandle<rpc::WebSocketSessionMan> wsSessionMan;
|
||||
if(option_->getAsBool(PREF_ENABLE_RPC)) {
|
||||
|
@ -233,11 +234,22 @@ error_code::Value MultiUrlRequestInfo::execute()
|
|||
if(uriListParser_) {
|
||||
e->getRequestGroupMan()->setUriListParser(uriListParser_);
|
||||
}
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGINT);
|
||||
sigaddset(&mask, SIGTERM);
|
||||
#ifdef SIGHUP
|
||||
util::setGlobalSignalHandler(SIGHUP, handler, 0);
|
||||
sigaddset(&mask, SIGHUP);
|
||||
#endif // SIGHUP
|
||||
util::setGlobalSignalHandler(SIGINT, handler, 0);
|
||||
util::setGlobalSignalHandler(SIGTERM, handler, 0);
|
||||
#else // !HAVE_SIGACTION
|
||||
mask = 0;
|
||||
#endif // !HAVE_SIGACTION
|
||||
|
||||
#ifdef SIGHUP
|
||||
util::setGlobalSignalHandler(SIGHUP, &mask, handler, 0);
|
||||
#endif // SIGHUP
|
||||
util::setGlobalSignalHandler(SIGINT, &mask, handler, 0);
|
||||
util::setGlobalSignalHandler(SIGTERM, &mask, handler, 0);
|
||||
|
||||
e->getRequestGroupMan()->getNetStat().downloadStart();
|
||||
e->run();
|
||||
|
@ -284,11 +296,15 @@ error_code::Value MultiUrlRequestInfo::execute()
|
|||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
SingletonHolder<Notifier>::instance(0);
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigemptyset(&mask);
|
||||
#endif // HAVE_SIGACTION
|
||||
#ifdef SIGHUP
|
||||
util::setGlobalSignalHandler(SIGHUP, SIG_DFL, 0);
|
||||
util::setGlobalSignalHandler(SIGHUP, &mask, SIG_DFL, 0);
|
||||
#endif // SIGHUP
|
||||
util::setGlobalSignalHandler(SIGINT, SIG_DFL, 0);
|
||||
util::setGlobalSignalHandler(SIGTERM, SIG_DFL, 0);
|
||||
util::setGlobalSignalHandler(SIGINT, &mask, SIG_DFL, 0);
|
||||
util::setGlobalSignalHandler(SIGTERM, &mask, SIG_DFL, 0);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
|
11
src/main.cc
11
src/main.cc
|
@ -213,14 +213,19 @@ error_code::Value main(int argc, char* argv[])
|
|||
std::string iface = op->get(PREF_INTERFACE);
|
||||
SocketCore::bindAddress(iface);
|
||||
}
|
||||
|
||||
sigset_t mask;
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigemptyset(&mask);
|
||||
#else // !HAVE_SIGACTION
|
||||
mask = 0;
|
||||
#endif // !HAVE_SIGACTION
|
||||
#ifdef SIGPIPE
|
||||
util::setGlobalSignalHandler(SIGPIPE, SIG_IGN, 0);
|
||||
util::setGlobalSignalHandler(SIGPIPE, &mask, SIG_IGN, 0);
|
||||
#endif
|
||||
#ifdef SIGCHLD
|
||||
// Avoid to create zombie process when forked child processes are
|
||||
// died.
|
||||
util::setGlobalSignalHandler(SIGCHLD, SIG_IGN, 0);
|
||||
util::setGlobalSignalHandler(SIGCHLD, &mask, SIG_IGN, 0);
|
||||
#endif // SIGCHILD
|
||||
std::vector<SharedHandle<RequestGroup> > requestGroups;
|
||||
SharedHandle<UriListParser> uriListParser;
|
||||
|
|
|
@ -1221,12 +1221,13 @@ bool isNumericHost(const std::string& name)
|
|||
return true;
|
||||
}
|
||||
|
||||
void setGlobalSignalHandler(int sig, void (*handler)(int), int flags) {
|
||||
void setGlobalSignalHandler(int sig, sigset_t* mask, void (*handler)(int),
|
||||
int flags) {
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction sigact;
|
||||
sigact.sa_handler = handler;
|
||||
sigact.sa_flags = flags;
|
||||
sigemptyset(&sigact.sa_mask);
|
||||
sigact.sa_mask = *mask;
|
||||
sigaction(sig, &sigact, NULL);
|
||||
#else
|
||||
signal(sig, handler);
|
||||
|
|
|
@ -63,6 +63,10 @@
|
|||
#include "DlAbortEx.h"
|
||||
#include "fmt.h"
|
||||
|
||||
#ifndef HAVE_SIGACTION
|
||||
# define sigset_t int
|
||||
#endif // HAVE_SIGACTION
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class Randomizer;
|
||||
|
@ -335,7 +339,8 @@ char toLowerChar(char c);
|
|||
|
||||
bool isNumericHost(const std::string& name);
|
||||
|
||||
void setGlobalSignalHandler(int signal, void (*handler)(int), int flags);
|
||||
void setGlobalSignalHandler(int signal, sigset_t* mask, void (*handler)(int),
|
||||
int flags);
|
||||
|
||||
std::string getHomeDir();
|
||||
|
||||
|
|
Loading…
Reference in New Issue