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

Function cli_scope_host_child

tests/test_cli.c:1635–1726  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1633} cli_scope_fixture_t;
1634
1635static _Noreturn void cli_scope_host_child(const cli_scope_fixture_t *fixture, int ready_fd,
1636 int release_fd) {
1637 cbm_daemon_ipc_endpoint_t *endpoint =
1638 cbm_daemon_bootstrap_endpoint_new(fixture->runtime_parent);
1639 cbm_version_cohort_manager_t *manager =
1640 endpoint ? cbm_version_cohort_manager_new(endpoint) : NULL;
1641 cbm_version_cohort_lease_t *lease = NULL;
1642 cbm_daemon_conflict_t conflict;
1643 cbm_daemon_runtime_service_t *service = NULL;
1644 int acquire_status = -1;
1645 if (endpoint && manager) {
1646 /* UINT64_MAX: wait as long as a lock is held, never for a conflicting
1647 * holder (that is answered at once), so no deadline decides the join. */
1648 acquire_status = (int)cbm_version_cohort_acquire(manager, &fixture->identity, UINT64_MAX,
1649 &lease, &conflict);
1650 }
1651 bool admitted = acquire_status == (int)CBM_VERSION_COHORT_OK;
1652 if (admitted) {
1653 cbm_daemon_runtime_service_config_t config = {
1654 .endpoint = endpoint,
1655 .identity = fixture->identity,
1656 .conflict_log_path = fixture->conflict_log,
1657 .conflict_log_cap_bytes = 64U * 1024U,
1658 .max_clients = 8,
1659 .lease_timeout_ms = CLI_SCOPE_TIMEOUT_MS,
1660 .request_timeout_ms = CLI_SCOPE_TIMEOUT_MS,
1661 .shutdown_timeout_ms = CLI_SCOPE_TIMEOUT_MS,
1662 /* Born permanent: only a drain/stop ends it, never the parent's
1663 * client leaving, so "still alive" is a statement about the
1664 * drain alone. */
1665 .permanent = true,
1666 };
1667 service = cbm_daemon_runtime_service_start(&config);
1668 }
1669 bool ready_ok =
1670 service && cbm_daemon_runtime_service_state(service) == CBM_DAEMON_RUNTIME_SERVICE_RUNNING;
1671 if (!ready_ok) {
1672 /* The parent sees only 'E'; say here which step it was. */
1673 const char *step = !endpoint ? "creating the endpoint"
1674 : !manager ? "creating the cohort manager"
1675 : !admitted ? "joining the version cohort"
1676 : !service ? "starting the runtime service"
1677 : "reaching the running state";
1678 (void)fprintf(stderr, "cli scope host: setup failed at %s (cohort status %d)\n", step,
1679 acquire_status);
1680 }
1681 char ready = ready_ok ? 'R' : 'E';
1682 (void)write(ready_fd, &ready, 1);
1683 close(ready_fd);
1684 bool drained = false;
1685 /* The parent owns the release pipe. If it exits, poll observes POLLHUP;
1686 * a fixed lifetime can stop a healthy host during a slow binary install. */
1687 while (ready_ok) {
1688 if (cbm_daemon_runtime_service_wait_exited(service, 50U)) {
1689 drained = true;
1690 break;
1691 }
1692 struct pollfd release_poll = {.fd = release_fd, .events = POLLIN, .revents = 0};

Callers 1

cli_scope_fixture_startFunction · 0.85

Tested by

no test coverage detected