commit 4bcbb1b6de51aa1c6bdb10377ece129d75bd64b9
parent f027ee69ba2a264a45b43f73d0d0caa20a7ab4a8
Author: Colin Leroy <colin@colino.net>
Date: Wed, 5 Nov 2008 18:05:32 +0000
2008-11-05 [colin] 3.6.1cvs18
* src/action.c
* src/main.c
* src/mainwindow.c
* src/common/socket.c
* src/common/socket.h
* src/gtk/gtkutils.c
* src/gtk/gtkutils.h
w32: Implement single launch (lock
socket); always put debug log to
the rc_dir; fix Start menu update
after registering as default Mail
app
Diffstat:
10 files changed, 161 insertions(+), 30 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,18 @@
+2008-11-05 [colin] 3.6.1cvs18
+
+ * src/action.c
+ * src/main.c
+ * src/mainwindow.c
+ * src/common/socket.c
+ * src/common/socket.h
+ * src/gtk/gtkutils.c
+ * src/gtk/gtkutils.h
+ w32: Implement single launch (lock
+ socket); always put debug log to
+ the rc_dir; fix Start menu update
+ after registering as default Mail
+ app
+
2008-11-05 [colin] 3.6.1cvs17
* src/mainwindow.c
diff --git a/PATCHSETS b/PATCHSETS
@@ -3599,3 +3599,4 @@
( cvs diff -u -r 1.274.2.285 -r 1.274.2.286 src/mainwindow.c; cvs diff -u -r 1.83.2.146 -r 1.83.2.147 src/mimeview.c; cvs diff -u -r 1.204.2.181 -r 1.204.2.182 src/prefs_common.c; cvs diff -u -r 1.103.2.116 -r 1.103.2.117 src/prefs_common.h; cvs diff -u -r 1.3.2.23 -r 1.3.2.24 src/prefs_ext_prog.c; cvs diff -u -r 1.49.2.118 -r 1.49.2.119 src/procmime.c; cvs diff -u -r 1.96.2.209 -r 1.96.2.210 src/textview.c; cvs diff -u -r 1.36.2.153 -r 1.36.2.154 src/common/utils.c; cvs diff -u -r 1.1.2.2 -r 1.1.2.3 src/common/w32_reg.c; cvs diff -u -r 1.1.2.4 -r 1.1.2.5 src/common/w32lib.h; ) > 3.6.1cvs15.patchset
( cvs diff -u -r 1.1.2.3 -r 1.1.2.4 src/common/w32_reg.c; ) > 3.6.1cvs16.patchset
( cvs diff -u -r 1.274.2.286 -r 1.274.2.287 src/mainwindow.c; ) > 3.6.1cvs17.patchset
+( cvs diff -u -r 1.12.2.54 -r 1.12.2.55 src/action.c; cvs diff -u -r 1.115.2.214 -r 1.115.2.215 src/main.c; cvs diff -u -r 1.274.2.287 -r 1.274.2.288 src/mainwindow.c; cvs diff -u -r 1.13.2.40 -r 1.13.2.41 src/common/socket.c; cvs diff -u -r 1.13.2.21 -r 1.13.2.22 src/common/socket.h; cvs diff -u -r 1.5.2.84 -r 1.5.2.85 src/gtk/gtkutils.c; cvs diff -u -r 1.4.2.46 -r 1.4.2.47 src/gtk/gtkutils.h; ) > 3.6.1cvs18.patchset
diff --git a/configure.ac b/configure.ac
@@ -11,7 +11,7 @@ MINOR_VERSION=6
MICRO_VERSION=1
INTERFACE_AGE=0
BINARY_AGE=0
-EXTRA_VERSION=17
+EXTRA_VERSION=18
EXTRA_RELEASE=
EXTRA_GTK2_VERSION=
diff --git a/src/action.c b/src/action.c
@@ -892,7 +892,8 @@ static gboolean execute_actions(gchar *action, GSList *msg_list,
child_info->tag_status =
claws_input_add(child_info->chld_status,
GDK_INPUT_READ,
- catch_status, child_info);
+ catch_status, child_info,
+ FALSE);
}
create_io_dialog(children);
@@ -1052,9 +1053,9 @@ static ChildInfo *fork_child(gchar *cmd, const gchar *msg_str,
child_info->chld_status = chld_status[0];
child_info->tag_in = -1;
child_info->tag_out = claws_input_add(chld_out[0], GDK_INPUT_READ,
- catch_output, child_info);
+ catch_output, child_info, FALSE);
child_info->tag_err = claws_input_add(chld_err[0], GDK_INPUT_READ,
- catch_output, child_info);
+ catch_output, child_info, FALSE);
if (!(children->action_type &
(ACTION_PIPE_IN | ACTION_PIPE_OUT | ACTION_INSERT)))
@@ -1139,7 +1140,7 @@ static void send_input(GtkWidget *w, gpointer data)
child_info->tag_in = claws_input_add(child_info->chld_in,
GDK_INPUT_WRITE,
- catch_input, children);
+ catch_input, children, FALSE);
}
static gint delete_io_dialog_cb(GtkWidget *w, GdkEvent *e, gpointer data)
diff --git a/src/common/socket.c b/src/common/socket.c
@@ -35,6 +35,7 @@
# ifndef EINPROGRESS
# define EINPROGRESS WSAEINPROGRESS
# endif
+# include "w32lib.h"
#else
# if HAVE_SYS_WAIT_H
# include <sys/wait.h>
@@ -231,6 +232,11 @@ void refresh_resolvers(void)
#endif /*G_OS_UNIX*/
}
+#ifdef G_OS_WIN32
+#define SOCKET_IS_VALID(s) ((s) != INVALID_SOCKET)
+#else
+#define SOCKET_IS_VALID(s) TRUE
+#endif
/* Due to the fact that socket under Windows are not represented by
standard file descriptors, we sometimes need to check whether a
@@ -248,6 +254,78 @@ static int fd_is_w32_socket(gint fd)
#endif
}
+gint fd_connect_inet(gushort port)
+{
+ gint sock;
+ struct sockaddr_in addr;
+
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+ if (!SOCKET_IS_VALID(sock)) {
+#ifdef G_OS_WIN32
+ debug_print("fd_connect_inet(): socket() failed: %d\n",
+ WSAGetLastError());
+#else
+ perror("fd_connect_inet(): socket");
+#endif
+ return -1;
+ }
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(port);
+ addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+ if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ fd_close(sock);
+ return -1;
+ }
+
+ return sock;
+}
+gint fd_open_inet(gushort port)
+{
+ gint sock;
+ struct sockaddr_in addr;
+ gint val;
+
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+ if (!SOCKET_IS_VALID(sock)) {
+#ifdef G_OS_WIN32
+ g_warning("fd_open_inet(): socket() failed: %d\n",
+ WSAGetLastError());
+#else
+ perror("fd_open_inet(): socket");
+#endif
+ return -1;
+ }
+
+ val = 1;
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&val,
+ sizeof(val)) < 0) {
+ perror("setsockopt");
+ fd_close(sock);
+ return -1;
+ }
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(port);
+ addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+ if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ perror("bind");
+ fd_close(sock);
+ return -1;
+ }
+
+ if (listen(sock, 1) < 0) {
+ perror("listen");
+ fd_close(sock);
+ return -1;
+ }
+
+ return sock;
+}
gint fd_connect_unix(const gchar *path)
{
diff --git a/src/common/socket.h b/src/common/socket.h
@@ -110,6 +110,9 @@ gint fd_connect_unix (const gchar *path);
gint fd_open_unix (const gchar *path);
gint fd_accept (gint sock);
+gint fd_connect_inet(gushort port);
+gint fd_open_inet(gushort port);
+
gint fd_write (gint sock, const gchar *buf, gint len);
gint fd_write_all (gint sock, const gchar *buf, gint len);
gint fd_gets (gint sock, gchar *buf, gint len);
diff --git a/src/gtk/gtkutils.c b/src/gtk/gtkutils.c
@@ -1662,7 +1662,8 @@ gint
claws_input_add (gint source,
GdkInputCondition condition,
GdkInputFunction function,
- gpointer data)
+ gpointer data,
+ gboolean is_sock)
{
guint result;
ClawsIOClosure *closure = g_new (ClawsIOClosure, 1);
@@ -1684,7 +1685,10 @@ claws_input_add (gint source,
#ifndef G_OS_WIN32
channel = g_io_channel_unix_new (source);
#else
- channel = g_io_channel_win32_new_fd(source);
+ if (is_sock)
+ channel = g_io_channel_win32_new_socket(source);
+ else
+ channel = g_io_channel_win32_new_fd(source);
#endif
result = g_io_add_watch_full (channel, G_PRIORITY_DEFAULT, cond,
claws_io_invoke,
diff --git a/src/gtk/gtkutils.h b/src/gtk/gtkutils.h
@@ -210,13 +210,12 @@ gboolean gtkut_list_view_select_row(GtkWidget *list, gint row);
GtkUIManager *gtkut_create_ui_manager(void);
GtkUIManager *gtkut_ui_manager(void);
-#ifdef G_OS_UNIX
gint
claws_input_add (gint source,
GdkInputCondition condition,
GdkInputFunction function,
- gpointer data);
-#endif
+ gpointer data,
+ gboolean is_sock);
#if GTK_CHECK_VERSION(2,12,0)
#define CLAWS_TIP_DECL() {}
#define CLAWS_SET_TIP(widget,tip) { \
diff --git a/src/main.c b/src/main.c
@@ -798,11 +798,16 @@ static void win32_log(const gchar *log_domain, GLogLevelFlags log_level, const g
static void win32_open_log(void)
{
- if (is_file_exist("claws-win32.log")) {
- if (rename_force("claws-win32.log", "claws-win32.log.bak") < 0)
- FILE_OP_ERROR("claws-win32.log", "rename");
+ gchar *logfile = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "claws-win32.log", NULL);
+ gchar *oldlogfile = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "claws-win32.log.bak", NULL);
+
+ if (is_file_exist(logfile)) {
+ if (rename_force(logfile, oldlogfile) < 0)
+ FILE_OP_ERROR(logfile, "rename");
}
- win32_debug_fp = g_fopen("claws-win32.log", "w");
+ win32_debug_fp = g_fopen(logfile, "w");
+ g_free(logfile);
+ g_free(oldlogfile);
if (win32_debug_fp)
{
g_set_print_handler(win32_print_stdout);
@@ -1091,7 +1096,6 @@ int main(int argc, char *argv[])
sock_init();
/* check and create unix domain socket for remote operation */
-#ifdef G_OS_UNIX
lock_socket = prohibit_duplicate_launch();
if (lock_socket < 0) {
#ifdef HAVE_STARTUP_NOTIFICATION
@@ -1109,7 +1113,6 @@ int main(int argc, char *argv[])
if (cmd.exit)
return 0;
-#endif
if (!g_thread_supported())
g_thread_init(NULL);
@@ -1377,12 +1380,10 @@ int main(int argc, char *argv[])
folder_item_update_freeze();
/* register the callback of unix domain socket input */
-#ifdef G_OS_UNIX
lock_socket_tag = claws_input_add(lock_socket,
GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
lock_socket_input_cb,
- mainwin);
-#endif
+ mainwin, TRUE);
prefs_account_init();
@@ -1803,7 +1804,7 @@ static void parse_cmd_opt(int argc, char *argv[])
} else if (!strncmp(argv[i], "--receive", 9)) {
cmd.receive = TRUE;
} else if (!strncmp(argv[i], "--compose", 9)) {
- const gchar *p = argv[i + 1];
+ const gchar *p = (i+1 < argc)?argv[i+1]:NULL;
cmd.compose = TRUE;
cmd.compose_mailto = NULL;
@@ -1816,13 +1817,13 @@ static void parse_cmd_opt(int argc, char *argv[])
i++;
}
} else if (!strncmp(argv[i], "--subscribe", 11)) {
- const gchar *p = argv[i + 1];
+ const gchar *p = (i+1 < argc)?argv[i+1]:NULL;
if (p && *p != '\0' && *p != '-') {
cmd.subscribe = TRUE;
cmd.subscribe_uri = p;
}
} else if (!strncmp(argv[i], "--attach", 8)) {
- const gchar *p = argv[i + 1];
+ const gchar *p = (i+1 < argc)?argv[i+1]:NULL;
gchar *file = NULL;
while (p && *p != '\0' && *p != '-') {
@@ -1844,7 +1845,7 @@ static void parse_cmd_opt(int argc, char *argv[])
}
g_ptr_array_add(cmd.attach_files, file);
i++;
- p = argv[i + 1];
+ p = (i+1 < argc)?argv[i+1]:NULL;
}
} else if (!strncmp(argv[i], "--send", 6)) {
cmd.send = TRUE;
@@ -1858,7 +1859,7 @@ static void parse_cmd_opt(int argc, char *argv[])
g_print("Claws Mail version " VERSION "\n");
exit(0);
} else if (!strncmp(argv[i], "--status-full", 13)) {
- const gchar *p = argv[i + 1];
+ const gchar *p = (i+1 < argc)?argv[i+1]:NULL;
cmd.status_full = TRUE;
while (p && *p != '\0' && *p != '-') {
@@ -1869,10 +1870,10 @@ static void parse_cmd_opt(int argc, char *argv[])
g_ptr_array_add(cmd.status_full_folders,
g_strdup(p));
i++;
- p = argv[i + 1];
+ p = (i+1 < argc)?argv[i+1]:NULL;
}
} else if (!strncmp(argv[i], "--status", 8)) {
- const gchar *p = argv[i + 1];
+ const gchar *p = (i+1 < argc)?argv[i+1]:NULL;
cmd.status = TRUE;
while (p && *p != '\0' && *p != '-') {
@@ -1881,7 +1882,7 @@ static void parse_cmd_opt(int argc, char *argv[])
g_ptr_array_add(cmd.status_folders,
g_strdup(p));
i++;
- p = argv[i + 1];
+ p = (i+1 < argc)?argv[i+1]:NULL;
}
} else if (!strncmp(argv[i], "--online", 8)) {
cmd.online_mode = ONLINE_MODE_ONLINE;
@@ -1920,7 +1921,7 @@ static void parse_cmd_opt(int argc, char *argv[])
exit(1);
} else if (!strncmp(argv[i], "--crash", 7)) {
cmd.crash = TRUE;
- cmd.crash_params = g_strdup(argv[i + 1]);
+ cmd.crash_params = g_strdup((i+1 < argc)?argv[i+1]:NULL);
i++;
} else if (!strncmp(argv[i], "--config-dir", sizeof "--config-dir" - 1)) {
g_print(RC_DIR "\n");
@@ -2140,6 +2141,7 @@ static gchar *get_crashfile_name(void)
static gint prohibit_duplicate_launch(void)
{
gint uxsock;
+#ifdef G_OS_UNIX
gchar *path;
path = claws_get_socket_name();
@@ -2152,7 +2154,25 @@ static gint prohibit_duplicate_launch(void)
claws_unlink(path);
return fd_open_unix(path);
}
-
+#else
+ HANDLE hmutex;
+
+ hmutex = CreateMutexA(NULL, FALSE, "ClawsMail");
+ if (!hmutex) {
+ debug_print("cannot create Mutex\n");
+ return -1;
+ }
+ if (GetLastError() != ERROR_ALREADY_EXISTS) {
+ uxsock = fd_open_inet(50216);
+ if (uxsock < 0)
+ return 0;
+ return uxsock;
+ }
+
+ uxsock = fd_connect_inet(50216);
+ if (uxsock < 0)
+ return -1;
+#endif
/* remote command mode */
debug_print("another Claws Mail instance is already running.\n");
@@ -2234,6 +2254,7 @@ static gint prohibit_duplicate_launch(void)
fd_write_all(uxsock, str, strlen(str));
g_free(str);
} else {
+#ifndef G_OS_WIN32
gchar buf[BUFSIZ];
fd_write_all(uxsock, "get_display\n", 12);
memset(buf, 0, sizeof(buf));
@@ -2246,6 +2267,9 @@ static gint prohibit_duplicate_launch(void)
uxsock = fd_connect_unix(path);
fd_write_all(uxsock, "popup\n", 6);
}
+#else
+ fd_write_all(uxsock, "popup\n", 6);
+#endif
}
fd_close(uxsock);
@@ -2256,7 +2280,7 @@ static gint lock_socket_remove(void)
{
#ifdef G_OS_UNIX
gchar *filename;
-
+#endif
if (lock_socket < 0) {
return -1;
}
@@ -2265,6 +2289,8 @@ static gint lock_socket_remove(void)
g_source_remove(lock_socket_tag);
}
fd_close(lock_socket);
+
+#ifdef G_OS_UNIX
filename = claws_get_socket_name();
claws_unlink(filename);
#endif
diff --git a/src/mainwindow.c b/src/mainwindow.c
@@ -81,6 +81,9 @@
#include "imap.h"
#include "socket.h"
#include "printing.h"
+#ifdef G_OS_WIN32
+#include "w32lib.h"
+#endif
#define AC_LABEL_WIDTH 240
@@ -4977,6 +4980,7 @@ static void set_default_client_cb(GtkAction *action, gpointer data)
"", binary_compose);
if (!r) {
+ SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Software\\Clients\\Mail");
alertpanel_notice(_("Claws Mail has been registered as default client."));
} else {
alertpanel_error(_("Can not register as default client: impossible to write to the registry."));