| 2088 | } |
| 2089 | |
| 2090 | static void *runtime_accept_loop(void *opaque) { |
| 2091 | cbm_daemon_runtime_service_t *service = opaque; |
| 2092 | for (;;) { |
| 2093 | runtime_reap_completed_workers(service); |
| 2094 | cbm_mutex_lock(&service->mutex); |
| 2095 | cbm_daemon_runtime_service_state_t state = service->state; |
| 2096 | cbm_mutex_unlock(&service->mutex); |
| 2097 | if (state == CBM_DAEMON_RUNTIME_SERVICE_EXITED) { |
| 2098 | break; |
| 2099 | } |
| 2100 | if (state == CBM_DAEMON_RUNTIME_SERVICE_STOPPING) { |
| 2101 | runtime_service_interrupt_connections(service); |
| 2102 | if (runtime_service_can_exit(service, cbm_now_ms())) { |
| 2103 | break; |
| 2104 | } |
| 2105 | uint64_t tick_deadline = runtime_deadline_after(1); |
| 2106 | runtime_wait_tick(tick_deadline); |
| 2107 | continue; |
| 2108 | } |
| 2109 | |
| 2110 | cbm_daemon_ipc_connection_t *connection = NULL; |
| 2111 | int accepted = |
| 2112 | cbm_daemon_ipc_accept(service->listener, RUNTIME_ACCEPT_POLL_MS, &connection); |
| 2113 | if (accepted == 1 && connection) { |
| 2114 | runtime_accept_connection(service, connection); |
| 2115 | } else if (accepted < 0) { |
| 2116 | /* IPC intentionally combines invalid-peer and listener errors. |
| 2117 | * Retry while RUNNING so one hostile peer cannot stop the daemon. */ |
| 2118 | uint64_t tick_deadline = runtime_deadline_after(1); |
| 2119 | runtime_wait_tick(tick_deadline); |
| 2120 | } |
| 2121 | } |
| 2122 | runtime_reap_completed_workers(service); |
| 2123 | atomic_store_explicit(&service->accept_thread_done, true, memory_order_release); |
| 2124 | return NULL; |
| 2125 | } |
| 2126 | |
| 2127 | static char *runtime_string_copy_bounded(const char *value, size_t capacity) { |
| 2128 | size_t length = 0; |
nothing calls this directly
no test coverage detected