diff options
author | tradke <tradke@83718e91-0e4f-0410-abf4-91180603181f> | 2006-07-27 14:31:18 +0000 |
---|---|---|
committer | tradke <tradke@83718e91-0e4f-0410-abf4-91180603181f> | 2006-07-27 14:31:18 +0000 |
commit | 4ca4d073b66b77072a19d8a72b021c30792793c6 (patch) | |
tree | 32b2d8e1efa68f31366cf1fdceba288a6450b99a | |
parent | 4a4304aa65d4aa2b92700aa90c10e99ed75e8a3a (diff) |
Use POSIX::sigaction for setting the SIGALRM handler to bypass the Perl
interpreter's signal handling which uses defered signals effectively
ignoring user-defined timeouts for some I/O functions (see 'man perlipc'
and then grep for 'Interrupting IO').
Check whether system ('perl script') exited due to SIGINT and, if so, raise(3)
that signal also in the simulation process in order to stop it.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@102 83718e91-0e4f-0410-abf4-91180603181f
-rw-r--r-- | src/rdf.cc | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -13,6 +13,7 @@ #include <list> #include <string> #include <sstream> +#include <signal.h> #include <unistd.h> @@ -395,6 +396,7 @@ namespace Formaline << endl << "use strict;" << endl << "use Socket;" << endl +<< "use POSIX;" << endl << endl << "my $input = '" << datafilename << "';" << endl << "my @hostlist = ("; @@ -420,7 +422,18 @@ namespace Formaline << endl << " # set a timeout for the entire interaction with this server" << endl << " eval {" << endl +// +// use POSIX::sigaction to bypass the Perl interpreter's signal handling +// which uses defered signals effectively ignoring user-defined timeouts +// for some I/O functions +// (see 'man perlipc' and then grep for 'Interrupting IO') +// +#if 1 +<< " POSIX::sigaction (SIGALRM, POSIX::SigAction->new (sub { die 'timeout' }))" << endl +<< " or die \"Error setting SIGALRM handler: $!\";" << endl +#else << " local $SIG{ALRM} = sub { die 'timeout' };" << endl +#endif << " alarm " << timeout << ";" << endl << endl << " my $iaddr = inet_aton ($host);" << endl @@ -608,6 +621,12 @@ namespace Formaline int const ierr = system (cmd); if (ierr != 0) { + // system(3) blocks SIGINT which otherwise would interrupt the simulation + // make sure that this is still so if a user types CTRL-C + if (WIFSIGNALED (ierr) and WTERMSIG (ierr) == SIGINT) { + raise (SIGINT); + } + static bool did_complain = false; if (! did_complain) { |