SF.net SVN: geany: [2235] trunk
eht16 at users.sourceforge.net
eht16 at xxxxx
Thu Feb 7 15:53:03 UTC 2008
Revision: 2235
http://geany.svn.sourceforge.net/geany/?rev=2235&view=rev
Author: eht16
Date: 2008-02-07 07:53:02 -0800 (Thu, 07 Feb 2008)
Log Message:
-----------
Create the Unix Domain Socket for detecting a running instance in system's tmp directory and create a symlink to it in Geany's configuration directory (closes #1888561).
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/socket.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-02-07 14:49:01 UTC (rev 2234)
+++ trunk/ChangeLog 2008-02-07 15:53:02 UTC (rev 2235)
@@ -3,6 +3,10 @@
* plugins/Makefile.am: Fix typo (thanks Slava Semushin for reporting).
* scintilla/include/Platform.h:
Use a better check for PLAT_GTK_WIN32 (backport from Scintilla CVS).
+ * src/socket.c:
+ Create the Unix Domain Socket for detecting a running instance in
+ system's tmp directory and create a symlink to it in Geany's
+ configuration directory (closes #1888561).
2008-02-06 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/src/socket.c
===================================================================
--- trunk/src/socket.c 2008-02-07 14:49:01 UTC (rev 2234)
+++ trunk/src/socket.c 2008-02-07 15:53:02 UTC (rev 2235)
@@ -54,6 +54,7 @@
# include <sys/socket.h>
# include <sys/un.h>
# include <netinet/in.h>
+# include <glib/gstdio.h>
#else
# include <winsock2.h>
# include <ws2tcpip.h>
@@ -67,6 +68,7 @@
#include "document.h"
#include "support.h"
#include "ui_utils.h"
+#include "utils.h"
@@ -188,7 +190,7 @@
sock = socket_fd_connect_unix(socket_info.file_name);
if (sock < 0)
{
- unlink(socket_info.file_name);
+ g_unlink(socket_info.file_name);
return socket_fd_open_unix(socket_info.file_name);
}
#endif
@@ -220,9 +222,22 @@
#ifdef G_OS_WIN32
WSACleanup();
#else
- if (socket_info.file_name)
+ if (socket_info.file_name != NULL)
{
- unlink(socket_info.file_name);
+ gchar real_path[512];
+ gsize len;
+
+ real_path[0] = '\0';
+
+ // read the contents of the symbolic link socket_info.file_name and delete it
+ // readlink should return something like "/tmp/geany_socket.1202396669"
+ len = readlink(socket_info.file_name, real_path, sizeof(real_path) - 1);
+ if ((gint) len > 0)
+ {
+ real_path[len] = '\0';
+ g_unlink(real_path);
+ }
+ g_unlink(socket_info.file_name);
g_free(socket_info.file_name);
}
#endif
@@ -263,6 +278,7 @@
gint sock;
struct sockaddr_un addr;
gint val;
+ gchar *real_path;
sock = socket(PF_UNIX, SOCK_STREAM, 0);
@@ -280,10 +296,33 @@
return -1;
}
+ // fix for #1888561:
+ // in case the configuration directory is located on a network file system or any other
+ // file system which doesn't support sockets, we just link the socket there and create the
+ // real socket in the system's tmp directory assuming it supports sockets
+ real_path = g_strdup_printf("%s%cgeany_socket.%d",
+ g_get_tmp_dir(), G_DIR_SEPARATOR, (gint) time(NULL));
+
+ if (utils_is_file_writeable(real_path) != 0)
+ { // if real_path is not writable for us, fall back to /home/user/.geany/geany_socket
+ // instead of creating a symlink and print a warning
+ g_warning("Socket %s could not be written, using %s as fallback.", real_path, path);
+ setptr(real_path, g_strdup(path));
+ }
+ // create a symlink in e.g. /home/user/.geany/geany_socket to /tmp/geany_socket.1202396669
+ else if (symlink(real_path, path) != 0)
+ {
+ perror("symlink");
+ socket_fd_close(sock);
+ return -1;
+ }
+
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
- strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
+ strncpy(addr.sun_path, real_path, sizeof(addr.sun_path) - 1);
+ g_free(real_path);
+
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
{
perror("bind");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list