]> git.lyx.org Git - lyx.git/blobdiff - src/support/forkedcontr.C
* lyxfunctional.h: delete compare_memfun and helper classes
[lyx.git] / src / support / forkedcontr.C
index 9a35444df4340e57bb25edcfc71e86792fe2d9e4..07546eeee8d9ef37e3f50508afd1d7a418259a90 100644 (file)
 
 #include "forkedcontr.h"
 #include "forkedcall.h"
-#include "lyxfunctional.h"
 
 #include "debug.h"
 
+#include <boost/bind.hpp>
 #include <boost/iterator/indirect_iterator.hpp>
 
 #include <cerrno>
 #include <unistd.h>
 #include <sys/wait.h>
 
+using boost::bind;
+
 using std::endl;
+using std::equal_to;
 using std::find_if;
 
 using std::string;
@@ -163,6 +166,12 @@ extern "C"
 void child_handler(int)
 {
        ForkedcallsController & fcc = ForkedcallsController::get();
+
+       // Be safe
+       typedef vector<ForkedcallsController::Data>::size_type size_type;
+       if (size_type(fcc.current_child + 1) >= fcc.reaped_children.size())
+               return;
+
        ForkedcallsController::Data & store =
                fcc.reaped_children[++fcc.current_child];
        // Clean up the child process.
@@ -223,8 +232,9 @@ ForkedcallsController::iterator ForkedcallsController::find_pid(pid_t pid)
        iterator begin = boost::make_indirect_iterator(forkedCalls.begin());
        iterator end   = boost::make_indirect_iterator(forkedCalls.end());
        iterator it = find_if(begin, end,
-                             lyx::compare_memfun(&Forkedcall::pid, pid));
-
+                             bind(equal_to<pid_t>(),
+                                  bind(&Forkedcall::pid, _1),
+                                  pid));
        return it.base();
 }
 
@@ -255,13 +265,18 @@ void ForkedcallsController::handleCompletedProcesses()
                Data & store = reaped_children[i];
 
                if (store.pid == -1) {
-                       lyxerr << "LyX: Error waiting for child: "
-                              << strerror(errno) << endl;
+                       // Might happen perfectly innocently, eg as a result
+                       // of the system (3) call.
+                       if (errno)
+                               lyxerr << "LyX: Error waiting for child: "
+                                      << strerror(errno) << endl;
                        continue;
                }
 
                ListType::iterator it = find_pid(store.pid);
-               BOOST_ASSERT(it != forkedCalls.end());
+               if (it == forkedCalls.end())
+                       // Eg, child was run in blocking mode
+                       continue;
 
                ForkedProcess & child = *it->get();
                bool remove_it = false;