Commit 7193a176 authored by Andreas Gustafsson's avatar Andreas Gustafsson
Browse files

suppress logging until UID switch to avoid creating log

files as root
parent 46fb173b
......@@ -45,7 +45,16 @@
#define NS_LOGMODULE_OMAPI (&ns_g_modules[9])
isc_result_t
ns_log_init(void);
ns_log_init(isc_boolean_t safe);
/*
* Initialize the logging system and set up an initial default
* logging default configuration that will be used until the
* config file has been read.
*
* If 'safe' is true, use a default configuration that refrains
* from opening files. This is to avoid creating log files
* as root.
*/
isc_result_t
ns_log_setdefaultchannels(isc_logconfig_t *lcfg);
......@@ -55,6 +64,13 @@ ns_log_setdefaultchannels(isc_logconfig_t *lcfg);
* this just means setting up default_debug.
*/
isc_result_t
ns_log_setsafechannels(isc_logconfig_t *lcfg);
/*
* Like ns_log_setdefaultchannels(), but omits any logging
* to files.
*/
isc_result_t
ns_log_setdefaultcategory(isc_logconfig_t *lcfg);
/*
......
......@@ -56,18 +56,13 @@ static isc_logmodule_t modules[] = {
};
isc_result_t
ns_log_init(void) {
ns_log_init(isc_boolean_t safe) {
isc_result_t result;
isc_logconfig_t *lcfg;
ns_g_categories = categories;
ns_g_modules = modules;
/*
* XXXRTH This is not necessarily the final default logging
* setup.
*/
/*
* Setup a logging context.
*/
......@@ -79,9 +74,13 @@ ns_log_init(void) {
isc_log_registermodules(ns_g_lctx, ns_g_modules);
dns_log_init(ns_g_lctx);
result = ns_log_setdefaultchannels(lcfg);
if (safe)
result = ns_log_setsafechannels(lcfg);
else
result = ns_log_setdefaultchannels(lcfg);
if (result != ISC_R_SUCCESS)
goto cleanup;
result = ns_log_setdefaultcategory(lcfg);
if (result != ISC_R_SUCCESS)
goto cleanup;
......@@ -130,6 +129,31 @@ ns_log_setdefaultchannels(isc_logconfig_t *lcfg) {
return (result);
}
isc_result_t
ns_log_setsafechannels(isc_logconfig_t *lcfg) {
isc_result_t result;
if (! ns_g_logstderr) {
result = isc_log_createchannel(lcfg, "default_debug",
ISC_LOG_TONULL,
ISC_LOG_DYNAMIC,
NULL, 0);
if (result != ISC_R_SUCCESS)
goto cleanup;
}
/*
* Setting the debug level to zero should get the output
* discarded a bit faster.
*/
isc_log_setdebuglevel(ns_g_lctx, 0);
result = ISC_R_SUCCESS;
cleanup:
return (result);
}
isc_result_t
ns_log_setdefaultcategory(isc_logconfig_t *lcfg) {
isc_result_t result;
......
......@@ -300,7 +300,7 @@ setup() {
*/
ns_os_minprivs(ns_g_username);
result = ns_log_init();
result = ns_log_init(ISC_TF(ns_g_username != NULL));
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("ns_log_init() failed: %s",
isc_result_totext(result));
......
......@@ -1304,8 +1304,8 @@ load_configuration(const char *filename, ns_server_t *server,
if (ns_g_logstderr) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_INFO,
"ignoring named.conf logging statement "
"due to -g option");
"ignoring config file logging "
"statement due to -g option");
} else {
dns_c_logginglist_t *clog = NULL;
isc_logconfig_t *logc = NULL;
......@@ -1331,6 +1331,11 @@ load_configuration(const char *filename, ns_server_t *server,
}
}
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_DEBUG(1),
"now using logging configuration from "
"config file");
if (dns_c_ctx_getpidfilename(cctx, &pidfilename) ==
ISC_R_NOTFOUND)
pidfilename = ns_g_defaultpidfile;
......
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