summaryrefslogtreecommitdiff
path: root/src/plugins/logger
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2007-11-11 17:05:42 +0100
committerSebastien Helleu <flashcode@flashtux.org>2007-11-11 17:05:42 +0100
commitac30e2226d2aac2dbd6a34bd12aa1c8902010662 (patch)
tree2d10753494c0550eaaa6f204c67963d7a56b7f43 /src/plugins/logger
parentcdc08d6fc38d0c81e4826930b266f74a33ca2185 (diff)
downloadweechat-ac30e2226d2aac2dbd6a34bd12aa1c8902010662.zip
Added log directory creation in logger plugin, removed unused log config options in core
Diffstat (limited to 'src/plugins/logger')
-rw-r--r--src/plugins/logger/logger.c48
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 ();