Angus Leeming wrote: > We could probably get rid of all calls > to RunCommand (see below). However, for now, I think that we should > just fix the bug.
OK. I added a FIXME for now. > Could you see if adding this to RunCommand fixes the problem? It does. Shall I apply the attached? Thanks, Jürgen.
Index: src/support/filetools.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/filetools.C,v retrieving revision 1.180 diff -u -r1.180 filetools.C --- src/support/filetools.C 1 Apr 2004 21:03:52 -0000 1.180 +++ src/support/filetools.C 3 Apr 2004 16:39:48 -0000 @@ -28,6 +28,7 @@ #include "filetools.h" #include "lstrings.h" #include "FileInfo.h" +#include "forkedcontr.h" #include "path.h" #include "path_defines.h" #include "gettext.h" @@ -1172,17 +1173,30 @@ cmd_ret const RunCommand(string const & cmd) { + // FIXME: we should try and replace all calls + // to RunCommand with ForkedCall. + // One question is if we should use popen or // create our own popen based on fork, exec, pipe // of course the best would be to have a // pstream (process stream), with the // variants ipstream, opstream + sigset_t newMask, oldMask; + sigemptyset(&oldMask); + sigemptyset(&newMask); + sigaddset(&newMask, SIGCHLD); + + // Block the SIGCHLD signal. + sigprocmask(SIG_BLOCK, &newMask, &oldMask); + FILE * inf = ::popen(cmd.c_str(), os::popen_read_mode()); // (Claus Hentschel) Check if popen was succesful ;-) - if (!inf) + if (!inf) { return make_pair(-1, string()); + lyxerr << "RunCommand:: could not start child process" << endl; + } string ret; int c = fgetc(inf); @@ -1191,6 +1205,12 @@ c = fgetc(inf); } int const pret = pclose(inf); + if (pret == -1) + perror("RunCommand:: could not terminate child process"); + + // Unblock the SIGCHLD signal and restore the old mask. + sigprocmask(SIG_SETMASK, &oldMask, 0); + return make_pair(pret, ret); }