aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/scoped_message_writer.h2
-rw-r--r--src/common/stack_trace.cpp15
-rw-r--r--src/common/util.cpp35
-rw-r--r--src/common/util.h4
5 files changed, 52 insertions, 5 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 808ef7630..f0df05b0d 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -78,7 +78,6 @@ monero_add_library(common
DEPENDS generate_translations_header)
target_link_libraries(common
PUBLIC
- epee
cncrypto
${UNBOUND_LIBRARY}
${LIBUNWIND_LIBRARIES}
diff --git a/src/common/scoped_message_writer.h b/src/common/scoped_message_writer.h
index d7517babb..d887a13c9 100644
--- a/src/common/scoped_message_writer.h
+++ b/src/common/scoped_message_writer.h
@@ -73,7 +73,7 @@ public:
#if defined(_MSC_VER)
, m_oss(std::move(rhs.m_oss))
#else
- // GCC bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316
+ // GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316
, m_oss(rhs.m_oss.str(), std::ios_base::out | std::ios_base::ate)
#endif
, m_color(std::move(rhs.m_color))
diff --git a/src/common/stack_trace.cpp b/src/common/stack_trace.cpp
index 9c2bf4b53..141621427 100644
--- a/src/common/stack_trace.cpp
+++ b/src/common/stack_trace.cpp
@@ -49,9 +49,18 @@
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "stacktrace"
-#define ST_LOG(x) CINFO(el::base::Writer,el::base::DispatchAction::FileOnlyLog,MONERO_DEFAULT_LOG_CATEGORY) << x
-
-// from http://stackoverflow.com/questions/11665829/how-can-i-print-stack-trace-for-caught-exceptions-in-c-code-injection-in-c
+#define ST_LOG(x) \
+ do { \
+ auto elpp = ELPP; \
+ if (elpp) { \
+ CINFO(el::base::Writer,el::base::DispatchAction::FileOnlyLog,MONERO_DEFAULT_LOG_CATEGORY) << x; \
+ } \
+ else { \
+ std::cout << x << std::endl; \
+ } \
+ } while(0)
+
+// from https://stackoverflow.com/questions/11665829/how-can-i-print-stack-trace-for-caught-exceptions-in-c-code-injection-in-c
// The decl of __cxa_throw in /usr/include/.../cxxabi.h uses
// 'std::type_info *', but GCC's built-in protype uses 'void *'.
diff --git a/src/common/util.cpp b/src/common/util.cpp
index 7d9d7b408..5e0d2726e 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -37,6 +37,7 @@
#ifdef __GLIBC__
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/resource.h>
#include <ustat.h>
#include <unistd.h>
#include <dirent.h>
@@ -682,6 +683,21 @@ std::string get_nix_version_display_string()
static void setup_crash_dump() {}
#endif
+ bool disable_core_dumps()
+ {
+#ifdef __GLIBC__
+ // disable core dumps in release mode
+ struct rlimit rlimit;
+ rlimit.rlim_cur = rlimit.rlim_max = 0;
+ if (setrlimit(RLIMIT_CORE, &rlimit))
+ {
+ MWARNING("Failed to disable core dumps");
+ return false;
+ }
+#endif
+ return true;
+ }
+
bool on_startup()
{
mlog_configure("", true);
@@ -919,4 +935,23 @@ std::string get_nix_version_display_string()
return {};
}
}
+
+ std::string glob_to_regex(const std::string &val)
+ {
+ std::string newval;
+
+ bool escape = false;
+ for (char c: val)
+ {
+ if (c == '*')
+ newval += escape ? "*" : ".*";
+ else if (c == '?')
+ newval += escape ? "?" : ".";
+ else if (c == '\\')
+ newval += '\\', escape = !escape;
+ else
+ newval += c;
+ }
+ return newval;
+ }
}
diff --git a/src/common/util.h b/src/common/util.h
index a57a85fee..8815232e2 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -149,6 +149,8 @@ namespace tools
bool sanitize_locale();
+ bool disable_core_dumps();
+
bool on_startup();
/*! \brief Defines a signal handler for win32 and *nix
@@ -231,4 +233,6 @@ namespace tools
bool is_hdd(const char *path);
boost::optional<std::pair<uint32_t, uint32_t>> parse_subaddress_lookahead(const std::string& str);
+
+ std::string glob_to_regex(const std::string &val);
}