| 1806 | } |
| 1807 | |
| 1808 | static void runtime_worker_handle_status(cbm_daemon_runtime_worker_t *worker, |
| 1809 | const uint8_t *payload, uint32_t length) { |
| 1810 | cbm_daemon_runtime_service_t *service = worker->service; |
| 1811 | char requested_build[CBM_DAEMON_BUILD_FINGERPRINT_SIZE] = {0}; |
| 1812 | bool peer_verified = |
| 1813 | runtime_control_request_decode(payload, length, requested_build) && |
| 1814 | runtime_activation_peer_matches_claim(service, worker->peer_process_id, requested_build); |
| 1815 | uint8_t response[CBM_DAEMON_STATUS_RESPONSE_SIZE]; |
| 1816 | memset(response, 0, sizeof(response)); |
| 1817 | if (peer_verified) { |
| 1818 | uint8_t count = 0U; |
| 1819 | uint32_t pids[CBM_DAEMON_CONTROL_CLIENT_CAP] = {0}; |
| 1820 | cbm_mutex_lock(&service->mutex); |
| 1821 | response[0] = 1U; |
| 1822 | response[1] = |
| 1823 | (uint8_t)((service->permanent ? 0x01U : 0U) | |
| 1824 | (service->state != CBM_DAEMON_RUNTIME_SERVICE_RUNNING ? 0x02U : 0U)); |
| 1825 | uint16_t committed = service->committed_clients > UINT16_MAX |
| 1826 | ? UINT16_MAX |
| 1827 | : (uint16_t)service->committed_clients; |
| 1828 | response[2] = (uint8_t)(committed >> 8); |
| 1829 | response[3] = (uint8_t)(committed & 0xFFU); |
| 1830 | uint32_t daemon_pid = (uint32_t)runtime_current_process_id(); |
| 1831 | response[4] = (uint8_t)(daemon_pid >> 24); |
| 1832 | response[5] = (uint8_t)(daemon_pid >> 16); |
| 1833 | response[6] = (uint8_t)(daemon_pid >> 8); |
| 1834 | response[7] = (uint8_t)(daemon_pid & 0xFFU); |
| 1835 | runtime_control_collect_clients_locked(service, worker, &count, pids); |
| 1836 | response[8] = count; |
| 1837 | for (size_t index = 0; index < CBM_DAEMON_CONTROL_CLIENT_CAP; index++) { |
| 1838 | size_t offset = 12U + index * 4U; |
| 1839 | response[offset] = (uint8_t)(pids[index] >> 24); |
| 1840 | response[offset + 1U] = (uint8_t)(pids[index] >> 16); |
| 1841 | response[offset + 2U] = (uint8_t)(pids[index] >> 8); |
| 1842 | response[offset + 3U] = (uint8_t)(pids[index] & 0xFFU); |
| 1843 | } |
| 1844 | (void)snprintf((char *)response + 44U, CBM_DAEMON_BUILD_FINGERPRINT_SIZE, "%s", |
| 1845 | service->identity.build_fingerprint); |
| 1846 | (void)snprintf((char *)response + 109U, 12U, "%s", |
| 1847 | service->identity.semantic_version ? service->identity.semantic_version |
| 1848 | : ""); |
| 1849 | cbm_mutex_unlock(&service->mutex); |
| 1850 | } |
| 1851 | (void)runtime_worker_send_frame(worker, CBM_DAEMON_FRAME_RESPONSE, CBM_DAEMON_RUNTIME_OP_STATUS, |
| 1852 | response, (uint32_t)sizeof(response)); |
| 1853 | runtime_worker_finish(worker); |
| 1854 | } |
| 1855 | |
| 1856 | static void runtime_worker_handle_stop(cbm_daemon_runtime_worker_t *worker, const uint8_t *payload, |
| 1857 | uint32_t length) { |
no test coverage detected