services[service].size = 0;
}
-static void handle_msg(void *buf, ssize_t len)
+static bool handle_msg(void *buf, ssize_t len)
{
struct ipc_hdr *msg = buf;
const struct hal_ipc_handler *handler;
uint8_t opcode;
if (len < (ssize_t) sizeof(*msg)) {
- error("IPC: message too small (%zd bytes), aborting", len);
- exit(EXIT_FAILURE);
+ error("IPC: message too small (%zd bytes)", len);
+ return false;
}
if (len != (ssize_t) (sizeof(*msg) + msg->len)) {
- error("IPC: message malformed (%zd bytes), aborting", len);
- exit(EXIT_FAILURE);
+ error("IPC: message malformed (%zd bytes)", len);
+ return false;
}
/* if service is valid */
if (msg->service_id > HAL_SERVICE_ID_MAX) {
- error("IPC: unknown service (0x%x), aborting",
- msg->service_id);
- exit(EXIT_FAILURE);
+ error("IPC: unknown service (0x%x)", msg->service_id);
+ return false;
}
/* if service is registered */
if (!services[msg->service_id].handler) {
- error("IPC: unregistered service (0x%x), aborting",
- msg->service_id);
- exit(EXIT_FAILURE);
+ error("IPC: unregistered service (0x%x)", msg->service_id);
+ return false;
}
/* if opcode fit valid range */
if (msg->opcode < HAL_MINIMUM_EVENT) {
- error("IPC: invalid opcode for service 0x%x (0x%x), aborting",
+ error("IPC: invalid opcode for service 0x%x (0x%x)",
msg->service_id, msg->opcode);
- exit(EXIT_FAILURE);
+ return false;
}
/*
/* if opcode is valid */
if (opcode >= services[msg->service_id].size) {
- error("IPC: invalid opcode for service 0x%x (0x%x), aborting",
+ error("IPC: invalid opcode for service 0x%x (0x%x)",
msg->service_id, msg->opcode);
- exit(EXIT_FAILURE);
+ return false;
}
handler = &services[msg->service_id].handler[opcode];
if ((handler->var_len && handler->data_len > msg->len) ||
(!handler->var_len && handler->data_len != msg->len)) {
error("IPC: message size invalid for service 0x%x opcode 0x%x "
- "(%u bytes), aborting",
+ "(%u bytes)",
msg->service_id, msg->opcode, msg->len);
- exit(EXIT_FAILURE);
+ return false;
}
handler->handler(msg->payload, msg->len);
+
+ return true;
}
static void *notification_handler(void *data)
}
}
- handle_msg(buf, ret);
+ if (!handle_msg(buf, ret))
+ exit(EXIT_FAILURE);
}
close(notif_sk);