From ee94d45beac29512e06048ebbdf393591727a0e9 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Fri, 12 Feb 2016 15:46:06 +0100 Subject: [PATCH 01/12] Use fcntl instead of flock, this is more modern and better portable. --- lib/Basics/files.cpp | 53 ++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/lib/Basics/files.cpp b/lib/Basics/files.cpp index f964e940c3..5cc06f5e3f 100644 --- a/lib/Basics/files.cpp +++ b/lib/Basics/files.cpp @@ -1156,17 +1156,15 @@ int TRI_CreateLockFile(char const* filename) { } TRI_FreeString(TRI_CORE_MEM_ZONE, buf); - TRI_CLOSE(fd); - - // try to open pid file - fd = TRI_OPEN(filename, O_RDONLY | TRI_O_CLOEXEC); - - if (fd < 0) { - return TRI_set_errno(TRI_ERROR_SYS_ERROR); - } + + struct flock lock; + lock.l_start = 0; + lock.l_len = 0; + lock.l_type = F_WRLCK; + lock.l_whence = SEEK_SET; // try to lock pid file - rv = flock(fd, LOCK_EX); + rv = fcntl(fd, F_SETLK, &lock); if (rv == -1) { int res = TRI_set_errno(TRI_ERROR_SYS_ERROR); @@ -1237,19 +1235,20 @@ int TRI_VerifyLockFile(char const* filename) { sizeof(buffer)); // not really necessary, but this shuts up valgrind ssize_t n = TRI_READ(fd, buffer, sizeof(buffer)); - TRI_CLOSE(fd); - if (n < 0) { + TRI_CLOSE(fd); return TRI_ERROR_NO_ERROR; } // pid too long if (n == sizeof(buffer)) { + TRI_CLOSE(fd); return TRI_ERROR_NO_ERROR; } // file empty if (n == 0) { + TRI_CLOSE(fd); return TRI_ERROR_NO_ERROR; } @@ -1257,26 +1256,29 @@ int TRI_VerifyLockFile(char const* filename) { int res = TRI_errno(); if (res != TRI_ERROR_NO_ERROR) { + TRI_CLOSE(fd); return TRI_ERROR_NO_ERROR; } TRI_pid_t pid = fc; if (kill(pid, 0) == -1) { + TRI_CLOSE(fd); return TRI_ERROR_NO_ERROR; } + struct flock lock; - fd = TRI_OPEN(filename, O_RDONLY | TRI_O_CLOEXEC); + lock.l_start = 0; + lock.l_len = 0; + lock.l_type = F_WRLCK; + lock.l_whence = SEEK_SET; + // try to lock pid file + int canLock = fcntl(fd, F_SETLK, &lock); // Exclusive (write) lock - if (fd < 0) { - return TRI_ERROR_NO_ERROR; - } - - int canLock = flock(fd, LOCK_EX | LOCK_NB); - - // file was not yet be locked + // file was not yet locken; could be locked if (canLock == 0) { - flock(fd, LOCK_UN); + lock.l_type = F_UNLCK; + fcntl(fd, F_GETLK, &lock); TRI_CLOSE(fd); return TRI_ERROR_NO_ERROR; @@ -1286,7 +1288,7 @@ int TRI_VerifyLockFile(char const* filename) { TRI_CLOSE(fd); - LOG(WARN) << "flock on lockfile '" << filename << "' failed: " << TRI_errno_string(canLock); + LOG(WARN) << "fcntl on lockfile '" << filename << "' failed: " << TRI_errno_string(canLock); return TRI_ERROR_ARANGO_DATADIR_LOCKED; } @@ -1337,7 +1339,14 @@ int TRI_DestroyLockFile(char const* filename) { return TRI_ERROR_NO_ERROR; } - int res = flock(fd, LOCK_UN); + struct flock lock; + + lock.l_start = 0; + lock.l_len = 0; + lock.l_type = F_UNLCK; + lock.l_whence = SEEK_SET; + // relesae the lock + int res = fcntl(fd, F_GETLK, &lock); TRI_CLOSE(fd); if (res == 0) { From d85e19c902d59bffa163fcf982cd763e35cb8458 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Fri, 12 Feb 2016 15:47:31 +0100 Subject: [PATCH 02/12] Depending on which solaris version we compile at, these facilities can be unknown. --- lib/Basics/syslog_names.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Basics/syslog_names.h b/lib/Basics/syslog_names.h index 8386b87141..d1e585596e 100644 --- a/lib/Basics/syslog_names.h +++ b/lib/Basics/syslog_names.h @@ -51,10 +51,14 @@ CODE prioritynames[] = CODE facilitynames[] = { { "auth", LOG_AUTH }, + #ifdef LOG_AUTHPRIV { "authpriv", LOG_AUTHPRIV }, + #endif { "cron", LOG_CRON }, { "daemon", LOG_DAEMON }, + #ifdef LOG_FTP { "ftp", LOG_FTP }, + #endif { "kern", LOG_KERN }, { "lpr", LOG_LPR }, { "mail", LOG_MAIL }, From 1c8acea215f6a929913660da663da15c339a52ce Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Fri, 12 Feb 2016 15:52:04 +0100 Subject: [PATCH 03/12] On solaris we need to hide ERR... --- lib/Basics/Logger.h | 4 +++- lib/Basics/operating-system.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Basics/Logger.h b/lib/Basics/Logger.h index a7d02fa943..a50eff6c46 100644 --- a/lib/Basics/Logger.h +++ b/lib/Basics/Logger.h @@ -169,7 +169,9 @@ namespace arangodb { //////////////////////////////////////////////////////////////////////////////// /// @brief LogLevel //////////////////////////////////////////////////////////////////////////////// - +#ifdef TRI_UNDEF_ERR +#undef ERR +#endif enum class LogLevel { DEFAULT = 0, FATAL = 1, diff --git a/lib/Basics/operating-system.h b/lib/Basics/operating-system.h index a3081348b3..4bf95ed3ae 100644 --- a/lib/Basics/operating-system.h +++ b/lib/Basics/operating-system.h @@ -47,6 +47,8 @@ #define TRI_PLATFORM "solaris" +#define TRI_UNDEF_ERR 1 + #define TRI_HAVE_PSTACK 1 //////////////////////////////////////////////////////////////////////////////// From ce9ec761995042ac4ee9b056896245066ecce066 Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Fri, 12 Feb 2016 17:05:43 +0000 Subject: [PATCH 04/12] ENABLE_RELATIVE --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6d9d05c2a..f6d9f104a8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -235,6 +235,7 @@ if (USE_RELATIVE) set(TRI_SBINDIR_INSTALL "sbin") set(TRI_SBINDIR "${CMAKE_INSTALL_PREFIX}/sbin") endif () + add_definitions("-D_SYSCONFDIR_=\"${ETCDIR_ESCAPED}\"") else(USE_RELATIVE) # etcd ------------------------------- set(ETCDIR "" CACHE path "System configuration directory (defaults to prefix/etc)") @@ -254,6 +255,7 @@ else(USE_RELATIVE) file(TO_NATIVE_PATH "${ETCDIR_NATIVE}" ETCDIR_NATIVE) STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ETCDIR_ESCAPED "${ETCDIR_NATIVE}") endif() + add_definitions("-D_SYSCONFDIR_=\"${ETCDIR_ESCAPED}\"") # arango directories ----------------- # /var From 13cceddbcc5f319a457d60b276f8e41bb307dff8 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 12 Feb 2016 18:07:42 +0100 Subject: [PATCH 05/12] removed linenoise option --- CMakeLists.txt | 4 -- configure.ac | 20 +-------- lib/Basics/local-configuration.h.in | 6 --- lib/Basics/operating-system.h | 2 - lib/CMakeLists.txt | 1 - lib/Makefile.files | 5 --- lib/Utilities/DummyShell.cpp | 65 ----------------------------- lib/Utilities/DummyShell.h | 55 ------------------------ lib/Utilities/ShellBase.cpp | 17 +------- 9 files changed, 2 insertions(+), 173 deletions(-) delete mode 100644 lib/Utilities/DummyShell.cpp delete mode 100644 lib/Utilities/DummyShell.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3418ea6532..a76d21eaeb 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -517,10 +517,6 @@ endif () add_definitions("-DTRI_LIBEV_VERSION=\"${LIBEV_VERSION}\"") -# linenoise -------------------------------------------------------------------- -set(LINENOISE_VERSION "unknown" CACHE string "LINENOISE version") -option(USE_LINENOISE "User linenoise for editing command lines and command line histories" ON) - # Boost ------------------------------------------------------------------------ find_package(Boost 1.48 COMPONENTS unit_test_framework) diff --git a/configure.ac b/configure.ac index ce52949262..a3df43e807 100644 --- a/configure.ac +++ b/configure.ac @@ -614,28 +614,10 @@ AC_MSG_NOTICE([----------------------------------------------------------------- AC_MSG_NOTICE([CHECKING FOR CONSOLE SUPPORT]) AC_MSG_NOTICE([--------------------------------------------------------------------------------]) -CONSOLE_CPPFLAGS="" - -AC_ARG_ENABLE(console, - AS_HELP_STRING([--enable-console], [enable console support (default: linenoise)]), - tr_CONSOLE="$enableval", - tr_CONSOLE="linenoise" -) - -if test "$tr_CONSOLE" = "dummy"; then - LIB_INFO="$LIB_INFO|CONSOLE: dummy" -elif test "$tr_CONSOLE" = "linenoise"; then - LIB_INFO="$LIB_INFO|CONSOLE: linenoise" - CONSOLE_CPPFLAGS="-I${srcdir}/3rdParty/linenoise-ng/include -I${srcdir}/3rdParty/linenoise-ng/src -DTRI_HAVE_LINENOISE" -fi - -LIB_INFO="$LIB_INFO|CONSOLE_CPPFLAGS: ${CONSOLE_CPPFLAGS}" -LIB_INFO="$LIB_INFO|." +CONSOLE_CPPFLAGS="-I${srcdir}/3rdParty/linenoise-ng/include -I${srcdir}/3rdParty/linenoise-ng/src" AC_SUBST(CONSOLE_CPPFLAGS) -AM_CONDITIONAL(ENABLE_LINENOISE, test "x$tr_CONSOLE" = xlinenoise) - dnl ---------------------------------------------------------------------------- dnl tcmalloc dnl ---------------------------------------------------------------------------- diff --git a/lib/Basics/local-configuration.h.in b/lib/Basics/local-configuration.h.in index 910072bde6..aba4afa3a2 100644 --- a/lib/Basics/local-configuration.h.in +++ b/lib/Basics/local-configuration.h.in @@ -60,12 +60,6 @@ #undef TRI_ENABLE_FAILURE_TESTS -//////////////////////////////////////////////////////////////////////////////// -/// @brief enable linenoise -//////////////////////////////////////////////////////////////////////////////// - -#define TRI_HAVE_LINENOISE @TRI_HAVE_LINENOISE@ - //////////////////////////////////////////////////////////////////////////////// /// @brief enable tcmalloc //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/Basics/operating-system.h b/lib/Basics/operating-system.h index 4bf95ed3ae..94d22dea54 100644 --- a/lib/Basics/operating-system.h +++ b/lib/Basics/operating-system.h @@ -762,8 +762,6 @@ /// @brief available features //////////////////////////////////////////////////////////////////////////////// -#define TRI_HAVE_LINENOISE 1 - #define YY_NO_UNISTD_H 1 #define TRI_WIN32_CONSOLE 1 diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index de62167288..752525b8c6 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -148,7 +148,6 @@ add_library( Rest/InitializeRest.cpp Rest/SslInterface.cpp Rest/Version.cpp - Utilities/DummyShell.cpp Utilities/LineEditor.cpp Utilities/ScriptLoader.cpp Utilities/ShellBase.cpp diff --git a/lib/Makefile.files b/lib/Makefile.files index 85fe8bd6d0..311739c070 100644 --- a/lib/Makefile.files +++ b/lib/Makefile.files @@ -85,7 +85,6 @@ lib_libarango_a_SOURCES = \ lib/Rest/InitializeRest.cpp \ lib/Rest/SslInterface.cpp \ lib/Rest/Version.cpp \ - lib/Utilities/DummyShell.cpp \ lib/Utilities/LineEditor.cpp \ lib/Utilities/ScriptLoader.cpp \ lib/Utilities/ShellBase.cpp \ @@ -93,16 +92,12 @@ lib_libarango_a_SOURCES = \ lib/Zip/unzip.cpp \ lib/Zip/zip.cpp -if ENABLE_LINENOISE - lib_libarango_a_SOURCES += \ 3rdParty/linenoise-ng/src/linenoise.cpp \ 3rdParty/linenoise-ng/src/ConvertUTF.cpp \ 3rdParty/linenoise-ng/src/wcwidth.cpp \ lib/Utilities/LinenoiseShell.cpp -endif - lib_libarango_a_SOURCES += \ 3rdParty/velocypack/src/AttributeTranslator.cpp \ 3rdParty/velocypack/src/Builder.cpp \ diff --git a/lib/Utilities/DummyShell.cpp b/lib/Utilities/DummyShell.cpp deleted file mode 100644 index 0b6086bb77..0000000000 --- a/lib/Utilities/DummyShell.cpp +++ /dev/null @@ -1,65 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// DISCLAIMER -/// -/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany -/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is ArangoDB GmbH, Cologne, Germany -/// -/// @author Dr. Frank Celler -//////////////////////////////////////////////////////////////////////////////// - -#include "DummyShell.h" - -#include - -using namespace arangodb; - -DummyShell::DummyShell(std::string const& history, Completer* completer) - : ShellBase(history, completer) {} - -DummyShell::~DummyShell() { close(); } - -//////////////////////////////////////////////////////////////////////////////// -/// @brief line editor open -//////////////////////////////////////////////////////////////////////////////// - -bool DummyShell::open(bool) { - _state = STATE_OPENED; - return true; -} - -bool DummyShell::close() { - _state = STATE_CLOSED; - return true; -} - -void DummyShell::addHistory(std::string const&) {} - -bool DummyShell::writeHistory() { return true; } - -std::string DummyShell::getLine(std::string const& prompt, bool& eof) { - std::cout << prompt << std::flush; - - std::string line; - std::getline(std::cin, line); - - if (std::cin.eof()) { - eof = true; - return ""; - } - - return line; -} diff --git a/lib/Utilities/DummyShell.h b/lib/Utilities/DummyShell.h deleted file mode 100644 index d2dd87b7e5..0000000000 --- a/lib/Utilities/DummyShell.h +++ /dev/null @@ -1,55 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// DISCLAIMER -/// -/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany -/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is ArangoDB GmbH, Cologne, Germany -/// -/// @author Esteban Lombeyda -//////////////////////////////////////////////////////////////////////////////// - -#ifndef LIB_UTILITIES_DUMMY_SHELL_H -#define LIB_UTILITIES_DUMMY_SHELL_H 1 - -#include "ShellBase.h" - -namespace arangodb { -class Completer; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief DummyShell -//////////////////////////////////////////////////////////////////////////////// - -class DummyShell : public ShellBase { - public: - DummyShell(std::string const& history, Completer*); - - virtual ~DummyShell(); - - public: - bool open(bool autoComplete) override final; - - bool close() override final; - - void addHistory(std::string const&) override final; - - bool writeHistory() override final; - - std::string getLine(std::string const& prompt, bool& eof) override final; -}; -} - -#endif diff --git a/lib/Utilities/ShellBase.cpp b/lib/Utilities/ShellBase.cpp index 67fda9f627..6368e396de 100644 --- a/lib/Utilities/ShellBase.cpp +++ b/lib/Utilities/ShellBase.cpp @@ -26,11 +26,7 @@ #include "Basics/StringUtils.h" #include "Basics/files.h" #include "Utilities/Completer.h" -#include "Utilities/DummyShell.h" - -#if defined(TRI_HAVE_LINENOISE) #include "Utilities/LinenoiseShell.h" -#endif using namespace arangodb; using namespace arangodb::basics; @@ -41,18 +37,7 @@ using namespace arangodb::basics; ShellBase* ShellBase::buildShell(std::string const& history, Completer* completer) { - // no keyboard input. use low-level shell without fancy color codes - // and with proper pipe handling - - if (!isatty(STDIN_FILENO)) { - return new DummyShell(history, completer); - } else { -#if defined(TRI_HAVE_LINENOISE) - return new LinenoiseShell(history, completer); -#else - return new DummyShell(history, completer); // last resort! -#endif - } + return new LinenoiseShell(history, completer); } //////////////////////////////////////////////////////////////////////////////// From 2955f330067d67cd205ea1c5b381a8d8e5b19bec Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Fri, 12 Feb 2016 17:43:45 +0000 Subject: [PATCH 06/12] Checking C++11 features. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf01288686..d005d24309 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) # ArangoDB needs c++11 set(CMAKE_CXX_STANDARD 11) +include (CheckCXX11Features) # Need threads find_package(Threads REQUIRED) From 20aebf6cc00290d129700946d99b6c33ef2a0b44 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 12 Feb 2016 19:10:52 +0100 Subject: [PATCH 07/12] fix some Visual Studio 2015 errors --- lib/Basics/operating-system.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Basics/operating-system.h b/lib/Basics/operating-system.h index 94d22dea54..20b21c27df 100644 --- a/lib/Basics/operating-system.h +++ b/lib/Basics/operating-system.h @@ -687,10 +687,14 @@ //////////////////////////////////////////////////////////////////////////////// // .............................................................................. -// Visual Studio 2013 does not support noexcept +// Visual Studio 2013 does not support noexcept, higher versions do // .............................................................................. +// Is noexcept supported? +#if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 180021114 +#else #define noexcept throw() +#endif // .............................................................................. // This directive below suppresses warnings about 'inline' From b734e4c228bb29428a3b31b8729eec4067ae9841 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 12 Feb 2016 19:12:56 +0100 Subject: [PATCH 08/12] don't log to the same output multiple times --- .../ApplicationServer/ApplicationServer.cpp | 10 +- arangosh/ArangoShell/ArangoClient.cpp | 5 +- lib/Basics/Logger.cpp | 118 +++++++++++++----- lib/Basics/Logger.h | 3 +- 4 files changed, 95 insertions(+), 41 deletions(-) diff --git a/arangod/ApplicationServer/ApplicationServer.cpp b/arangod/ApplicationServer/ApplicationServer.cpp index 39578f959d..d6535bce8e 100644 --- a/arangod/ApplicationServer/ApplicationServer.cpp +++ b/arangod/ApplicationServer/ApplicationServer.cpp @@ -224,11 +224,11 @@ void ApplicationServer::setupLogging(bool threaded, bool daemon, } else { bool regularOut = false; - for (auto definition : _logOutput) { + for (auto const& definition : _logOutput) { regularOut = regularOut || definition == "+" || definition == "-"; } - for (auto definition : outputs) { + for (auto const& definition : outputs) { regularOut = regularOut || definition == "+" || definition == "-"; } @@ -245,8 +245,10 @@ void ApplicationServer::setupLogging(bool threaded, bool daemon, Logger::setLogLevel(levels); - for (auto definition : outputs) { - Logger::addAppender(definition, !ttyLogger, _logContentFilter); + std::unordered_set filenames; + + for (auto const& definition : outputs) { + Logger::addAppender(definition, !ttyLogger, _logContentFilter, filenames); } } diff --git a/arangosh/ArangoShell/ArangoClient.cpp b/arangosh/ArangoShell/ArangoClient.cpp index 55d6f8af28..75082e2f13 100644 --- a/arangosh/ArangoShell/ArangoClient.cpp +++ b/arangosh/ArangoShell/ArangoClient.cpp @@ -346,11 +346,12 @@ void ArangoClient::parse(ProgramOptions& options, Logger::setShowLineNumber(false); Logger::setShowThreadIdentifier(false); + std::unordered_set existingAppenders; if (_logOutput.empty()) { - Logger::addAppender("-", true, ""); + Logger::addAppender("-", true, "", existingAppenders); } else { for (auto& definition : _logOutput) { - Logger::addAppender(definition, true, ""); + Logger::addAppender(definition, true, "", existingAppenders); } } diff --git a/lib/Basics/Logger.cpp b/lib/Basics/Logger.cpp index 418c6be559..2fc6f2962b 100644 --- a/lib/Basics/Logger.cpp +++ b/lib/Basics/Logger.cpp @@ -42,6 +42,7 @@ #include #include "Basics/ConditionLocker.h" +#include "Basics/Exceptions.h" #include "Basics/MutexLocker.h" #include "Basics/StringUtils.h" #include "Basics/Thread.h" @@ -214,10 +215,8 @@ LogAppenderFile::LogAppenderFile(std::string const& filename, bool fatal2stderr, if (fd < 0) { std::cerr << "cannot write to file '" << filename << "'" << std::endl; - _filename = "+"; - _fd.store(STDERR_FILENO); - } else { - _fd.store(fd); + + THROW_ARANGO_EXCEPTION(TRI_ERROR_CANNOT_WRITE_FILE); } } } @@ -452,6 +451,79 @@ std::string LogAppenderSyslog::details() { #endif +//////////////////////////////////////////////////////////////////////////////// +/// @brief build an appender object +//////////////////////////////////////////////////////////////////////////////// + +static LogAppender* buildAppender(std::string const& output, bool fatal2stderr, + std::string const& contentFilter, + std::unordered_set& existingAppenders) { + // first handle syslog-logging +#ifdef TRI_ENABLE_SYSLOG + if (StringUtils::isPrefix(output, "syslog://")) { + auto s = StringUtils::split(output.substr(9), '/'); + + if (s.size() < 1 || s.size() > 2) { + LOG(ERR) << "unknown syslog definition '" << output << "', expecting " + << "'syslog://facility/identifier'"; + return nullptr; + } + + if (s.size() == 1) { + return new LogAppenderSyslog(s[0], "", contentFilter); + } + return new LogAppenderSyslog(s[0], s[1], contentFilter); + } +#endif + + // everything else must be file-based logging + std::string filename; + if (output == "-" || output == "+") { + filename = output; + } else if (StringUtils::isPrefix(output, "file://")) { + filename = output.substr(7); + } else { + LOG(ERR) << "unknown logger output '" << output << "'"; + return nullptr; + } + + // helper function to prevent duplicate output filenames + auto hasAppender = [&existingAppenders](std::string const& filename) { + if (existingAppenders.find(filename) != existingAppenders.end()) { + return true; + } + // treat stderr and stdout as one output filename + if (filename == "-" && + existingAppenders.find("+") != existingAppenders.end()) { + return true; + } + if (filename == "+" && + existingAppenders.find("-") != existingAppenders.end()) { + return true; + } + return false; + }; + + if (hasAppender(filename)) { + // already have an appender for the same output + return nullptr; + } + + try { + std::unique_ptr appender(new LogAppenderFile(filename, fatal2stderr, contentFilter)); + existingAppenders.emplace(filename); + return appender.release(); + } + catch (...) { + // cannot open file for logging + // try falling back to stderr instead + if (hasAppender("-")) { + return nullptr; + } + return buildAppender("-", fatal2stderr, contentFilter, existingAppenders); + } +} + //////////////////////////////////////////////////////////////////////////////// /// @brief RingBuffer //////////////////////////////////////////////////////////////////////////////// @@ -726,7 +798,8 @@ std::atomic Logger::_level(LogLevel::INFO); //////////////////////////////////////////////////////////////////////////////// void Logger::addAppender(std::string const& definition, bool fatal2stderr, - std::string const& filter) { + std::string const& filter, + std::unordered_set& existingAppenders) { std::vector v = StringUtils::split(definition, '='); std::string topicName; std::string output; @@ -767,42 +840,19 @@ void Logger::addAppender(std::string const& definition, bool fatal2stderr, topic = it->second; } + + std::unique_ptr appender(buildAppender(output, f2s, contentFilter, existingAppenders)); - std::unique_ptr appender; - - if (output == "-") { - appender.reset(new LogAppenderFile("-", f2s, contentFilter)); - } else if (output == "+") { - appender.reset(new LogAppenderFile("+", f2s, contentFilter)); - } else if (StringUtils::isPrefix(output, "file://")) { - auto filename = output.substr(7); - - appender.reset(new LogAppenderFile(filename, f2s, contentFilter)); -#ifdef TRI_ENABLE_SYSLOG - } else if (StringUtils::isPrefix(output, "syslog://")) { - auto s = StringUtils::split(output.substr(9), '/'); - - if (s.size() < 1 || s.size() > 2) { - LOG(ERR) << "unknown syslog definition '" << output << "', expecting " - << "'syslog://facility/identifier'"; - return; - } - - if (s.size() == 1) { - appender.reset(new LogAppenderSyslog(s[0], "", contentFilter)); - } else { - appender.reset(new LogAppenderSyslog(s[0], s[1], contentFilter)); - } -#endif - } else { - LOG(ERR) << "unknown output '" << output << "'"; + if (appender == nullptr) { + // cannot open appender or already have an appender for the channel return; } size_t n = topic == nullptr ? MAX_LOG_TOPICS : topic->id(); MUTEX_LOCKER(guard, AppendersLock); - Appenders[n].emplace_back(appender.release()); + Appenders[n].emplace_back(appender.get()); + appender.release(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/Basics/Logger.h b/lib/Basics/Logger.h index a50eff6c46..0be2a1a7b3 100644 --- a/lib/Basics/Logger.h +++ b/lib/Basics/Logger.h @@ -332,7 +332,7 @@ class Logger { /// @brief creates a new appender ////////////////////////////////////////////////////////////////////////////// - static void addAppender(std::string const&, bool, std::string const&); + static void addAppender(std::string const&, bool, std::string const&, std::unordered_set&); ////////////////////////////////////////////////////////////////////////////// /// @brief determines the global log level @@ -447,6 +447,7 @@ class Logger { static void flush(); private: + ////////////////////////////////////////////////////////////////////////////// /// @brief current log level ////////////////////////////////////////////////////////////////////////////// From 0f88ade5680c656e94925ddaa300495c34352264 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Sat, 13 Feb 2016 21:36:51 +0100 Subject: [PATCH 09/12] raised sleep --- UnitTests/HttpInterface/api-replication-spec.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/UnitTests/HttpInterface/api-replication-spec.rb b/UnitTests/HttpInterface/api-replication-spec.rb index 7de711ce26..8c064cf66e 100644 --- a/UnitTests/HttpInterface/api-replication-spec.rb +++ b/UnitTests/HttpInterface/api-replication-spec.rb @@ -347,7 +347,7 @@ describe ArangoDB do it "fetches a create collection action from the follow log" do ArangoDB.drop_collection("UnitTestsReplication") - sleep 1 + sleep 5 cmd = api + "/logger-state" doc = ArangoDB.log_get("#{prefix}-follow-create-collection", cmd, :body => "") @@ -357,7 +357,8 @@ describe ArangoDB do cid = ArangoDB.create_collection("UnitTestsReplication") - sleep 1 + sleep 5 + cmd = api + "/logger-follow?from=" + fromTick doc = ArangoDB.log_get("#{prefix}-follow-create-collection", cmd, :body => "", :format => :plain) doc.code.should eq(200) @@ -408,7 +409,7 @@ describe ArangoDB do it "fetches some collection operations from the follow log" do ArangoDB.drop_collection("UnitTestsReplication") - sleep 1 + sleep 5 cmd = api + "/logger-state" doc = ArangoDB.log_get("#{prefix}-follow-collection", cmd, :body => "") @@ -435,7 +436,7 @@ describe ArangoDB do doc = ArangoDB.log_delete("#{prefix}-follow-collection", cmd) doc.code.should eq(200) - sleep 1 + sleep 5 cmd = api + "/logger-follow?from=" + fromTick doc = ArangoDB.log_get("#{prefix}-follow-create-collection", cmd, :body => "", :format => :plain) From 687f7fdd72bd322c2102fe660088950d2c0b33df Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Sun, 14 Feb 2016 15:34:03 +0100 Subject: [PATCH 10/12] higher wait intervall --- js/server/tests/replication/replication-static.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/server/tests/replication/replication-static.js b/js/server/tests/replication/replication-static.js index b7801a15b1..b9b4ea026a 100644 --- a/js/server/tests/replication/replication-static.js +++ b/js/server/tests/replication/replication-static.js @@ -161,7 +161,7 @@ function ReplicationSuite() { console.log("waiting for slave to catch up"); printed = true; } - internal.wait(1.0, false); + internal.wait(5.0, false); } db._flushCache(); From 6ac522f9ead75f40f896bb40b7537c9a0ce8b1ef Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Sun, 14 Feb 2016 16:50:41 +0100 Subject: [PATCH 11/12] added jslint script --- scripts/jslint.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 scripts/jslint.sh diff --git a/scripts/jslint.sh b/scripts/jslint.sh new file mode 100755 index 0000000000..497331086c --- /dev/null +++ b/scripts/jslint.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +JAVASCRIPT_JSLINT="\ + `find ./js/actions -name "*.js"` \ + `find ./js/common/bootstrap -name "*.js"` \ + `find ./js/client/bootstrap -name "*.js"` \ + `find ./js/server/bootstrap -name "*.js"` \ + \ + `find ./js/common/modules/@arangodb -name "*.js"` \ + `find ./js/client/modules/@arangodb -name "*.js"` \ + `find ./js/server/modules/@arangodb -name "*.js"` \ + `find ./js/server/tests -name "*.js" | grep -v "ranges-combined"` \ + `find ./js/common/tests -name "*.js"` \ + `find ./js/client/tests -name "*.js"` \ + \ + `find ./js/apps/system/_system/cerberus/APP -name "*.js"` \ + `find ./js/apps/system/_api/gharial/APP -name "*.js"` \ + `find ./js/apps/system/_system/sessions/APP -name "*.js"` \ + `find ./js/apps/system/_system/simple-auth/APP -name "*.js"` \ + `find ./js/apps/system/_system/users/APP -name "*.js"` \ + \ + `find ./js/apps/system/_admin/aardvark/APP/frontend/js/models -name "*.js"` \ + `find ./js/apps/system/_admin/aardvark/APP/frontend/js/views -name "*.js"` \ + `find ./js/apps/system/_admin/aardvark/APP/frontend/js/collections -name "*.js"` \ + `find ./js/apps/system/_admin/aardvark/APP/frontend/js/routers -name "*.js"` \ + `find ./js/apps/system/_admin/aardvark/APP/frontend/js/arango -name "*.js"` \ + `find ./js/apps/system/_admin/aardvark/APP/frontend/js/shell -name "*.js"` \ + `find ./js/apps/system/_admin/aardvark/APP/test/specs -name "*.js"` \ + `find ./js/apps/system/_admin/aardvark/APP/test/clusterSpecs -name "*.js"` \ + \ + `find ./scripts -name "*.js"` \ + \ + ./js/common/modules/jsunity.js \ + ./js/client/client.js \ + ./js/server/server.js \ + ./js/server/upgrade-database.js \ + \ + ./js/apps/system/_admin/aardvark/APP/frontend/js/shell/browser.js \ +" + +FILELIST="" + +for file in ${JAVASCRIPT_JSLINT}; do + FILELIST="${FILELIST} --jslint ${file}"; +done + +exec ./build/bin/arangosh \ + -c none \ + --log.level error \ + --server.password "" \ + --javascript.startup-directory ./js \ + ${FILELIST} From 8da0c61de8049ac140900220f8130db16316f7fe Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Sun, 14 Feb 2016 17:14:00 +0100 Subject: [PATCH 12/12] fixed jslint --- .../aardvark/APP/frontend/js/models/arangoCollectionModel.js | 2 +- .../aardvark/APP/frontend/js/views/collectionsItemView.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/models/arangoCollectionModel.js b/js/apps/system/_admin/aardvark/APP/frontend/js/models/arangoCollectionModel.js index 37f7250f0d..f01e970da4 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/models/arangoCollectionModel.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/models/arangoCollectionModel.js @@ -190,7 +190,7 @@ self.set("name", name); result = true; }, - error: function(data) { + error: function(/*data*/) { try { console.log("error"); //var parsed = JSON.parse(data.responseText); diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/views/collectionsItemView.js b/js/apps/system/_admin/aardvark/APP/frontend/js/views/collectionsItemView.js index fe89d96c58..88e9c9f98d 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/views/collectionsItemView.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/views/collectionsItemView.js @@ -548,7 +548,7 @@ if (error) { arangoHelper.arangoError("Could not delete index"); } - } + }; $("#indexDeleteModal").modal('hide'); this.model.deleteIndex(this.lastId, callback);