summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2002-07-16 20:46:14 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2002-07-16 20:46:14 +0000
commit0a1e18b50d014f6438e43c491182c2276470942c (patch)
tree7fd60e4d0c375ca3b39ae3b09005908a007ba2b7
parenteb0bb65c7f76b88097262728ea90cc9dbea16a89 (diff)
downloadirssi-0a1e18b50d014f6438e43c491182c2276470942c.zip
If log file path contains any $variables or %time codes, create the
whole directory structure to the log file. This way log files created with /LOG OPEN properly create the directories at startup. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2869 dbcabf3a-b0e7-0310-adc4-f8d773084564
-rw-r--r--src/core/log.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/core/log.c b/src/core/log.c
index 9a131f96..e17f5c56 100644
--- a/src/core/log.c
+++ b/src/core/log.c
@@ -100,6 +100,8 @@ static char *log_filename(LOG_REC *log)
int log_start_logging(LOG_REC *log)
{
+ char *dir;
+
g_return_val_if_fail(log != NULL, FALSE);
if (log->handle != -1)
@@ -108,6 +110,16 @@ int log_start_logging(LOG_REC *log)
/* Append/create log file */
g_free_not_null(log->real_fname);
log->real_fname = log_filename(log);
+
+ if (log->real_fname != NULL &&
+ strcmp(log->real_fname, log->fname) != 0) {
+ /* path may contain variables (%time, $vars),
+ make sure the directory is created */
+ dir = g_dirname(log->real_fname);
+ mkpath(dir, LOG_DIR_CREATE_MODE);
+ g_free(dir);
+ }
+
log->handle = log->real_fname == NULL ? -1 :
open(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
log_file_create_mode);
@@ -165,7 +177,7 @@ void log_stop_logging(LOG_REC *log)
static void log_rotate_check(LOG_REC *log)
{
- char *new_fname, *dir;
+ char *new_fname;
g_return_if_fail(log != NULL);
@@ -178,10 +190,6 @@ static void log_rotate_check(LOG_REC *log)
log_stop_logging(log);
signal_emit("log rotated", 1, log);
- dir = g_dirname(new_fname);
- mkpath(dir, LOG_DIR_CREATE_MODE);
- g_free(dir);
-
log_start_logging(log);
}
g_free(new_fname);