mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Use user-specific temp directory for mate’s socket
We have TextMate create a named socket that ‘mate’ can use to contact the main application. Previously it was hardcoded to ‘/tmp/avian.sock’ which is bad on a multi-user system. Placing it in the user’s temporary directory should ensure it doesn’t clash, yet still give us a predictable path (for mate to use). Presently we maintain the old socket path as a link to the new location so that old versions of mate will still work.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
OAK_DEBUG_VAR(RMateServer);
|
||||
|
||||
#define SOCKET_PATH "/tmp/avian.sock"
|
||||
#define OLD_SOCKET_PATH "/tmp/avian.sock"
|
||||
|
||||
/*
|
||||
open
|
||||
@@ -120,28 +120,34 @@ namespace
|
||||
{
|
||||
struct mate_server_t
|
||||
{
|
||||
mate_server_t ()
|
||||
mate_server_t () : _socket_path(path::join(path::temp(), "textmate.sock"))
|
||||
{
|
||||
D(DBF_RMateServer, bug("%s\n", SOCKET_PATH););
|
||||
unlink(SOCKET_PATH);
|
||||
D(DBF_RMateServer, bug("%s\n", _socket_path.c_str()););
|
||||
unlink(_socket_path.c_str());
|
||||
|
||||
socket_t fd(socket(AF_UNIX, SOCK_STREAM, 0));
|
||||
fcntl(fd, F_SETFD, 1);
|
||||
struct sockaddr_un addr = { 0, AF_UNIX, SOCKET_PATH };
|
||||
struct sockaddr_un addr = { 0, AF_UNIX };
|
||||
strcpy(addr.sun_path, _socket_path.c_str());
|
||||
addr.sun_len = SUN_LEN(&addr);
|
||||
bind(fd, (sockaddr*)&addr, sizeof(addr));
|
||||
listen(fd, 5);
|
||||
|
||||
unlink(OLD_SOCKET_PATH);
|
||||
link(_socket_path.c_str(), OLD_SOCKET_PATH);
|
||||
|
||||
_callback.reset(new socket_callback_t(&rmate_connection_handler_t, fd));
|
||||
}
|
||||
|
||||
~mate_server_t ()
|
||||
{
|
||||
D(DBF_RMateServer, bug("%s\n", SOCKET_PATH););
|
||||
unlink(SOCKET_PATH);
|
||||
D(DBF_RMateServer, bug("%s\n", _socket_path.c_str()););
|
||||
unlink(_socket_path.c_str());
|
||||
unlink(OLD_SOCKET_PATH);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _socket_path;
|
||||
socket_callback_ptr _callback;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user