[Commits] main.c 1.115.2.265 1.115.2.266

colin at claws-mail.org colin at claws-mail.org
Sun Dec 2 21:35:08 CET 2012


Update of /home/claws-mail/claws/src
In directory srv:/tmp/cvs-serv5016/src

Modified Files:
      Tag: gtk2
	main.c 
Log Message:
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"

Index: main.c
===================================================================
RCS file: /home/claws-mail/claws/src/main.c,v
retrieving revision 1.115.2.265
retrieving revision 1.115.2.266
diff -u -d -r1.115.2.265 -r1.115.2.266
--- main.c	27 Nov 2012 10:22:34 -0000	1.115.2.265
+++ main.c	2 Dec 2012 20:35:06 -0000	1.115.2.266
@@ -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 @@
 {
 	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);						
+					   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 lock_socket_remove(void)
 {
 #ifdef G_OS_UNIX
-	gchar *filename;
+	gchar *filename, *dirname;
 #endif
 	if (lock_socket < 0) {
 		return -1;
@@ -2534,7 +2554,10 @@
 
 #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;



More information about the Commits mailing list