Commit 6098e089 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[3591] Changes after review:

 - ChangeLog updated
 - applyDefaultConfiguration() removed
 - couple unit-tests renamed
 - comments added for code that uses TEST_DATA_TOPBUILDDIR
 - copyright years updated
 - one function moved: logger_unittest_support.cc => logger_support.cc
parent bf254452
8xx. [bug] tomek
Kea components now use the KEA_LOCKFILE_DIR environment variable
to specify the directory of the logging lockfile. Locking can be
disabled completely by setting the variable to 'none'.
(Trac #3591, git tbd)
Kea 0.9 released on August 29, 2014
......
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012,2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -12,6 +12,9 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// This file requires LOCKFILE_DIR to be defined. It points to the default
// directory where lockfile will be created.
#include <log/interprocess/interprocess_sync_file.h>
#include <string>
......@@ -57,8 +60,9 @@ InterprocessSyncFile::do_lock(int cmd, short l_type) {
// Open the lockfile in the constructor so it doesn't do the access
// checks every time a message is logged.
const mode_t mode = umask(0111);
fd_ = open(lockfile_path.c_str(), O_CREAT | O_RDWR, 0660);
const mode_t mode = umask(S_IXUSR | S_IXGRP | S_IXOTH); // 0111
fd_ = open(lockfile_path.c_str(), O_CREAT | O_RDWR,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); // 0660
umask(mode);
if (fd_ == -1) {
......
// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2013-2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -16,6 +16,9 @@
#include <util/unittests/run_all.h>
#include <stdlib.h>
// This file uses TEST_DATA_TOPBUILDDIR macro, which must point to a writeable
// directory. It will be used for creating a logger lockfile.
int
main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
......
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2011,2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2011,2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -15,6 +15,7 @@
#include <string>
#include <log/logger_support.h>
#include <log/logger_manager.h>
#include <log/logger_name.h>
using namespace std;
......@@ -50,5 +51,75 @@ initLogger(const string& root, isc::log::Severity severity, int dbglevel,
LoggerManager::init(root, severity, dbglevel, file, buffer);
}
// Reset characteristics of the root logger to that set by the environment
// variables KEA_LOGGER_SEVERITY, KEA_LOGGER_DBGLEVEL and KEA_LOGGER_DESTINATION.
void
setDefaultLoggingOutput(bool verbose) {
using namespace isc::log;
// Constants: not declared static as this is function is expected to be
// called once only
const string DEVNULL = "/dev/null";
const string STDOUT = "stdout";
const string STDERR = "stderr";
const string SYSLOG = "syslog";
const string SYSLOG_COLON = "syslog:";
// Get the destination. If not specified, assume /dev/null. (The default
// severity for unit tests is DEBUG, which generates a lot of output.
// Routing the logging to /dev/null will suppress that, whilst still
// ensuring that the code paths are tested.)
const char* destination = getenv("KEA_LOGGER_DESTINATION");
const string dest((destination == NULL) ? DEVNULL : destination);
// Prepare the objects to define the logging specification
LoggerSpecification spec(getRootLoggerName(),
keaLoggerSeverity(verbose ? isc::log::DEBUG :
isc::log::INFO),
keaLoggerDbglevel(isc::log::MAX_DEBUG_LEVEL));
OutputOption option;
// Set up output option according to destination specification
if (dest == STDOUT) {
option.destination = OutputOption::DEST_CONSOLE;
option.stream = OutputOption::STR_STDOUT;
} else if (dest == STDERR) {
option.destination = OutputOption::DEST_CONSOLE;
option.stream = OutputOption::STR_STDERR;
} else if (dest == SYSLOG) {
option.destination = OutputOption::DEST_SYSLOG;
// Use default specified in OutputOption constructor for the
// syslog destination
} else if (dest.find(SYSLOG_COLON) == 0) {
option.destination = OutputOption::DEST_SYSLOG;
// Must take account of the string actually being "syslog:"
if (dest == SYSLOG_COLON) {
cerr << "**ERROR** value for KEA_LOGGER_DESTINATION of " <<
SYSLOG_COLON << " is invalid, " << SYSLOG <<
" will be used instead\n";
// Use default for logging facility
} else {
// Everything else in the string is the facility name
option.facility = dest.substr(SYSLOG_COLON.size());
}
} else {
// Not a recognised destination, assume a file.
option.destination = OutputOption::DEST_FILE;
option.filename = dest;
}
// ... and set the destination
spec.addOutputOption(option);
LoggerManager manager;
manager.process(spec);
}
} // namespace log
} // namespace isc
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2011,2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2011,2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -75,77 +75,6 @@ keaLoggerDbglevel(int defdbglevel) {
return (defdbglevel);
}
// Reset characteristics of the root logger to that set by the environment
// variables KEA_LOGGER_SEVERITY, KEA_LOGGER_DBGLEVEL and KEA_LOGGER_DESTINATION.
void
setDefaultLoggingOutput(bool verbose) {
using namespace isc::log;
// Constants: not declared static as this is function is expected to be
// called once only
const string DEVNULL = "/dev/null";
const string STDOUT = "stdout";
const string STDERR = "stderr";
const string SYSLOG = "syslog";
const string SYSLOG_COLON = "syslog:";
// Get the destination. If not specified, assume /dev/null. (The default
// severity for unit tests is DEBUG, which generates a lot of output.
// Routing the logging to /dev/null will suppress that, whilst still
// ensuring that the code paths are tested.)
const char* destination = getenv("KEA_LOGGER_DESTINATION");
const string dest((destination == NULL) ? DEVNULL : destination);
// Prepare the objects to define the logging specification
LoggerSpecification spec(getRootLoggerName(),
keaLoggerSeverity(verbose ? isc::log::DEBUG :
isc::log::INFO),
keaLoggerDbglevel(isc::log::MAX_DEBUG_LEVEL));
OutputOption option;
// Set up output option according to destination specification
if (dest == STDOUT) {
option.destination = OutputOption::DEST_CONSOLE;
option.stream = OutputOption::STR_STDOUT;
} else if (dest == STDERR) {
option.destination = OutputOption::DEST_CONSOLE;
option.stream = OutputOption::STR_STDERR;
} else if (dest == SYSLOG) {
option.destination = OutputOption::DEST_SYSLOG;
// Use default specified in OutputOption constructor for the
// syslog destination
} else if (dest.find(SYSLOG_COLON) == 0) {
option.destination = OutputOption::DEST_SYSLOG;
// Must take account of the string actually being "syslog:"
if (dest == SYSLOG_COLON) {
cerr << "**ERROR** value for KEA_LOGGER_DESTINATION of " <<
SYSLOG_COLON << " is invalid, " << SYSLOG <<
" will be used instead\n";
// Use default for logging facility
} else {
// Everything else in the string is the facility name
option.facility = dest.substr(SYSLOG_COLON.size());
}
} else {
// Not a recognised destination, assume a file.
option.destination = OutputOption::DEST_FILE;
option.filename = dest;
}
// ... and set the destination
spec.addOutputOption(option);
LoggerManager manager;
manager.process(spec);
}
// Logger Run-Time Initialization via Environment Variables
void initLogger(isc::log::Severity severity, int dbglevel) {
......
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2011,2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2011,2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2011,2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012,2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -16,6 +16,9 @@
#include <util/unittests/run_all.h>
#include <stdlib.h>
// This file uses TEST_DATA_TOPBUILDDIR macro, which must point to a writeable
// directory. It will be used for creating a logger lockfile.
int
main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment