summaryrefslogtreecommitdiff
path: root/main/logger.c
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2014-02-05 20:43:50 +0000
committerKinsey Moore <kmoore@digium.com>2014-02-05 20:43:50 +0000
commit6f4a834870e0b0eabd79fe361e2c10f09bdfbb55 (patch)
tree2b9cdf527d6dd928867042a39aa1aee81c5297cd /main/logger.c
parent99f8f0f80afe2bb0e4d9e1cb9590a111afedfb9f (diff)
Logger: Fix handling of absolute paths
This fixes path handling for log files so that an extra / is not appended to the file path when the path is absolute (begins with /). This would previously result in different but functionally equivalent paths in the output of 'logger show channels'. ........ Merged revisions 407455 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 407456 from http://svn.asterisk.org/svn/asterisk/branches/11 ........ Merged revisions 407458 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@407459 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/logger.c')
-rw-r--r--main/logger.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/main/logger.c b/main/logger.c
index 3ecf2fcef..6c16853c2 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -322,13 +322,22 @@ static struct logchannel *make_logchannel(const char *channel, const char *compo
ast_copy_string(chan->filename, channel, sizeof(chan->filename));
openlog("asterisk", LOG_PID, chan->facility);
} else {
+ const char *log_dir_prefix = "";
+ const char *log_dir_separator = "";
+
+ if (channel[0] != '/') {
+ log_dir_prefix = ast_config_AST_LOG_DIR;
+ log_dir_separator = "/";
+ }
+
if (!ast_strlen_zero(hostname)) {
- snprintf(chan->filename, sizeof(chan->filename), "%s/%s.%s",
- channel[0] != '/' ? ast_config_AST_LOG_DIR : "", channel, hostname);
+ snprintf(chan->filename, sizeof(chan->filename), "%s%s%s.%s",
+ log_dir_prefix, log_dir_separator, channel, hostname);
} else {
- snprintf(chan->filename, sizeof(chan->filename), "%s/%s",
- channel[0] != '/' ? ast_config_AST_LOG_DIR : "", channel);
+ snprintf(chan->filename, sizeof(chan->filename), "%s%s%s",
+ log_dir_prefix, log_dir_separator, channel);
}
+
if (!(chan->fileptr = fopen(chan->filename, "a"))) {
/* Can't do real logging here since we're called with a lock
* so log to any attached consoles */
@@ -1007,7 +1016,7 @@ static struct ast_cli_entry cli_logger[] = {
AST_CLI_DEFINE(handle_logger_show_channels, "List configured log channels"),
AST_CLI_DEFINE(handle_logger_reload, "Reopens the log files"),
AST_CLI_DEFINE(handle_logger_rotate, "Rotates and reopens the log files"),
- AST_CLI_DEFINE(handle_logger_set_level, "Enables/Disables a specific logging level for this console")
+ AST_CLI_DEFINE(handle_logger_set_level, "Enables/Disables a specific logging level for this console"),
};
static void _handle_SIGXFSZ(int sig)