Skip to content

Commit 6beb268

Browse files
edecosta-mwgitster
authored andcommitted
fsmonitor: relocate socket file if .git directory is remote
If the .git directory is on a remote filesystem, create the socket file in 'fsmonitor.socketDir' if it is defined, else create it in $HOME. Signed-off-by: Eric DeCosta <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 508c1a5 commit 6beb268

File tree

8 files changed

+78
-13
lines changed

8 files changed

+78
-13
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,7 @@ ifdef FSMONITOR_DAEMON_BACKEND
20322032
COMPAT_CFLAGS += -DHAVE_FSMONITOR_DAEMON_BACKEND
20332033
COMPAT_OBJS += compat/fsmonitor/fsm-listen-$(FSMONITOR_DAEMON_BACKEND).o
20342034
COMPAT_OBJS += compat/fsmonitor/fsm-health-$(FSMONITOR_DAEMON_BACKEND).o
2035+
COMPAT_OBJS += compat/fsmonitor/fsm-ipc-$(FSMONITOR_DAEMON_BACKEND).o
20352036
endif
20362037

20372038
ifdef FSMONITOR_OS_SETTINGS

builtin/fsmonitor--daemon.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,8 @@ static int fsmonitor_run_daemon(void)
13431343
* directory.)
13441344
*/
13451345
strbuf_init(&state.path_ipc, 0);
1346-
strbuf_addstr(&state.path_ipc, absolute_path(fsmonitor_ipc__get_path()));
1346+
strbuf_addstr(&state.path_ipc,
1347+
absolute_path(fsmonitor_ipc__get_path(the_repository)));
13471348

13481349
/*
13491350
* Confirm that we can create platform-specific resources for the

compat/fsmonitor/fsm-ipc-darwin.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "cache.h"
2+
#include "config.h"
3+
#include "strbuf.h"
4+
#include "fsmonitor.h"
5+
#include "fsmonitor-ipc.h"
6+
#include "fsmonitor-path-utils.h"
7+
8+
static GIT_PATH_FUNC(fsmonitor_ipc__get_default_path, "fsmonitor--daemon.ipc")
9+
10+
const char *fsmonitor_ipc__get_path(struct repository *r)
11+
{
12+
static const char *ipc_path = NULL;
13+
SHA_CTX sha1ctx;
14+
char *sock_dir = NULL;
15+
struct strbuf ipc_file = STRBUF_INIT;
16+
unsigned char hash[SHA_DIGEST_LENGTH];
17+
18+
if (!r)
19+
BUG("No repository passed into fsmonitor_ipc__get_path");
20+
21+
if (ipc_path)
22+
return ipc_path;
23+
24+
25+
/* By default the socket file is created in the .git directory */
26+
if (fsmonitor__is_fs_remote(r->gitdir) < 1) {
27+
ipc_path = fsmonitor_ipc__get_default_path();
28+
return ipc_path;
29+
}
30+
31+
SHA1_Init(&sha1ctx);
32+
SHA1_Update(&sha1ctx, r->worktree, strlen(r->worktree));
33+
SHA1_Final(hash, &sha1ctx);
34+
35+
repo_config_get_string(r, "fsmonitor.socketdir", &sock_dir);
36+
37+
/* Create the socket file in either socketDir or $HOME */
38+
if (sock_dir && *sock_dir) {
39+
strbuf_addf(&ipc_file, "%s/.git-fsmonitor-%s",
40+
sock_dir, hash_to_hex(hash));
41+
} else {
42+
strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s", hash_to_hex(hash));
43+
}
44+
free(sock_dir);
45+
46+
ipc_path = interpolate_path(ipc_file.buf, 1);
47+
if (!ipc_path)
48+
die(_("Invalid path: %s"), ipc_file.buf);
49+
50+
strbuf_release(&ipc_file);
51+
return ipc_path;
52+
}

compat/fsmonitor/fsm-ipc-win32.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "config.h"
2+
#include "fsmonitor-ipc.h"
3+
4+
const char *fsmonitor_ipc__get_path(struct repository *r) {
5+
static char *ret;
6+
if (!ret)
7+
ret = git_pathdup("fsmonitor--daemon.ipc");
8+
return ret;
9+
}

compat/fsmonitor/fsm-settings-darwin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
static enum fsmonitor_reason check_uds_volume(struct repository *r)
2727
{
2828
struct fs_info fs;
29-
const char *ipc_path = fsmonitor_ipc__get_path();
29+
const char *ipc_path = fsmonitor_ipc__get_path(r);
3030
struct strbuf path = STRBUF_INIT;
3131
strbuf_add(&path, ipc_path, strlen(ipc_path));
3232

contrib/buildsystems/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ if(SUPPORTS_SIMPLE_IPC)
308308
add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND)
309309
list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-win32.c)
310310
list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-win32.c)
311+
list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-win32.c)
311312
list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-win32.c)
312313

313314
add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS)
@@ -316,6 +317,7 @@ if(SUPPORTS_SIMPLE_IPC)
316317
add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND)
317318
list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-darwin.c)
318319
list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-darwin.c)
320+
list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-darwin.c)
319321
list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-darwin.c)
320322

321323
add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS)

fsmonitor-ipc.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int fsmonitor_ipc__is_supported(void)
1818
return 0;
1919
}
2020

21-
const char *fsmonitor_ipc__get_path(void)
21+
const char *fsmonitor_ipc__get_path(struct repository *r)
2222
{
2323
return NULL;
2424
}
@@ -47,11 +47,9 @@ int fsmonitor_ipc__is_supported(void)
4747
return 1;
4848
}
4949

50-
GIT_PATH_FUNC(fsmonitor_ipc__get_path, "fsmonitor--daemon.ipc")
51-
5250
enum ipc_active_state fsmonitor_ipc__get_state(void)
5351
{
54-
return ipc_get_active_state(fsmonitor_ipc__get_path());
52+
return ipc_get_active_state(fsmonitor_ipc__get_path(the_repository));
5553
}
5654

5755
static int spawn_daemon(void)
@@ -81,8 +79,8 @@ int fsmonitor_ipc__send_query(const char *since_token,
8179
trace2_data_string("fsm_client", NULL, "query/command", tok);
8280

8381
try_again:
84-
state = ipc_client_try_connect(fsmonitor_ipc__get_path(), &options,
85-
&connection);
82+
state = ipc_client_try_connect(fsmonitor_ipc__get_path(the_repository),
83+
&options, &connection);
8684

8785
switch (state) {
8886
case IPC_STATE__LISTENING:
@@ -117,13 +115,13 @@ int fsmonitor_ipc__send_query(const char *since_token,
117115

118116
case IPC_STATE__INVALID_PATH:
119117
ret = error(_("fsmonitor_ipc__send_query: invalid path '%s'"),
120-
fsmonitor_ipc__get_path());
118+
fsmonitor_ipc__get_path(the_repository));
121119
goto done;
122120

123121
case IPC_STATE__OTHER_ERROR:
124122
default:
125123
ret = error(_("fsmonitor_ipc__send_query: unspecified error on '%s'"),
126-
fsmonitor_ipc__get_path());
124+
fsmonitor_ipc__get_path(the_repository));
127125
goto done;
128126
}
129127

@@ -149,8 +147,8 @@ int fsmonitor_ipc__send_command(const char *command,
149147
options.wait_if_busy = 1;
150148
options.wait_if_not_found = 0;
151149

152-
state = ipc_client_try_connect(fsmonitor_ipc__get_path(), &options,
153-
&connection);
150+
state = ipc_client_try_connect(fsmonitor_ipc__get_path(the_repository),
151+
&options, &connection);
154152
if (state != IPC_STATE__LISTENING) {
155153
die(_("fsmonitor--daemon is not running"));
156154
return -1;

fsmonitor-ipc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "simple-ipc.h"
55

6+
struct repository;
7+
68
/*
79
* Returns true if built-in file system monitor daemon is defined
810
* for this platform.
@@ -16,7 +18,7 @@ int fsmonitor_ipc__is_supported(void);
1618
*
1719
* Returns NULL if the daemon is not supported on this platform.
1820
*/
19-
const char *fsmonitor_ipc__get_path(void);
21+
const char *fsmonitor_ipc__get_path(struct repository *r);
2022

2123
/*
2224
* Try to determine whether there is a `git-fsmonitor--daemon` process

0 commit comments

Comments
 (0)