| 1476 | } |
| 1477 | |
| 1478 | static void runtime_worker_handle_status(cbm_daemon_runtime_worker_t *worker, |
| 1479 | const uint8_t *payload, uint32_t length) { |
| 1480 | cbm_daemon_runtime_service_t *service = worker->service; |
| 1481 | char requested_build[CBM_DAEMON_BUILD_FINGERPRINT_SIZE] = {0}; |
| 1482 | bool peer_verified = |
| 1483 | runtime_control_request_decode(payload, length, requested_build) && |
| 1484 | runtime_activation_peer_matches_claim(service, worker->peer_process_id, requested_build); |
| 1485 | uint8_t response[CBM_DAEMON_STATUS_RESPONSE_SIZE]; |
| 1486 | memset(response, 0, sizeof(response)); |
| 1487 | if (peer_verified) { |
| 1488 | uint8_t count = 0U; |
| 1489 | uint32_t pids[CBM_DAEMON_CONTROL_CLIENT_CAP] = {0}; |
| 1490 | cbm_mutex_lock(&service->mutex); |
| 1491 | response[0] = 1U; |
| 1492 | response[1] = |
| 1493 | (uint8_t)((service->permanent ? 0x01U : 0U) | |
| 1494 | (service->state != CBM_DAEMON_RUNTIME_SERVICE_RUNNING ? 0x02U : 0U)); |
| 1495 | uint16_t committed = service->committed_clients > UINT16_MAX |
| 1496 | ? UINT16_MAX |
| 1497 | : (uint16_t)service->committed_clients; |
| 1498 | response[2] = (uint8_t)(committed >> 8); |
| 1499 | response[3] = (uint8_t)(committed & 0xFFU); |
| 1500 | uint32_t daemon_pid = (uint32_t)runtime_current_process_id(); |
| 1501 | response[4] = (uint8_t)(daemon_pid >> 24); |
| 1502 | response[5] = (uint8_t)(daemon_pid >> 16); |
| 1503 | response[6] = (uint8_t)(daemon_pid >> 8); |
| 1504 | response[7] = (uint8_t)(daemon_pid & 0xFFU); |
| 1505 | runtime_control_collect_clients_locked(service, worker, &count, pids); |
| 1506 | response[8] = count; |
| 1507 | for (size_t index = 0; index < CBM_DAEMON_CONTROL_CLIENT_CAP; index++) { |
| 1508 | size_t offset = 12U + index * 4U; |
| 1509 | response[offset] = (uint8_t)(pids[index] >> 24); |
| 1510 | response[offset + 1U] = (uint8_t)(pids[index] >> 16); |
| 1511 | response[offset + 2U] = (uint8_t)(pids[index] >> 8); |
| 1512 | response[offset + 3U] = (uint8_t)(pids[index] & 0xFFU); |
| 1513 | } |
| 1514 | (void)snprintf((char *)response + 44U, CBM_DAEMON_BUILD_FINGERPRINT_SIZE, "%s", |
| 1515 | service->identity.build_fingerprint); |
| 1516 | (void)snprintf((char *)response + 109U, 12U, "%s", |
| 1517 | service->identity.semantic_version ? service->identity.semantic_version |
| 1518 | : ""); |
| 1519 | cbm_mutex_unlock(&service->mutex); |
| 1520 | } |
| 1521 | (void)runtime_worker_send_frame(worker, CBM_DAEMON_FRAME_RESPONSE, CBM_DAEMON_RUNTIME_OP_STATUS, |
| 1522 | response, (uint32_t)sizeof(response)); |
| 1523 | runtime_worker_finish(worker); |
| 1524 | } |
| 1525 | |
| 1526 | static void runtime_worker_handle_stop(cbm_daemon_runtime_worker_t *worker, const uint8_t *payload, |
| 1527 | uint32_t length) { |
no test coverage detected