MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / main_run_daemon_ctl

Function main_run_daemon_ctl

src/main.c:2165–2367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2163}
2164
2165static int main_run_daemon_ctl(int argc, char **argv, const cbm_daemon_ipc_endpoint_t *endpoint,
2166 const cbm_daemon_build_identity_t *identity,
2167 const char *executable_path) {
2168 const char *subcommand = NULL;
2169 bool open_browser = false;
2170 int requested_port = 0;
2171 bool arguments_valid = true;
2172 for (int index = 1; index < argc; index++) {
2173 if (strcmp(argv[index], "daemon") == 0) {
2174 continue;
2175 }
2176 if (strcmp(argv[index], "start") == 0 || strcmp(argv[index], "stop") == 0 ||
2177 strcmp(argv[index], "status") == 0) {
2178 subcommand = argv[index];
2179 } else if (strcmp(argv[index], "--open") == 0) {
2180 open_browser = true;
2181 } else if (strncmp(argv[index], "--port=", 7) == 0) {
2182 requested_port = atoi(argv[index] + 7);
2183 if (requested_port <= 0 || requested_port >= MAIN_MAX_PORT) {
2184 (void)fprintf(stderr, "error: --port requires a value between 1 and 65535\n");
2185 return EXIT_FAILURE;
2186 }
2187 } else {
2188 (void)fprintf(stderr, "error: unknown daemon option: %s\n", argv[index]);
2189 arguments_valid = false;
2190 break;
2191 }
2192 }
2193 if (!arguments_valid || !subcommand) {
2194 (void)fprintf(stderr, "usage: codebase-memory-mcp daemon <start|stop|status> "
2195 "[--open] [--port=N]\n");
2196 return EXIT_FAILURE;
2197 }
2198
2199 cbm_daemon_runtime_status_t status;
2200 bool active = cbm_daemon_runtime_request_status(endpoint, identity,
2201 MAIN_DAEMON_CTL_PROBE_TIMEOUT_MS, &status);
2202
2203 if (strcmp(subcommand, "status") == 0) {
2204 if (!active) {
2205 printf("daemon: not running\n");
2206 printf("hint: `codebase-memory-mcp daemon start` keeps a daemon warm so CLI "
2207 "commands and hooks skip the per-command startup cost.\n");
2208 return EXIT_FAILURE;
2209 }
2210 printf("daemon: active (%s)\n", status.permanent ? "permanent" : "session-managed");
2211 printf(" pid: %lu\n", (unsigned long)status.daemon_pid);
2212 printf(" build: %s (%.12s...)\n", status.semantic_version, status.build_fingerprint);
2213 if (status.stopping) {
2214 printf(" state: stopping\n");
2215 }
2216 main_daemon_ctl_print_clients(status.client_pids, status.client_count,
2217 status.committed_clients);
2218 main_daemon_ctl_print_ui_configuration();
2219 return EXIT_SUCCESS;
2220 }
2221
2222 if (strcmp(subcommand, "stop") == 0) {

Callers 1

mainFunction · 0.85

Tested by

no test coverage detected