[sylpheed:33987] Experimental multiple instance implementation (Re: Re: multiple instances, again)
Hiroyuki Yamamoto
hiro-y at kcn.ne.jp
Mon May 24 13:43:25 JST 2010
Hello,
On Thu, 20 May 2010 14:58:26 -0400
Casco Bucci <Casco.Bucci at comcast.net> wrote:
> On Thu, 20 May 2010 18:52:14 +0900
> Hiroyuki Yamamoto <hiro-y at kcn.ne.jp> wrote:
>
> > I was hesitative about multiple instances because accessing a
> > resource (local folders, settings, etc.) from multiple processes
> > can cause inconsistensy without proper resource management.
> >
> > Maybe it's not a problem if they are completely separated. I'll
> > think about that.
> >
> > --
> > Hiroyuki Yamamoto <hiro-y at kcn.ne.jp>
>
> Very welcomed news Mr. Yamamoto.
>
> Realize that Sylpheed and Sylpheed-Claws/Claws-Mail parted ways years
> ago. However, the way that C-M's developers implemented multiple
> instances should work without too much effort in Sylpheed.
>
> Perhaps it might not hurt to look at C-W's code base?
Claws-Mail is now GPL3, so it might be a problem to bollow the code.
Anyway, I've implemented a very simple multiple instances feature in
svn trunk.
The new option --instance-id <ID> allows users to specify any instance
ID (default is 'sylpheed'). This ID is used for the name of unix domain
socket (Unix) or mutex name (Windows).
% sylpheed --instance-id test --configdir ~/alt-sylpheed-config
(/tmp/test-1234 is created instead of /tmp/sylpheed-1234)
There is no extra checks, so please use with caution.
(DON'T share same configdir/mailboxes with multiple instances)
Following is the patch.
Index: src/main.c
===================================================================
--- src/main.c (revision 2543)
+++ src/main.c (working copy)
@@ -113,6 +113,7 @@
static gint lock_socket = -1;
static gint lock_socket_tag = 0;
static GIOChannel *lock_ch = NULL;
+static gchar *instance_id = NULL;
#if USE_THREADS
static GThread *main_thread;
@@ -551,6 +552,12 @@
i++;
}
#endif
+ } else if (!strncmp(argv[i], "--instance-id", 13)) {
+ if (argv[i + 1]) {
+ instance_id = g_locale_to_utf8
+ (argv[i + 1], -1, NULL, NULL, NULL);
+ i++;
+ }
} else if (!strncmp(argv[i], "--exit", 6)) {
cmd.exit = TRUE;
} else if (!strncmp(argv[i], "--help", 6)) {
@@ -1195,8 +1202,9 @@
static gchar *filename = NULL;
if (filename == NULL) {
- filename = g_strdup_printf("%s%csylpheed-%d",
+ filename = g_strdup_printf("%s%c%s-%d",
g_get_tmp_dir(), G_DIR_SEPARATOR,
+ instance_id ? instance_id : "sylpheed",
#if HAVE_GETUID
getuid());
#else
@@ -1213,28 +1221,35 @@
#ifdef G_OS_WIN32
HANDLE hmutex;
+ const gchar *ins_id = instance_id ? instance_id : "Sylpheed";
+ gushort port = cmd.ipcport ? cmd.ipcport : REMOTE_CMD_PORT;
- hmutex = CreateMutexA(NULL, FALSE, "Sylpheed");
+ debug_print("prohibit_duplicate_launch: checking mutex: %s\n", ins_id);
+ hmutex = CreateMutexA(NULL, FALSE, ins_id);
if (!hmutex) {
- g_warning("cannot create Mutex\n");
+ g_warning("cannot create Mutex: %s\n", ins_id);
return -1;
}
if (GetLastError() != ERROR_ALREADY_EXISTS) {
- sock = fd_open_inet(cmd.ipcport ? cmd.ipcport : REMOTE_CMD_PORT);
+ debug_print("prohibit_duplicate_launch: creating socket: port %d\n", port);
+ sock = fd_open_inet(port);
if (sock < 0)
return 0;
return sock;
}
- sock = fd_connect_inet(cmd.ipcport ? cmd.ipcport : REMOTE_CMD_PORT);
+ debug_print("prohibit_duplicate_launch: connecting to socket: port %d\n", port);
+ sock = fd_connect_inet(port);
if (sock < 0)
return -1;
#else
gchar *path;
path = get_socket_name();
+ debug_print("prohibit_duplicate_launch: checking socket: %s\n", path);
sock = fd_connect_unix(path);
if (sock < 0) {
+ debug_print("prohibit_duplicate_launch: creating socket: %s\n", path);
g_unlink(path);
return fd_open_unix(path);
}
@@ -1346,6 +1361,7 @@
#ifndef G_OS_WIN32
filename = get_socket_name();
+ debug_print("lock_socket_remove: removing socket: %s\n", filename);
g_unlink(filename);
#endif
--
Hiroyuki Yamamoto <hiro-y at kcn.ne.jp>
More information about the Sylpheed
mailing list