]> git.lyx.org Git - lyx.git/commitdiff
Angus' fix to make pclose work again:
authorJürgen Spitzmüller <spitz@lyx.org>
Mon, 5 Apr 2004 06:46:22 +0000 (06:46 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Mon, 5 Apr 2004 06:46:22 +0000 (06:46 +0000)
block SIGCHLD during popen/pclose.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8596 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/ChangeLog
src/support/filetools.C

index 7f5ce3ba9ac89a81fa62cff53fd3c52f4fcc45c0..72452642072b8a496aee80a806a1f2f8941228c5 100644 (file)
@@ -1,3 +1,8 @@
+2004-04-05  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
+
+       * filetools.C (RunCommand): block SIGCHLD during popen/pclose
+       (actually Angus' fix).
+
 2004-04-01  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
 
        * filetools.C (DeleteAllFilesInDir): delete directories with
index 4a62faf65d0ae98e39daf36f00edd4bec0055d1b..0f09a962ad86e1c630f64b12851ec9b3fafdb19c 100644 (file)
@@ -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,31 @@ bool LyXReadLink(string const & file, string & link, bool resolve)
 
 cmd_ret const RunCommand(string const & cmd)
 {
+       // FIXME: replace all calls to RunCommand with ForkedCall 
+       // (if the output is not needed) or the code in ispell.C
+       // (if the output is needed).
+       
        // 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 +1206,12 @@ cmd_ret const RunCommand(string const & cmd)
                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);
 }