aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-09-28 16:12:14 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-09-28 16:12:14 +0000
commit09aad8d0adf1afd67f663d4d94cb8227f5596f98 (patch)
tree60929850321f9cd7fb5facc8266a422a0c616c1d
parent069308ce630fb41cb8435120926f50259b5d103f (diff)
downloadpaludis-09aad8d0adf1afd67f663d4d94cb8227f5596f98.tar.gz
paludis-09aad8d0adf1afd67f663d4d94cb8227f5596f98.tar.xz
Use sigaction rather than signal for signal handling. Do signal handling as part of ConsoleInstallTask
-rw-r--r--paludis/tasks/install_task.hh2
-rw-r--r--src/clients/contrarius/install.cc69
-rw-r--r--src/clients/paludis/install.cc69
-rw-r--r--src/output/console_install_task.cc55
-rw-r--r--src/output/console_install_task.hh2
5 files changed, 58 insertions, 139 deletions
diff --git a/paludis/tasks/install_task.hh b/paludis/tasks/install_task.hh
index ccb2b4c..d348613 100644
--- a/paludis/tasks/install_task.hh
+++ b/paludis/tasks/install_task.hh
@@ -190,7 +190,7 @@ namespace paludis
/**
* Run the task.
*/
- void execute();
+ virtual void execute();
/**
* Fetch our deplist.
diff --git a/src/clients/contrarius/install.cc b/src/clients/contrarius/install.cc
index ac3b4e1..55dd927 100644
--- a/src/clients/contrarius/install.cc
+++ b/src/clients/contrarius/install.cc
@@ -26,10 +26,6 @@
#include <limits>
#include <set>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
#include <paludis/tasks/install_task.hh>
#include <paludis/util/fd_output_stream.hh>
#include <paludis/util/log.hh>
@@ -136,71 +132,6 @@ namespace
}
}
};
-
- class InstallKilledCatcher
- {
- private:
- static const ConsoleInstallTask * _task;
-
- static tr1::shared_ptr<Environment> _env;
-
- static void _signal_handler(int sig) PALUDIS_ATTRIBUTE((noreturn));
-
- sig_t _old;
-
- public:
- InstallKilledCatcher(tr1::shared_ptr<Environment> env, const ConsoleInstallTask & task) :
- _old(signal(SIGINT, &InstallKilledCatcher::_signal_handler))
- {
- _task = &task;
- _env = env;
- }
-
- ~InstallKilledCatcher()
- {
- signal(SIGINT, _old);
- _task = 0;
- }
- };
-
- const ConsoleInstallTask * InstallKilledCatcher::_task(0);
- tr1::shared_ptr<Environment> InstallKilledCatcher::_env;
-
- void
- InstallKilledCatcher::_signal_handler(int sig)
- {
- // ignore further signals to avoid a race if
- // a sigal arrives while this handler hasn't finished
- signal(sig, SIG_IGN);
-
- static bool recursing(false);
-
- if (recursing)
- {
- cout << endl;
- cerr << "Caught signal " << sig << " inside signal" << endl;
- cerr << "NOT waiting for children any more..." << endl;
- cerr << endl;
- cerr << "Exiting with failure" << endl;
- exit(EXIT_FAILURE);
- }
- else
- {
- recursing = true;
-
- cout << endl;
- cerr << "Caught signal " << sig << endl;
- cerr << "Waiting for children..." << endl;
- while (-1 != wait(0))
- ;
- cerr << endl;
- if (_task)
- _task->show_resume_command();
- cerr << endl;
- cerr << "Exiting with failure" << endl;
- exit(EXIT_FAILURE);
- }
- }
}
int
diff --git a/src/clients/paludis/install.cc b/src/clients/paludis/install.cc
index 67ee442..912c40c 100644
--- a/src/clients/paludis/install.cc
+++ b/src/clients/paludis/install.cc
@@ -28,9 +28,7 @@
#include <cstdlib>
#include <cstring>
-#include <signal.h>
#include <sys/types.h>
-#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
@@ -248,71 +246,6 @@ namespace
}
};
- class InstallKilledCatcher
- {
- private:
- static const ConsoleInstallTask * _task;
-
- static tr1::shared_ptr<Environment> _env;
-
- static void _signal_handler(int sig) PALUDIS_ATTRIBUTE((noreturn));
-
- sig_t _old;
-
- public:
- InstallKilledCatcher(tr1::shared_ptr<Environment> env, const ConsoleInstallTask & task) :
- _old(signal(SIGINT, &InstallKilledCatcher::_signal_handler))
- {
- _task = &task;
- _env = env;
- }
-
- ~InstallKilledCatcher()
- {
- signal(SIGINT, _old);
- _task = 0;
- }
- };
-
- const ConsoleInstallTask * InstallKilledCatcher::_task(0);
- tr1::shared_ptr<Environment> InstallKilledCatcher::_env;
-
- void
- InstallKilledCatcher::_signal_handler(int sig)
- {
- // ignore further signals to avoid a race if
- // a sigal arrives while this handler hasn't finished
- signal(sig, SIG_IGN);
-
- static bool recursing(false);
-
- if (recursing)
- {
- cout << endl;
- cerr << "Caught signal " << sig << " inside signal" << endl;
- cerr << "NOT waiting for children any more..." << endl;
- cerr << endl;
- cerr << "Exiting with failure" << endl;
- exit(EXIT_FAILURE);
- }
- else
- {
- recursing = true;
-
- cout << endl;
- cerr << "Caught signal " << sig << endl;
- cerr << "Waiting for children..." << endl;
- while (-1 != wait(0))
- ;
- cerr << endl;
- if (_task)
- _task->show_resume_command();
- cerr << endl;
- cerr << "Exiting with failure" << endl;
- exit(EXIT_FAILURE);
- }
- }
-
DepListDepsOption
enum_arg_to_dep_list_deps_option(const args::EnumArg & arg)
{
@@ -577,8 +510,6 @@ do_install(tr1::shared_ptr<Environment> env)
throw args::DoHelp("bad value for --continue-on-failure");
}
- InstallKilledCatcher install_killed_catcher(env, task);
-
cout << "Building target list... " << std::flush;
for (CommandLine::ParametersConstIterator q(CommandLine::get_instance()->begin_parameters()),
q_end(CommandLine::get_instance()->end_parameters()) ; q != q_end ; ++q)
diff --git a/src/output/console_install_task.cc b/src/output/console_install_task.cc
index 82e1dfa..7164a18 100644
--- a/src/output/console_install_task.cc
+++ b/src/output/console_install_task.cc
@@ -26,6 +26,7 @@
#include <paludis/util/sr.hh>
#include <paludis/util/strip.hh>
#include <paludis/util/tokeniser.hh>
+#include <paludis/util/mutex.hh>
#include <paludis/util/join.hh>
#include <paludis/util/set-impl.hh>
#include <paludis/util/iterator.hh>
@@ -44,15 +45,45 @@
#include <algorithm>
#include <set>
+#include <list>
#include <iostream>
#include <iomanip>
#include <limits>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
using namespace paludis;
+using std::cout;
+using std::cerr;
using std::endl;
#include <src/output/console_install_task-sr.cc>
+namespace
+{
+ std::list<ConsoleInstallTask *> tasks;
+ Mutex tasks_mutex;
+
+ void sigterm_handler(int sig)
+ {
+ cout << endl;
+ cerr << "Caught signal " << sig << endl;
+ cerr << "Waiting for children..." << endl;
+ while (-1 != wait(0))
+ ;
+ cerr << endl;
+ {
+ Lock l(tasks_mutex);
+ if (! tasks.empty())
+ (*tasks.begin())->show_resume_command();
+ }
+ cerr << endl;
+ cerr << "Exiting with failure" << endl;
+ exit(EXIT_FAILURE);
+ }
+}
+
bool
UseDescriptionComparator::operator() (const UseDescription & lhs, const UseDescription & rhs) const
{
@@ -89,6 +120,30 @@ ConsoleInstallTask::ConsoleInstallTask(Environment * const env,
}
void
+ConsoleInstallTask::execute()
+{
+ struct sigaction act, oldact;
+ act.sa_handler = &sigterm_handler;
+ act.sa_flags = 0;
+ ::sigemptyset(&act.sa_mask);
+ ::sigaddset(&act.sa_mask, SIGTERM);
+
+ {
+ Lock l(tasks_mutex);
+ tasks.push_front(this);
+ ::sigaction(SIGTERM, &act, &oldact);
+ }
+
+ InstallTask::execute();
+
+ {
+ Lock l(tasks_mutex);
+ ::sigaction(SIGTERM, &oldact, 0);
+ tasks.remove(this);
+ }
+}
+
+void
ConsoleInstallTask::on_build_deplist_pre()
{
output_activity_start_message("Building dependency list");
diff --git a/src/output/console_install_task.hh b/src/output/console_install_task.hh
index d66a358..ddbc8aa 100644
--- a/src/output/console_install_task.hh
+++ b/src/output/console_install_task.hh
@@ -126,6 +126,8 @@ namespace paludis
tr1::shared_ptr<const DestinationsSet>);
public:
+ virtual void execute();
+
virtual std::string make_x_of_y(const int x, const int y, const int s, const int f);
virtual void on_build_deplist_pre();