summaryrefslogtreecommitdiff
path: root/mteval/ns_ext.cc
diff options
context:
space:
mode:
authorChris Dyer <cdyer@allegro.clab.cs.cmu.edu>2014-03-20 12:47:17 -0400
committerChris Dyer <cdyer@allegro.clab.cs.cmu.edu>2014-03-20 12:47:17 -0400
commit3cfb30225123e56e7ba85f5c92c79c16ffff995f (patch)
treea3159cc1fd63acbfe0221061e05fbd6b7d8508a5 /mteval/ns_ext.cc
parent57767b8121f605b7e89e7a52c6d71be614399469 (diff)
fix crashes in mira
Diffstat (limited to 'mteval/ns_ext.cc')
-rw-r--r--mteval/ns_ext.cc45
1 files changed, 36 insertions, 9 deletions
diff --git a/mteval/ns_ext.cc b/mteval/ns_ext.cc
index 9d2c75c6..efe48afe 100644
--- a/mteval/ns_ext.cc
+++ b/mteval/ns_ext.cc
@@ -10,17 +10,49 @@
#include <iostream>
#include <cassert>
+#include "filelib.h"
#include "stringlib.h"
#include "tdict.h"
using namespace std;
+static volatile bool child_need_init = true;
+
void metric_child_signal_handler(int signo) {
int status = 0;
- cerr << "Received SIGCHLD(" << signo << ") ... aborting.\n";
+ string cmd;
+ {
+ ReadFile rf("/proc/self/cmdline");
+ if (rf) getline(*rf.stream(), cmd);
+ }
+ for (unsigned i = 0; i < cmd.size(); ++i)
+ if (cmd[i] == 0) cmd[i] = ' ';
+ cerr << "Received SIGCHLD(" << signo << ")\n";
+ if (cmd.size())
+ cerr << " Parent command line: " << cmd << endl;
+ else
+ cerr << " Parent command line not available!\n";
// reap zombies
- while (waitpid(-1, &status, WNOHANG) > 0) {}
- abort();
+ bool should_exit = false;
+ while (waitpid(-1, &status, WNOHANG) > 0) {
+ cerr << " Child status: " << status << (status ? " [FAILURE]" : " [OK]") << endl;
+ if (status) should_exit = true;
+ }
+ if (should_exit) {
+ cerr << "Exiting on account of non-zero child exit code...\n";
+ exit(1);
+ }
+}
+
+void setup_child_process_handler() {
+ if (child_need_init == true) {
+ child_need_init = false;
+ struct sigaction sa;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = SA_NOCLDSTOP;
+ sa.sa_handler = metric_child_signal_handler;
+ sigaction(SIGCHLD, &sa, NULL);
+ }
}
struct NScoreServer {
@@ -37,12 +69,7 @@ struct NScoreServer {
};
NScoreServer::NScoreServer(const string& cmd) {
- static bool need_init = true;
- if (need_init) {
- need_init = false;
- signal(SIGCHLD, metric_child_signal_handler);
- }
-
+ setup_child_process_handler();
cerr << "Invoking " << cmd << " ..." << endl;
if (pipe(p2c) < 0) { perror("pipe"); exit(1); }
if (pipe(c2p) < 0) { perror("pipe"); exit(1); }