diff options
Diffstat (limited to 'src/plugins/logger/logger.c')
-rw-r--r-- | src/plugins/logger/logger.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c index 0458a0395..3a0690ba6 100644 --- a/src/plugins/logger/logger.c +++ b/src/plugins/logger/logger.c @@ -25,6 +25,7 @@ #include <stdlib.h> #include <unistd.h> +#include <errno.h> #include <stdio.h> #include <stdarg.h> #include <string.h> @@ -70,6 +71,51 @@ logger_config_read () } /* + * logger_create_directory: create logger directory + * return 1 if success, 0 if failed + */ + +int +logger_create_directory () +{ + int rc; + char *dir1, *dir2, *weechat_dir; + + rc = 1; + + dir1 = weechat_string_replace (logger_path, "~", getenv ("HOME")); + if (dir1) + { + weechat_dir = weechat_info_get ("weechat_dir"); + if (weechat_dir) + { + dir2 = weechat_string_replace (dir1, "%h", weechat_dir); + if (dir2) + { + if (mkdir (dir2, 0755) < 0) + { + if (errno != EEXIST) + rc = 0; + } + else + chmod (dir2, 0700); + free (dir2); + } + else + rc = 0; + free (weechat_dir); + } + else + rc = 0; + free (dir1); + } + else + rc = 0; + + return rc; +} + +/* * logger_get_filename: build log filename for a buffer */ @@ -368,6 +414,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) logger_config_read (); if (!logger_path || !logger_time_format) return PLUGIN_RC_FAILED; + if (!logger_create_directory ()) + return PLUGIN_RC_FAILED; logger_start_buffer_all (); |