]> git.lyx.org Git - lyx.git/blobdiff - src/support/ForkedCalls.cpp
an example for the sweave module, prepared by Gregor Gorjanc
[lyx.git] / src / support / ForkedCalls.cpp
index dcc2c3dd3428cdf975cfe87e9f4e9a36d59e3678..d1f6c35738f28454bee6b5dbfccbaefe68079a1a 100644 (file)
@@ -108,6 +108,9 @@ ForkedProcess::ForkedProcess()
 {}
 
 
+bool ForkedProcess::IAmAChild = false;
+
+
 void ForkedProcess::emitSignal()
 {
        if (signal_.get()) {
@@ -123,6 +126,10 @@ int ForkedProcess::run(Starttype type)
        pid_ = generateChild();
        if (pid_ <= 0) { // child or fork failed.
                retval_ = 1;
+               if (pid_ == 0)
+                       //we also do this in fork(), too, but maybe someone will try
+                       //to bypass that
+                       IAmAChild = true; 
                return retval_;
        }
 
@@ -184,6 +191,18 @@ void ForkedProcess::kill(int tol)
 }
 
 
+pid_t ForkedProcess::fork() {
+#if !defined (HAVE_FORK)
+       return -1;
+#else
+       pid_t pid = ::fork();
+       if (pid == 0)
+               IAmAChild = true;
+       return pid;
+#endif
+}
+
+
 // Wait for child process to finish. Returns returncode from child.
 int ForkedProcess::waitForChild()
 {
@@ -425,8 +444,8 @@ void callNext()
        // Bind our chain caller
        pro.second->connect(boost::bind(&ForkedCallQueue::callback, _1, _2));
        ForkedCall call;
-       // If we fail to fork the process, then emit the signal
-       // to tell the outside world that it failed.
+       //If we fail to fork the process, then emit the signal
+       //to tell the outside world that it failed.
        if (call.startScript(pro.first, pro.second) > 0)
                pro.second->operator()(0,1);
 }