summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2006-05-16 13:53:34 +0000
committerSebastien Helleu <flashcode@flashtux.org>2006-05-16 13:53:34 +0000
commit88fd88373d0524404a3c38703ae2c03dc075063c (patch)
treef6a6a50918a8484ae3009463e0b5a929d39b9419
parented5f70aa6ad74fd4ff098b942d74fbd5169b751d (diff)
downloadweechat-88fd88373d0524404a3c38703ae2c03dc075063c.zip
Added lock for log file (~/.weechat/weechat.log), only one WeeChat process can use this file (bug #16382)
-rw-r--r--ChangeLog4
-rw-r--r--src/common/weechat.c20
-rw-r--r--weechat/ChangeLog4
-rw-r--r--weechat/src/common/weechat.c20
4 files changed, 38 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 7b1a0f208..6c229d829 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,11 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
-ChangeLog - 2006-05-14
+ChangeLog - 2006-05-16
Version 0.1.9 (under dev!):
+ * added lock for log file (~/.weechat/weechat.log), only one WeeChat
+ process can use this file (bug #16382)
* fixed crash with malformed UTF-8 strings
* fixed crash with ncurses color when too many colors defined in ncurses
(bug #16556)
diff --git a/src/common/weechat.c b/src/common/weechat.c
index 6468bc6dc..8a69facdb 100644
--- a/src/common/weechat.c
+++ b/src/common/weechat.c
@@ -44,6 +44,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
+#include <sys/file.h>
#include <sys/stat.h>
#include <time.h>
#include <signal.h>
@@ -846,10 +847,18 @@ weechat_init_log ()
filename =
(char *) malloc (filename_length * sizeof (char));
snprintf (filename, filename_length, "%s/" WEECHAT_LOG_NAME, weechat_home);
- if ((weechat_log_file = fopen (filename, "wt")) == NULL)
+
+ weechat_log_file = fopen (filename, "wt");
+ if (!weechat_log_file
+ || (flock (fileno (weechat_log_file), LOCK_EX | LOCK_NB) != 0))
+ {
fprintf (stderr,
- _("%s unable to create/append to log file (%s/%s)"),
- WEECHAT_WARNING, weechat_home, WEECHAT_LOG_NAME);
+ _("%s unable to create/append to log file (%s/%s)\n"
+ "If another WeeChat process is using this file, try to run WeeChat\n"
+ "with another home using \"--dir\" command line option.\n"),
+ WEECHAT_ERROR, weechat_home, WEECHAT_LOG_NAME);
+ exit (1);
+ }
free (filename);
}
@@ -939,7 +948,10 @@ weechat_shutdown (int return_code, int crash)
if (weechat_home)
free (weechat_home);
if (weechat_log_file)
+ {
+ flock (fileno (weechat_log_file), LOCK_UN);
fclose (weechat_log_file);
+ }
if (local_charset)
free (local_charset);
alias_free_all ();
@@ -956,7 +968,7 @@ weechat_shutdown (int return_code, int crash)
}
/*
- * weechat_dump writes dump to WeeChat log file
+ * weechat_dump: write dump to WeeChat log file
*/
void
diff --git a/weechat/ChangeLog b/weechat/ChangeLog
index 7b1a0f208..6c229d829 100644
--- a/weechat/ChangeLog
+++ b/weechat/ChangeLog
@@ -1,9 +1,11 @@
WeeChat - Wee Enhanced Environment for Chat
===========================================
-ChangeLog - 2006-05-14
+ChangeLog - 2006-05-16
Version 0.1.9 (under dev!):
+ * added lock for log file (~/.weechat/weechat.log), only one WeeChat
+ process can use this file (bug #16382)
* fixed crash with malformed UTF-8 strings
* fixed crash with ncurses color when too many colors defined in ncurses
(bug #16556)
diff --git a/weechat/src/common/weechat.c b/weechat/src/common/weechat.c
index 6468bc6dc..8a69facdb 100644
--- a/weechat/src/common/weechat.c
+++ b/weechat/src/common/weechat.c
@@ -44,6 +44,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
+#include <sys/file.h>
#include <sys/stat.h>
#include <time.h>
#include <signal.h>
@@ -846,10 +847,18 @@ weechat_init_log ()
filename =
(char *) malloc (filename_length * sizeof (char));
snprintf (filename, filename_length, "%s/" WEECHAT_LOG_NAME, weechat_home);
- if ((weechat_log_file = fopen (filename, "wt")) == NULL)
+
+ weechat_log_file = fopen (filename, "wt");
+ if (!weechat_log_file
+ || (flock (fileno (weechat_log_file), LOCK_EX | LOCK_NB) != 0))
+ {
fprintf (stderr,
- _("%s unable to create/append to log file (%s/%s)"),
- WEECHAT_WARNING, weechat_home, WEECHAT_LOG_NAME);
+ _("%s unable to create/append to log file (%s/%s)\n"
+ "If another WeeChat process is using this file, try to run WeeChat\n"
+ "with another home using \"--dir\" command line option.\n"),
+ WEECHAT_ERROR, weechat_home, WEECHAT_LOG_NAME);
+ exit (1);
+ }
free (filename);
}
@@ -939,7 +948,10 @@ weechat_shutdown (int return_code, int crash)
if (weechat_home)
free (weechat_home);
if (weechat_log_file)
+ {
+ flock (fileno (weechat_log_file), LOCK_UN);
fclose (weechat_log_file);
+ }
if (local_charset)
free (local_charset);
alias_free_all ();
@@ -956,7 +968,7 @@ weechat_shutdown (int return_code, int crash)
}
/*
- * weechat_dump writes dump to WeeChat log file
+ * weechat_dump: write dump to WeeChat log file
*/
void