tdf#120676: don't send "processing done" when refused to process

After commit cf333a878ceed18d0343520a2c65be69fc433b1f, condition
RequestHandler::cProcessed is set regardless if the request was
processed in RequestHandler::ExecuteCmdLineRequests. This allows
PipeIpcThread::execute to avoid infinite wait for the condition
object that is never signaled. But this makes the latter function
to send PROCESSING_DONE to the calling process. So the secondary
process gets no hint that the request actually failed.

This change adds a boolean field to signal if the request really
was processed. In the case of refused processing (i.e., when
pGlobal.is() is false, or when !pGlobal->AreRequestsEnabled() is
true, like when shutting down), the secondary process would get
empty response to its request in PipeIpcThread::enable, instead
of expected PROCESSING_DONE, and thus the process will eventually
exit with non-0 error code, which would allow to detect this in
scripts.

Change-Id: Id91ea28025e3f3ab60c7049f02ed9fc226d2a654
Reviewed-on: https://gerrit.libreoffice.org/65610
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index 3b7ba46..2871072 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -980,6 +980,8 @@ bool IpcThread::process(OString const & arguments, bool * waitProcessed) {
            aCmdLineArgs->getCwdUrl());
        m_handler->cProcessed.reset();
        pRequest->pcProcessed = &m_handler->cProcessed;
        m_handler->mbSucces = false;
        pRequest->mpbSuccess = &m_handler->mbSucces;

        // Print requests are not dependent on the --invisible cmdline argument as they are
        // loaded with the "hidden" flag! So they are always checked.
@@ -1178,17 +1180,24 @@ void PipeIpcThread::execute()

            // we don't need the mutex any longer...
            aGuard.clear();
            bool bSuccess = true;
            // wait for processing to finish
            if (waitProcessed)
            {
                m_handler->cProcessed.wait();
            // processing finished, inform the requesting end:
            SAL_INFO("desktop.app", "writing <" << PROCESSING_DONE << ">");
            n = aStreamPipe.write(
                PROCESSING_DONE, SAL_N_ELEMENTS(PROCESSING_DONE));
                bSuccess = m_handler->mbSucces;
            }
            if (bSuccess)
            {
                // processing finished, inform the requesting end:
                SAL_INFO("desktop.app", "writing <" << PROCESSING_DONE << ">");
                n = aStreamPipe.write(PROCESSING_DONE, SAL_N_ELEMENTS(PROCESSING_DONE));
                // incl. terminating NUL
            if (n != SAL_N_ELEMENTS(PROCESSING_DONE)) {
                SAL_WARN("desktop.app", "short write: " << n);
                continue;
                if (n != SAL_N_ELEMENTS(PROCESSING_DONE))
                {
                    SAL_WARN("desktop.app", "short write: " << n);
                    continue;
                }
            }
        }
        else
@@ -1350,6 +1359,8 @@ bool RequestHandler::ExecuteCmdLineRequests(

        // Execute dispatch requests
        bShutdown = dispatchWatcher->executeDispatchRequests( aTempList, noTerminate);
        if (aRequest.mpbSuccess)
            *aRequest.mpbSuccess = true; // signal that we have actually succeeded
    }

    return bShutdown;
diff --git a/desktop/source/app/officeipcthread.hxx b/desktop/source/app/officeipcthread.hxx
index 4634aef..224f154 100644
--- a/desktop/source/app/officeipcthread.hxx
+++ b/desktop/source/app/officeipcthread.hxx
@@ -64,6 +64,7 @@ struct ProcessDocumentsRequest
    OUString aImageConversionType;
    std::vector< OUString > aInFilter;
    ::osl::Condition *pcProcessed;  // pointer condition to be set when the request has been processed
    bool* mpbSuccess = nullptr; // pointer to boolean receiving if the processing was successful
    bool bTextCat; // boolean flag indicating whether to dump text content to console
    bool bScriptCat; // boolean flag indicating whether to dump script content to console
};
@@ -91,6 +92,8 @@ class RequestHandler: public salhelper::SimpleReferenceObject

    /* condition to be set when the request has been processed */
    ::osl::Condition cProcessed;
    /* receives if the processing was successful (may be false e.g. when shutting down) */
    bool mbSucces = false;

    /* condition to be set when the main event loop is ready
       otherwise an error dialogs event loop could eat away