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