talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit d3d3bb9a9f35461ea673c9493027e7e7645d64ba
parent 726ed3de38dd103179a1d860c2f81dba1a2f829a
Author: Colin Leroy <colin@colino.net>
Date:   Sun,  2 Dec 2012 20:35:06 +0000

2012-12-02 [colin]	3.9.0cvs36

	* src/main.c
		Move control sockets inside their own directory,
		$TMPDIR/claws-mail-$UID/, and name them after the configuration 		directory md5 hash. That allows
		- cleaner separation of sockets and config dirs in
		  case of alternate config directories
		- forward migration is handled: if $TMPDIR/claws-mail-$UID
		  exists as a socket, use it to control the running entity
		- backwards migration is handled: starting an old Claws Mail
		  version will bail out as creating the legacy socket won't
		  be possible.
		- migration for alternate-config-dirs is not handled, which
		  could be mentioned in release notes.
		Fixes bug #2828, "Use MD5 digest for socket name"

Diffstat:
MChangeLog | 16++++++++++++++++
MPATCHSETS | 1+
Mconfigure.ac | 2+-
Msrc/main.c | 43+++++++++++++++++++++++++++++++++----------
4 files changed, 51 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,19 @@ +2012-12-02 [colin] 3.9.0cvs36 + + * src/main.c + Move control sockets inside their own directory, + $TMPDIR/claws-mail-$UID/, and name them after the configuration directory md5 hash. That allows + - cleaner separation of sockets and config dirs in + case of alternate config directories + - forward migration is handled: if $TMPDIR/claws-mail-$UID + exists as a socket, use it to control the running entity + - backwards migration is handled: starting an old Claws Mail + version will bail out as creating the legacy socket won't + be possible. + - migration for alternate-config-dirs is not handled, which + could be mentioned in release notes. + Fixes bug #2828, "Use MD5 digest for socket name" + 2012-12-01 [colin] 3.9.0cvs35 * src/common/utils.c diff --git a/PATCHSETS b/PATCHSETS @@ -4533,3 +4533,4 @@ ( cvs diff -u -r 1.13.2.47 -r 1.13.2.48 src/common/plugin.c; ) > 3.9.0cvs33.patchset ( cvs diff -u -r 1.36.2.209 -r 1.36.2.210 src/common/utils.c; cvs diff -u -r 1.20.2.83 -r 1.20.2.84 src/common/utils.h; ) > 3.9.0cvs34.patchset ( cvs diff -u -r 1.36.2.210 -r 1.36.2.211 src/common/utils.c; ) > 3.9.0cvs35.patchset +( cvs diff -u -r 1.115.2.265 -r 1.115.2.266 src/main.c; ) > 3.9.0cvs36.patchset diff --git a/configure.ac b/configure.ac @@ -12,7 +12,7 @@ MINOR_VERSION=9 MICRO_VERSION=0 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=35 +EXTRA_VERSION=36 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/src/main.c b/src/main.c @@ -95,6 +95,8 @@ #include "procmsg.h" #include "inc.h" #include "imap.h" +#include "send_message.h" +#include "md5.h" #include "import.h" #include "manage_window.h" #include "alertpanel.h" @@ -2286,19 +2288,37 @@ gchar *claws_get_socket_name(void) { static gchar *filename = NULL; const gchar *socket_dir = NULL; - - if (rc_dir_is_alt()) - socket_dir = get_rc_dir(); - else - socket_dir = g_get_tmp_dir(); + gchar md5sum[33]; + if (filename == NULL) { - filename = g_strdup_printf("%s%cclaws-mail-%d", - socket_dir, G_DIR_SEPARATOR, + struct stat st; + socket_dir = g_strdup_printf("%s%cclaws-mail-%d", + g_get_tmp_dir(), G_DIR_SEPARATOR, #if HAVE_GETUID getuid()); #else - 0); -#endif + 0); +#endif + if (stat(socket_dir, &st) < 0 && errno != ENOENT) { + g_print("Error stat'ing socket_dir %s: %s\n", + socket_dir, strerror(errno)); + } else if (S_ISSOCK(st.st_mode)) { + /* old versions used a sock in $TMPDIR/claws-mail-$UID */ + debug_print("Using legacy socket %s\n", socket_dir); + filename = g_strdup(socket_dir); + return filename; + } + + if (!is_dir_exist(socket_dir) && make_dir(socket_dir) < 0) { + g_print("Error creating socket_dir %s: %s\n", + socket_dir, strerror(errno)); + } + + md5_hex_digest(md5sum, get_rc_dir()); + + filename = g_strdup_printf("%s%c%s", socket_dir, G_DIR_SEPARATOR, + md5sum); + debug_print("Using control socket %s\n", filename); } return filename; @@ -2521,7 +2541,7 @@ static gint prohibit_duplicate_launch(void) static gint lock_socket_remove(void) { #ifdef G_OS_UNIX - gchar *filename; + gchar *filename, *dirname; #endif if (lock_socket < 0) { return -1; @@ -2534,7 +2554,10 @@ static gint lock_socket_remove(void) #ifdef G_OS_UNIX filename = claws_get_socket_name(); + dirname = g_path_get_dirname(filename); claws_unlink(filename); + g_rmdir(dirname); + g_free(dirname); #endif return 0;