3 #include "simple-ipc.h"
4 #include "fsmonitor-ipc.h"
5 #include "run-command.h"
9 #ifndef HAVE_FSMONITOR_DAEMON_BACKEND
12 * A trivial implementation of the fsmonitor_ipc__ API for unsupported
16 int fsmonitor_ipc__is_supported(void)
21 const char *fsmonitor_ipc__get_path(void)
26 enum ipc_active_state
fsmonitor_ipc__get_state(void)
28 return IPC_STATE__OTHER_ERROR
;
31 int fsmonitor_ipc__send_query(const char *since_token
,
32 struct strbuf
*answer
)
37 int fsmonitor_ipc__send_command(const char *command
,
38 struct strbuf
*answer
)
45 int fsmonitor_ipc__is_supported(void)
50 GIT_PATH_FUNC(fsmonitor_ipc__get_path
, "fsmonitor--daemon.ipc")
52 enum ipc_active_state
fsmonitor_ipc__get_state(void)
54 return ipc_get_active_state(fsmonitor_ipc__get_path());
57 static int spawn_daemon(void)
59 const char *args
[] = { "fsmonitor--daemon", "start", NULL
};
61 return run_command_v_opt_tr2(args
, RUN_COMMAND_NO_STDIN
| RUN_GIT_CMD
,
65 int fsmonitor_ipc__send_query(const char *since_token
,
66 struct strbuf
*answer
)
69 int tried_to_spawn
= 0;
70 enum ipc_active_state state
= IPC_STATE__OTHER_ERROR
;
71 struct ipc_client_connection
*connection
= NULL
;
72 struct ipc_client_connect_options options
73 = IPC_CLIENT_CONNECT_OPTIONS_INIT
;
74 const char *tok
= since_token
? since_token
: "";
75 size_t tok_len
= since_token
? strlen(since_token
) : 0;
77 options
.wait_if_busy
= 1;
78 options
.wait_if_not_found
= 0;
80 trace2_region_enter("fsm_client", "query", NULL
);
81 trace2_data_string("fsm_client", NULL
, "query/command", tok
);
84 state
= ipc_client_try_connect(fsmonitor_ipc__get_path(), &options
,
88 case IPC_STATE__LISTENING
:
89 ret
= ipc_client_send_command_to_connection(
90 connection
, tok
, tok_len
, answer
);
91 ipc_client_close_connection(connection
);
93 trace2_data_intmax("fsm_client", NULL
,
94 "query/response-length", answer
->len
);
97 case IPC_STATE__NOT_LISTENING
:
98 case IPC_STATE__PATH_NOT_FOUND
:
107 * Try again, but this time give the daemon a chance to
108 * actually create the pipe/socket.
110 * Granted, the daemon just started so it can't possibly have
111 * any FS cached yet, so we'll always get a trivial answer.
112 * BUT the answer should include a new token that can serve
113 * as the basis for subsequent requests.
115 options
.wait_if_not_found
= 1;
118 case IPC_STATE__INVALID_PATH
:
119 ret
= error(_("fsmonitor_ipc__send_query: invalid path '%s'"),
120 fsmonitor_ipc__get_path());
123 case IPC_STATE__OTHER_ERROR
:
125 ret
= error(_("fsmonitor_ipc__send_query: unspecified error on '%s'"),
126 fsmonitor_ipc__get_path());
131 trace2_region_leave("fsm_client", "query", NULL
);
136 int fsmonitor_ipc__send_command(const char *command
,
137 struct strbuf
*answer
)
139 struct ipc_client_connection
*connection
= NULL
;
140 struct ipc_client_connect_options options
141 = IPC_CLIENT_CONNECT_OPTIONS_INIT
;
143 enum ipc_active_state state
;
144 const char *c
= command
? command
: "";
145 size_t c_len
= command
? strlen(command
) : 0;
147 strbuf_reset(answer
);
149 options
.wait_if_busy
= 1;
150 options
.wait_if_not_found
= 0;
152 state
= ipc_client_try_connect(fsmonitor_ipc__get_path(), &options
,
154 if (state
!= IPC_STATE__LISTENING
) {
155 die(_("fsmonitor--daemon is not running"));
159 ret
= ipc_client_send_command_to_connection(connection
, c
, c_len
,
161 ipc_client_close_connection(connection
);
164 die(_("could not send '%s' command to fsmonitor--daemon"), c
);