3 #include "simple-ipc.h"
4 #include "fsmonitor-ipc.h"
5 #include "run-command.h"
9 #ifdef HAVE_FSMONITOR_DAEMON_BACKEND
11 int fsmonitor_ipc__is_supported(void)
16 GIT_PATH_FUNC(fsmonitor_ipc__get_path, "fsmonitor--daemon.ipc")
18 enum ipc_active_state fsmonitor_ipc__get_state(void)
20 return ipc_get_active_state(fsmonitor_ipc__get_path());
23 static int spawn_daemon(void)
25 const char *args[] = { "fsmonitor--daemon", "start", NULL };
27 return run_command_v_opt_tr2(args, RUN_COMMAND_NO_STDIN | RUN_GIT_CMD,
31 int fsmonitor_ipc__send_query(const char *since_token,
32 struct strbuf *answer)
35 int tried_to_spawn = 0;
36 enum ipc_active_state state = IPC_STATE__OTHER_ERROR;
37 struct ipc_client_connection *connection = NULL;
38 struct ipc_client_connect_options options
39 = IPC_CLIENT_CONNECT_OPTIONS_INIT;
41 options.wait_if_busy = 1;
42 options.wait_if_not_found = 0;
44 trace2_region_enter("fsm_client", "query", NULL);
46 trace2_data_string("fsm_client", NULL, "query/command",
50 state = ipc_client_try_connect(fsmonitor_ipc__get_path(), &options,
54 case IPC_STATE__LISTENING:
55 ret = ipc_client_send_command_to_connection(
56 connection, since_token, strlen(since_token), answer);
57 ipc_client_close_connection(connection);
59 trace2_data_intmax("fsm_client", NULL,
60 "query/response-length", answer->len);
62 if (fsmonitor_is_trivial_response(answer))
63 trace2_data_intmax("fsm_client", NULL,
64 "query/trivial-response", 1);
68 case IPC_STATE__NOT_LISTENING:
69 ret = error(_("fsmonitor_ipc__send_query: daemon not available"));
72 case IPC_STATE__PATH_NOT_FOUND:
81 * Try again, but this time give the daemon a chance to
82 * actually create the pipe/socket.
84 * Granted, the daemon just started so it can't possibly have
85 * any FS cached yet, so we'll always get a trivial answer.
86 * BUT the answer should include a new token that can serve
87 * as the basis for subsequent requests.
89 options.wait_if_not_found = 1;
92 case IPC_STATE__INVALID_PATH:
93 ret = error(_("fsmonitor_ipc__send_query: invalid path '%s'"),
94 fsmonitor_ipc__get_path());
97 case IPC_STATE__OTHER_ERROR:
99 ret = error(_("fsmonitor_ipc__send_query: unspecified error on '%s'"),
100 fsmonitor_ipc__get_path());
105 trace2_region_leave("fsm_client", "query", NULL);
110 int fsmonitor_ipc__send_command(const char *command,
111 struct strbuf *answer)
113 struct ipc_client_connection *connection = NULL;
114 struct ipc_client_connect_options options
115 = IPC_CLIENT_CONNECT_OPTIONS_INIT;
117 enum ipc_active_state state;
119 strbuf_reset(answer);
121 options.wait_if_busy = 1;
122 options.wait_if_not_found = 0;
124 state = ipc_client_try_connect(fsmonitor_ipc__get_path(), &options,
126 if (state != IPC_STATE__LISTENING) {
127 die("fsmonitor--daemon is not running");
131 ret = ipc_client_send_command_to_connection(connection,
132 command, strlen(command),
134 ipc_client_close_connection(connection);
137 die("could not send '%s' command to fsmonitor--daemon",
148 * A trivial implementation of the fsmonitor_ipc__ API for unsupported
152 int fsmonitor_ipc__is_supported(void)
157 const char *fsmonitor_ipc__get_path(void)
162 enum ipc_active_state fsmonitor_ipc__get_state(void)
164 return IPC_STATE__OTHER_ERROR;
167 int fsmonitor_ipc__send_query(const char *since_token,
168 struct strbuf *answer)
173 int fsmonitor_ipc__send_command(const char *command,
174 struct strbuf *answer)