From 971a9ac4e375f8e0a9242c4b3d819ce72b15b81a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Mon, 5 Apr 2004 06:46:22 +0000 Subject: [PATCH] Angus' fix to make pclose work again: 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 | 5 +++++ src/support/filetools.C | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 7f5ce3ba9a..7245264207 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,8 @@ +2004-04-05 Jürgen Spitzmüller + + * filetools.C (RunCommand): block SIGCHLD during popen/pclose + (actually Angus' fix). + 2004-04-01 Georg Baum * filetools.C (DeleteAllFilesInDir): delete directories with diff --git a/src/support/filetools.C b/src/support/filetools.C index 4a62faf65d..0f09a962ad 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -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); }