Skip to content
Snippets Groups Projects
Commit a4c0fde6 authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

LLSD<->json handling fixes from Extra

parent 5b9e5426
No related branches found
No related tags found
No related merge requests found
...@@ -678,6 +678,10 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *) ...@@ -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 // We do the somewhat sketchy operation of blocking in here until the error handler
// has gracefully stopped the app. // 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) if (LLApp::sLogInSignal)
{ {
LL_INFOS() << "Signal handler - Got signal " << signum << " - " << apr_signal_description_get(signum) << LL_ENDL; 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 *) ...@@ -687,9 +691,10 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *)
switch (signum) switch (signum)
{ {
case SIGCHLD: case SIGCHLD:
case SIGHUP:
if (LLApp::sLogInSignal) 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; return;
...@@ -704,11 +709,10 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *) ...@@ -704,11 +709,10 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *)
raise(signum); raise(signum);
return; return;
case SIGINT: case SIGINT:
case SIGHUP:
case SIGTERM: case SIGTERM:
if (LLApp::sLogInSignal) 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 // Graceful exit
// Just set our state to quitting, not error // Just set our state to quitting, not error
...@@ -755,6 +759,7 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *) ...@@ -755,6 +759,7 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *)
{ {
LL_WARNS() << "Signal handler - Handling fatal signal!" << LL_ENDL; LL_WARNS() << "Signal handler - Handling fatal signal!" << LL_ENDL;
} }
if (LLApp::isError()) if (LLApp::isError())
{ {
// Received second fatal signal while handling first, just die right now // 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 *) ...@@ -792,11 +797,11 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *)
clear_signals(); clear_signals();
raise(signum); raise(signum);
return; return;
} else { }
if (LLApp::sLogInSignal)
{ if (LLApp::sLogInSignal)
LL_INFOS() << "Signal handler - Unhandled signal " << signum << ", ignoring!" << LL_ENDL; {
} LL_INFOS() << "Signal handler - Unhandled signal " << signum << ", ignoring!" << LL_ENDL;
} }
} }
} }
......
...@@ -26,11 +26,12 @@ ...@@ -26,11 +26,12 @@
// Must turn on conditional declarations in header file so definitions end up // Must turn on conditional declarations in header file so definitions end up
// with proper linkage. // with proper linkage.
#define LLSD_DEBUG_INFO
#include "linden_common.h" #include "linden_common.h"
#include "llsdjson.h" #include "llsdjson.h"
#include "llsdutil.h"
#include "llerror.h" #include "llerror.h"
#include <boost/json/src.hpp> #include <boost/json/src.hpp>
...@@ -59,12 +60,21 @@ LLSD LlsdFromJson(const boost::json::value& val) ...@@ -59,12 +60,21 @@ LLSD LlsdFromJson(const boost::json::value& val)
result = LLSD(val.as_bool()); result = LLSD(val.as_bool());
break; break;
case boost::json::kind::array: case boost::json::kind::array:
{
result = LLSD::emptyArray(); 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; break;
}
case boost::json::kind::object: case boost::json::kind::object:
result = LLSD::emptyMap(); result = LLSD::emptyMap();
for (const auto& element : val.as_object()) for (const auto& element : val.as_object())
...@@ -104,7 +114,8 @@ boost::json::value LlsdToJson(const LLSD &val) ...@@ -104,7 +114,8 @@ boost::json::value LlsdToJson(const LLSD &val)
case LLSD::TypeMap: case LLSD::TypeMap:
{ {
boost::json::object& obj = result.emplace_object(); 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); obj[llsd_dat.first] = LlsdToJson(llsd_dat.second);
} }
...@@ -113,7 +124,8 @@ boost::json::value LlsdToJson(const LLSD &val) ...@@ -113,7 +124,8 @@ boost::json::value LlsdToJson(const LLSD &val)
case LLSD::TypeArray: case LLSD::TypeArray:
{ {
boost::json::array& json_array = result.emplace_array(); 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)); json_array.push_back(LlsdToJson(llsd_dat));
} }
...@@ -121,7 +133,8 @@ boost::json::value LlsdToJson(const LLSD &val) ...@@ -121,7 +133,8 @@ boost::json::value LlsdToJson(const LLSD &val)
} }
case LLSD::TypeBinary: case LLSD::TypeBinary:
default: 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; break;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment