From a4c0fde6fd92f36edcafa15bcd420ccfd0c48981 Mon Sep 17 00:00:00 2001 From: Rye Mutt <rye@alchemyviewer.org> Date: Wed, 25 Dec 2024 02:39:24 -0500 Subject: [PATCH] LLSD<->json handling fixes from Extra --- indra/llcommon/llapp.cpp | 21 +++++++++++++-------- indra/llcommon/llsdjson.cpp | 25 +++++++++++++++++++------ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/indra/llcommon/llapp.cpp b/indra/llcommon/llapp.cpp index f53c74c4a3f..22fc7744795 100644 --- a/indra/llcommon/llapp.cpp +++ b/indra/llcommon/llapp.cpp @@ -678,6 +678,10 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *) // We do the somewhat sketchy operation of blocking in here until the error handler // has gracefully stopped the app. + // FIXME(brad) - we are using this handler for asynchronous signals as well, so sLogInSignal is currently + // disabled for safety. we need to find a way to selectively reenable it when it is safe. + // see issue secondlife/viewer#2566 + if (LLApp::sLogInSignal) { LL_INFOS() << "Signal handler - Got signal " << signum << " - " << apr_signal_description_get(signum) << LL_ENDL; @@ -687,9 +691,10 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *) switch (signum) { case SIGCHLD: + case SIGHUP: if (LLApp::sLogInSignal) { - LL_INFOS() << "Signal handler - Got SIGCHLD from " << info->si_pid << LL_ENDL; + LL_INFOS() << "Signal handler - Got SIGCHLD or SIGHUP from " << info->si_pid << LL_ENDL; } return; @@ -704,11 +709,10 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *) raise(signum); return; case SIGINT: - case SIGHUP: case SIGTERM: if (LLApp::sLogInSignal) { - LL_WARNS() << "Signal handler - Got SIGINT, HUP, or TERM, exiting gracefully" << LL_ENDL; + LL_WARNS() << "Signal handler - Got SIGINT, or TERM, exiting gracefully" << LL_ENDL; } // Graceful exit // Just set our state to quitting, not error @@ -755,6 +759,7 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *) { LL_WARNS() << "Signal handler - Handling fatal signal!" << LL_ENDL; } + if (LLApp::isError()) { // Received second fatal signal while handling first, just die right now @@ -792,11 +797,11 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *) clear_signals(); raise(signum); return; - } else { - if (LLApp::sLogInSignal) - { - LL_INFOS() << "Signal handler - Unhandled signal " << signum << ", ignoring!" << LL_ENDL; - } + } + + if (LLApp::sLogInSignal) + { + LL_INFOS() << "Signal handler - Unhandled signal " << signum << ", ignoring!" << LL_ENDL; } } } diff --git a/indra/llcommon/llsdjson.cpp b/indra/llcommon/llsdjson.cpp index 16ab2d5a453..542a3c26e34 100644 --- a/indra/llcommon/llsdjson.cpp +++ b/indra/llcommon/llsdjson.cpp @@ -26,11 +26,12 @@ // Must turn on conditional declarations in header file so definitions end up // with proper linkage. - +#define LLSD_DEBUG_INFO #include "linden_common.h" #include "llsdjson.h" +#include "llsdutil.h" #include "llerror.h" #include <boost/json/src.hpp> @@ -59,12 +60,21 @@ LLSD LlsdFromJson(const boost::json::value& val) result = LLSD(val.as_bool()); break; case boost::json::kind::array: + { result = LLSD::emptyArray(); - for (const auto &element : val.as_array()) + const boost::json::array& array = val.as_array(); + size_t size = array.size(); + // allocate elements 0 .. (size() - 1) to avoid incremental allocation + if (! array.empty()) { - result.append(LlsdFromJson(element)); + result[size - 1] = LLSD(); + } + for (size_t i = 0; i < size; i++) + { + result[i] = (LlsdFromJson(array[i])); } break; + } case boost::json::kind::object: result = LLSD::emptyMap(); for (const auto& element : val.as_object()) @@ -104,7 +114,8 @@ boost::json::value LlsdToJson(const LLSD &val) case LLSD::TypeMap: { boost::json::object& obj = result.emplace_object(); - for (const auto& llsd_dat : val.asMap()) + obj.reserve(val.size()); + for (const auto& llsd_dat : llsd::inMap(val)) { obj[llsd_dat.first] = LlsdToJson(llsd_dat.second); } @@ -113,7 +124,8 @@ boost::json::value LlsdToJson(const LLSD &val) case LLSD::TypeArray: { boost::json::array& json_array = result.emplace_array(); - for (const auto& llsd_dat : val.asArray()) + json_array.reserve(val.size()); + for (const auto& llsd_dat : llsd::inArray(val)) { json_array.push_back(LlsdToJson(llsd_dat)); } @@ -121,7 +133,8 @@ boost::json::value LlsdToJson(const LLSD &val) } case LLSD::TypeBinary: default: - LL_ERRS("LlsdToJson") << "Unsupported conversion to JSON from LLSD type (" << val.type() << ")." << LL_ENDL; + LL_ERRS("LlsdToJson") << "Unsupported conversion to JSON from LLSD type (" + << val.type() << ")." << LL_ENDL; break; } -- GitLab