+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
#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"
{
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;
static gint lock_socket_remove(void)
{
#ifdef G_OS_UNIX
- gchar *filename;
+ gchar *filename, *dirname;
#endif
if (lock_socket < 0) {
return -1;
#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;