From 74fcaf63192f8a20c008dc65d464725c65acddc1 Mon Sep 17 00:00:00 2001 From: Andrzej Surdej Date: Thu, 18 Apr 2013 16:37:13 +0200 Subject: [PATCH] Popup process fix. [Issue#] N/A [Problem] When fork process is created but, exec() return fail, the process crash and writes nothing to pipe. As result the caller process hangs. [Cause] N/A [Solution] Write data to pipe (deny and do not remember). [SCMRequest] N/A Change-Id: Ibd47e586790608972d45b7e80805ad15b0b4503b --- src/wrt-popup/wrt/popup-bin/InfoPopup.cpp | 1 + src/wrt-popup/wrt/popup-bin/YesNoCheckPopup.cpp | 1 + src/wrt-popup/wrt/popup-bin/YesNoPopup.cpp | 1 + src/wrt-popup/wrt/popup-runner/PopupInvoker.cpp | 83 +++++++++++++++++-------- 4 files changed, 59 insertions(+), 27 deletions(-) diff --git a/src/wrt-popup/wrt/popup-bin/InfoPopup.cpp b/src/wrt-popup/wrt/popup-bin/InfoPopup.cpp index faa3807..4536350 100644 --- a/src/wrt-popup/wrt/popup-bin/InfoPopup.cpp +++ b/src/wrt-popup/wrt/popup-bin/InfoPopup.cpp @@ -69,6 +69,7 @@ void InfoPopup::show(DPL::BinaryQueueAutoPtr data, WrtPopup* parent) void InfoPopup::responseCallback(const Renderer::AnswerCallbackData &answer) { DPL::BinaryQueue retValue; + PopupSerializer::appendArg(true, retValue); PopupSerializer::appendArg(answer.buttonAnswer, retValue); m_parent->response(retValue); } diff --git a/src/wrt-popup/wrt/popup-bin/YesNoCheckPopup.cpp b/src/wrt-popup/wrt/popup-bin/YesNoCheckPopup.cpp index ea743a6..7cdbf73 100644 --- a/src/wrt-popup/wrt/popup-bin/YesNoCheckPopup.cpp +++ b/src/wrt-popup/wrt/popup-bin/YesNoCheckPopup.cpp @@ -41,6 +41,7 @@ void YesNoCheckPopup::responseCallback( { bool result = (POPUP_YES_VALUE == answer.buttonAnswer); DPL::BinaryQueue retValue; + PopupSerializer::appendArg(true, retValue); PopupSerializer::appendArg(result, retValue); LogDebug("Check state: " << answer.chackState); PopupSerializer::appendArg(answer.chackState, retValue); diff --git a/src/wrt-popup/wrt/popup-bin/YesNoPopup.cpp b/src/wrt-popup/wrt/popup-bin/YesNoPopup.cpp index f2953a8..a47d205 100644 --- a/src/wrt-popup/wrt/popup-bin/YesNoPopup.cpp +++ b/src/wrt-popup/wrt/popup-bin/YesNoPopup.cpp @@ -51,6 +51,7 @@ void YesNoPopup::responseCallback(const Renderer::AnswerCallbackData &answer) { bool result = (POPUP_YES_VALUE == answer.buttonAnswer); DPL::BinaryQueue retValue; + PopupSerializer::appendArg(true, retValue); PopupSerializer::appendArg(result, retValue); m_parent->response(retValue); } diff --git a/src/wrt-popup/wrt/popup-runner/PopupInvoker.cpp b/src/wrt-popup/wrt/popup-runner/PopupInvoker.cpp index 28f32a1..16cbace 100644 --- a/src/wrt-popup/wrt/popup-runner/PopupInvoker.cpp +++ b/src/wrt-popup/wrt/popup-runner/PopupInvoker.cpp @@ -84,17 +84,24 @@ bool PopupInvoker::askYesNo(const std::string& title, //Result from popup application is available. Read it. DPL::BinaryQueueAutoPtr resultData = m_input.Read(std::numeric_limits::max()); - const int result = PopupSerializer::getIntArg(*resultData); + const int success = PopupSerializer::getIntArg(*resultData); + bool retVal = false; + if (success) { + const int result = PopupSerializer::getIntArg(*resultData); - LogDebug("Popup result is: " << result); + LogDebug("Popup result is: " << result); - Assert(resultData->Empty()); + Assert(resultData->Empty()); + retVal = (!!result); + } else { + LogWarning("Failed to show popup."); + } tmp.Close(); m_input.Close(); m_output.Close(); - return (!!result); + return retVal; } Catch(DPL::Exception) { @@ -122,7 +129,12 @@ void PopupInvoker::showInfo(const std::string& title, m_output.Write(data, data.Size()); executePopup(); - + DPL::BinaryQueueAutoPtr resultData = + m_input.Read(std::numeric_limits::max()); + const int success = PopupSerializer::getIntArg(*resultData); + if (!success) { + LogWarning("Failed to show popup."); + } //ignore result tmp.Close(); @@ -157,29 +169,38 @@ PopupResponse PopupInvoker::askYesNoCheckbox(const std::string& title, //Result from popup application is available. Read it. DPL::BinaryQueueAutoPtr resultData = m_input.Read(std::numeric_limits::max()); - const int result = PopupSerializer::getIntArg(*resultData); - const int rememberResult = PopupSerializer::getIntArg(*resultData); - - LogDebug( - "Popup result is: " << result << " remeber: " << rememberResult); - - Assert(resultData->Empty()); - tmp.Close(); - m_input.Close(); - m_output.Close(); - - if (1 == result) { - if (rememberResult == 1) { - return YES_DO_REMEMBER; + const int success = PopupSerializer::getIntArg(*resultData); + if (success) { + const int result = PopupSerializer::getIntArg(*resultData); + const int rememberResult = PopupSerializer::getIntArg(*resultData); + + LogDebug( + "Popup result is: " << result << " remeber: " << rememberResult); + + Assert(resultData->Empty()); + tmp.Close(); + m_input.Close(); + m_output.Close(); + + if (1 == result) { + if (rememberResult == 1) { + return YES_DO_REMEMBER; + } else { + return YES_DONT_REMEMBER; + } } else { - return YES_DONT_REMEMBER; + if (rememberResult == 1) { + return NO_DO_REMEMBER; + } else { + return NO_DONT_REMEMBER; + } } } else { - if (rememberResult == 1) { - return NO_DO_REMEMBER; - } else { - return NO_DONT_REMEMBER; - } + LogWarning("Popup failed to execute."); + tmp.Close(); + m_input.Close(); + m_output.Close(); + return NO_DONT_REMEMBER; } } Catch(DPL::Exception) @@ -194,7 +215,7 @@ void PopupInvoker::executePopup() pid_t pid = fork(); if (pid == -1) { //error occured - LogError("Cannot display popup!"); + LogError("Failed to create popup process."); Assert(false); } if (pid == 0) { @@ -206,7 +227,15 @@ void PopupInvoker::executePopup() NULL); if (ret == -1) { //execl returns -1 on error - LogError("Cannot display popup!"); + LogError("Failed to set popup binary"); + //write something to pipe to unblock caller process + DPL::NamedOutputPipe errOut; + errOut.Open(m_inputName); + DPL::BinaryQueue data; + PopupSerializer::appendArg(false, data); + errOut.Write(data, data.Size()); + errOut.Close(); + Assert(false); } } -- 2.7.4