| 2919 | } |
| 2920 | |
| 2921 | static bool runtime_control_request_send(const cbm_daemon_ipc_endpoint_t *endpoint, |
| 2922 | const cbm_daemon_build_identity_t *identity, |
| 2923 | cbm_daemon_runtime_operation_t operation, |
| 2924 | uint32_t timeout_ms, uint32_t response_size, |
| 2925 | uint8_t **payload_out, uint64_t *muted_holder_pid_out) { |
| 2926 | *payload_out = NULL; |
| 2927 | if (muted_holder_pid_out) { |
| 2928 | *muted_holder_pid_out = 0; |
| 2929 | } |
| 2930 | if (!endpoint || !identity || !identity->build_fingerprint || |
| 2931 | timeout_ms == CBM_DAEMON_IPC_WAIT_FOREVER) { |
| 2932 | return false; |
| 2933 | } |
| 2934 | uint8_t request[CBM_DAEMON_CONTROL_REQUEST_SIZE]; |
| 2935 | memset(request, 0, sizeof(request)); |
| 2936 | int written = snprintf((char *)request, sizeof(request), "%s", identity->build_fingerprint); |
| 2937 | if (written <= 0 || (size_t)written != CBM_DAEMON_BUILD_FINGERPRINT_SIZE - 1U) { |
| 2938 | return false; |
| 2939 | } |
| 2940 | cbm_daemon_ipc_connection_t *connection = cbm_daemon_ipc_connect(endpoint, timeout_ms); |
| 2941 | bool sent = |
| 2942 | connection && cbm_daemon_ipc_send_frame(connection, CBM_DAEMON_FRAME_REQUEST, operation, |
| 2943 | request, (uint32_t)sizeof(request)); |
| 2944 | cbm_daemon_frame_t frame = {0}; |
| 2945 | uint8_t *payload = NULL; |
| 2946 | int received = sent ? cbm_daemon_ipc_receive_frame_bounded(connection, timeout_ms, |
| 2947 | response_size, &frame, &payload) |
| 2948 | : 0; |
| 2949 | if (muted_holder_pid_out && sent && |
| 2950 | (received != 1 || (frame.type == CBM_DAEMON_FRAME_RESPONSE && frame.flags != operation))) { |
| 2951 | /* Connected but not served: either total silence (dead runtime), or a |
| 2952 | * wrong-operation reject frame (a wedged generation whose accept path |
| 2953 | * still answers inline while every worker slot is stuck). Both are |
| 2954 | * the zombie class — surface the holder's kernel-reported pid so |
| 2955 | * `daemon status` can name it instead of reporting "not running". */ |
| 2956 | *muted_holder_pid_out = cbm_daemon_ipc_connection_peer_pid(connection); |
| 2957 | } |
| 2958 | bool valid = received == 1 && frame.type == CBM_DAEMON_FRAME_RESPONSE && |
| 2959 | frame.flags == operation && frame.length == response_size && payload && |
| 2960 | payload[0] == 1U; |
| 2961 | cbm_daemon_ipc_connection_close(connection); |
| 2962 | if (!valid) { |
| 2963 | free(payload); |
| 2964 | return false; |
| 2965 | } |
| 2966 | *payload_out = payload; |
| 2967 | return true; |
| 2968 | } |
| 2969 | |
| 2970 | static uint32_t runtime_control_read_u32(const uint8_t *bytes) { |
| 2971 | return ((uint32_t)bytes[0] << 24) | ((uint32_t)bytes[1] << 16) | ((uint32_t)bytes[2] << 8) | |
no test coverage detected