mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
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
This commit is contained in:
parent
eb0bb65c7f
commit
0a1e18b50d
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user