From 21722f538f1725a6a8df8262b37cf01d1e9564dd Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Tue, 8 Jan 2013 15:26:56 +0100 Subject: [PATCH] [Prevent] Fixes issues with exceptions thrown out of main scope. [Issue#] LINUXNGWAP-651 [Bug] Exceptions throwed out of main [Cause] N/A [Solution] Adding UNHANDLED_EXCEPTION_HANDLER_* marcoes [Verification] Build repository Change-Id: I72b9308a4f438d45e31118027ceb8d060b0e824c --- src/wrt-popup/ace/popup-bin/Popup.cpp | 260 +++++++++++++++++----------------- 1 file changed, 132 insertions(+), 128 deletions(-) diff --git a/src/wrt-popup/ace/popup-bin/Popup.cpp b/src/wrt-popup/ace/popup-bin/Popup.cpp index abc614f..16b0640 100644 --- a/src/wrt-popup/ace/popup-bin/Popup.cpp +++ b/src/wrt-popup/ace/popup-bin/Popup.cpp @@ -273,6 +273,8 @@ static void show_popup(struct ace_popup_data *pdp) { EAPI_MAIN int elm_main(int argc , char ** argv) { + UNHANDLED_EXCEPTION_HANDLER_BEGIN + { // int pipe_in and int pipe_out should be passed to Popup via args. // These parameters should be passed to Popup via pipe: @@ -282,149 +284,151 @@ elm_main(int argc , char ** argv) // ace_widget_handle_t handle // const ace_param_list_t param_list - try { - DPL::Log::LogSystemSingleton::Instance().SetTag("WRT-POPUP-BIN"); - } Catch(DPL::Exception) { - //cannot run logger - return ACE_INTERNAL_ERROR; - } - LogDebug("############################ popup binary ################################"); + try { + DPL::Log::LogSystemSingleton::Instance().SetTag("WRT-POPUP-BIN"); + } Catch(DPL::Exception) { + //cannot run logger + return ACE_INTERNAL_ERROR; + } + LogDebug("############################ popup binary ################################"); - if(argc < 3){ - LogError("To few args passed in exec to popup-bin - should be at least 3:"); - LogError("(binary-name, pipe_in, pipe_out)"); - LogError("return ACE_INTERNAL_ERROR"); - return ACE_INTERNAL_ERROR; - } - LogDebug("Passed args: " << argv[0] <<", " << argv[1] << ", " << argv[2]); + if(argc < 3){ + LogError("To few args passed in exec to popup-bin - should be at least 3:"); + LogError("(binary-name, pipe_in, pipe_out)"); + LogError("return ACE_INTERNAL_ERROR"); + return ACE_INTERNAL_ERROR; + } + LogDebug("Passed args: " << argv[0] <<", " << argv[1] << ", " << argv[2]); - int pipe_in; - int pipe_out; + int pipe_in; + int pipe_out; - // Parsing args (pipe_in, pipe_out) - if ( 0 == sscanf(argv[1], "%d", &pipe_in) ){ - LogError("Error while parsing pipe_in; return ACE_INTERNAL_ERROR"); - return ACE_INTERNAL_ERROR; - } - if ( 0 == sscanf(argv[2], "%d", &pipe_out) ){ - LogError("Error while parsing pipe_out; return ACE_INTERNAL_ERROR"); - return ACE_INTERNAL_ERROR; - } - LogDebug("Parsed pipes: IN: " << pipe_in <<", OUT: " << pipe_out); - - int buff_size = 1024; - char line[buff_size]; - - struct ace_popup_data pd; - struct ace_popup_data *pdp = &pd; - - pdp->popup = NULL; - - ssize_t count = 0; - time_t time_start; - time(&time_start); // now - double timeout = 10.0; - // try to read parameters from pipe_in - // timeout is set for 10 seconds - do { - count = TEMP_FAILURE_RETRY(read(pipe_in, line, buff_size)); - if ( timeout < difftime(time(NULL), time_start) ) { - LogError("Timeout reached! Exit popup - ACE_INTERNAL_ERROR"); + // Parsing args (pipe_in, pipe_out) + if ( 0 == sscanf(argv[1], "%d", &pipe_in) ){ + LogError("Error while parsing pipe_in; return ACE_INTERNAL_ERROR"); + return ACE_INTERNAL_ERROR; + } + if ( 0 == sscanf(argv[2], "%d", &pipe_out) ){ + LogError("Error while parsing pipe_out; return ACE_INTERNAL_ERROR"); + return ACE_INTERNAL_ERROR; + } + LogDebug("Parsed pipes: IN: " << pipe_in <<", OUT: " << pipe_out); + + int buff_size = 1024; + char line[buff_size]; + + struct ace_popup_data pd; + struct ace_popup_data *pdp = &pd; + + pdp->popup = NULL; + + ssize_t count = 0; + time_t time_start; + time(&time_start); // now + double timeout = 10.0; + // try to read parameters from pipe_in + // timeout is set for 10 seconds + do { + count = TEMP_FAILURE_RETRY(read(pipe_in, line, buff_size)); + if ( timeout < difftime(time(NULL), time_start) ) { + LogError("Timeout reached! Exit popup - ACE_INTERNAL_ERROR"); + close(pipe_in); + close(pipe_out); + return ACE_INTERNAL_ERROR; + } + } while (0 == count); + if(count < 0){ close(pipe_in); close(pipe_out); + LogError("read returned a negative value (" << count <<")"); + LogError("errno: " << strerror( errno ) ); + LogError("Exit popup - ACE_INTERNAL_ERROR"); + return ACE_INTERNAL_ERROR; + } + LogDebug("Read bytes : " << count << " (in " << difftime(time_start, time(NULL)) << " seconds)"); + close(pipe_in); // cleanup + + Wrt::Popup::BinaryStream stream; + stream.Write(count, static_cast (line)); + int popup_type = ACE_ONESHOT; + std::string resource_name_str; + std::string session_id_str; + int handle = 0; + + LogDebug("------- Deserialization -------"); + // Deserialization order: + // popup_type, resource_name, session_id, handle, param_list + + DPL::Deserialization::Deserialize(stream, popup_type); + LogDebug("popup_type_int : " << popup_type); + pdp->popup_type = static_cast (popup_type); + + DPL::Deserialization::Deserialize(stream, resource_name_str); + LogDebug("resource_name_char : " << resource_name_str.c_str()); + pdp->resource_name = + strdup(const_cast (resource_name_str.c_str())); + + DPL::Deserialization::Deserialize(stream, session_id_str); + LogDebug("session_id_char : " << session_id_str.c_str()); + pdp->session_id = + strdup(const_cast (session_id_str.c_str())); + + DPL::Deserialization::Deserialize(stream, handle); + LogDebug("handle_int : " << handle); + pdp->handle = static_cast (handle); + + if(_ace_params_deserializer(&(pdp->param_list), &stream)){ return ACE_INTERNAL_ERROR; } - } while (0 == count); - if(count < 0){ - close(pipe_in); - close(pipe_out); - LogError("read returned a negative value (" << count <<")"); - LogError("errno: " << strerror( errno ) ); - LogError("Exit popup - ACE_INTERNAL_ERROR"); - return ACE_INTERNAL_ERROR; - } - LogDebug("Read bytes : " << count << " (in " << difftime(time_start, time(NULL)) << " seconds)"); - close(pipe_in); // cleanup - - Wrt::Popup::BinaryStream stream; - stream.Write(count, static_cast (line)); - int popup_type = ACE_ONESHOT; - std::string resource_name_str; - std::string session_id_str; - int handle = 0; - - LogDebug("------- Deserialization -------"); - // Deserialization order: - // popup_type, resource_name, session_id, handle, param_list - - DPL::Deserialization::Deserialize(stream, popup_type); - LogDebug("popup_type_int : " << popup_type); - pdp->popup_type = static_cast (popup_type); - - DPL::Deserialization::Deserialize(stream, resource_name_str); - LogDebug("resource_name_char : " << resource_name_str.c_str()); - pdp->resource_name = - strdup(const_cast (resource_name_str.c_str())); - - DPL::Deserialization::Deserialize(stream, session_id_str); - LogDebug("session_id_char : " << session_id_str.c_str()); - pdp->session_id = - strdup(const_cast (session_id_str.c_str())); - - DPL::Deserialization::Deserialize(stream, handle); - LogDebug("handle_int : " << handle); - pdp->handle = static_cast (handle); - - if(_ace_params_deserializer(&(pdp->param_list), &stream)){ - return ACE_INTERNAL_ERROR; - } - pdp->per_session = EINA_FALSE; - pdp->always = EINA_FALSE; - pdp->validation_return = ACE_ACE_UNKNOWN_ERROR; + pdp->per_session = EINA_FALSE; + pdp->always = EINA_FALSE; + pdp->validation_return = ACE_ACE_UNKNOWN_ERROR; - show_popup(pdp); // Showing popup + show_popup(pdp); // Showing popup - // sending validation_result to popup-runner - Wrt::Popup::BinaryStream stream_out; + // sending validation_result to popup-runner + Wrt::Popup::BinaryStream stream_out; - LogDebug("pdp->validation_result : " << pdp->validation_result); - int validation_result_int = (int) pdp->validation_result; - LogDebug("validation_result_int : " << validation_result_int); - DPL::Serialization::Serialize(stream_out, validation_result_int); - if(-1 == TEMP_FAILURE_RETRY(write(pipe_out, stream_out.char_pointer(), stream_out.size()))){ - LogError("Write to pipe failed!"); + LogDebug("pdp->validation_result : " << pdp->validation_result); + int validation_result_int = (int) pdp->validation_result; + LogDebug("validation_result_int : " << validation_result_int); + DPL::Serialization::Serialize(stream_out, validation_result_int); + if(-1 == TEMP_FAILURE_RETRY(write(pipe_out, stream_out.char_pointer(), stream_out.size()))){ + LogError("Write to pipe failed!"); + close(pipe_out); + return ACE_INTERNAL_ERROR; + } close(pipe_out); - return ACE_INTERNAL_ERROR; - } - close(pipe_out); - if (pdp->validation_return == ACE_OK) { - LogDebug("ACE_OK"); - } - else if (pdp->validation_return == ACE_INVALID_ARGUMENTS) { - LogError("ACE_INVALID_ARGUMENTS"); - } - else if (pdp->validation_return == ACE_INTERNAL_ERROR) { - LogError("ACE_INTERNAL_ERROR"); - } - else if (pdp->validation_return == ACE_ACE_UNKNOWN_ERROR) { - LogError("ACE_ACE_UNKNOWN_ERROR"); - } - else { - LogError("Really unknown error!!!"); - } + if (pdp->validation_return == ACE_OK) { + LogDebug("ACE_OK"); + } + else if (pdp->validation_return == ACE_INVALID_ARGUMENTS) { + LogError("ACE_INVALID_ARGUMENTS"); + } + else if (pdp->validation_return == ACE_INTERNAL_ERROR) { + LogError("ACE_INTERNAL_ERROR"); + } + else if (pdp->validation_return == ACE_ACE_UNKNOWN_ERROR) { + LogError("ACE_ACE_UNKNOWN_ERROR"); + } + else { + LogError("Really unknown error!!!"); + } - LogDebug("############################ /popup binary ################################"); + LogDebug("############################ /popup binary ################################"); - // Shutdown elementary - //LogDebug("elm_shutdown()"); - //elm_shutdown(); - // This is commented because, it causes that popup exits with 139 code (Segmentatation violation). - // Not calling elm_shutdown() should not have any negative consequences because this binary ends - // in next line, and system should clear the memory. + // Shutdown elementary + //LogDebug("elm_shutdown()"); + //elm_shutdown(); + // This is commented because, it causes that popup exits with 139 code (Segmentatation violation). + // Not calling elm_shutdown() should not have any negative consequences because this binary ends + // in next line, and system should clear the memory. - _ace_params_finalize(&(pdp->param_list)); - return pdp->validation_return; + _ace_params_finalize(&(pdp->param_list)); + return pdp->validation_return; + } + UNHANDLED_EXCEPTION_HANDLER_END } ELM_MAIN() -- 2.7.4