/*Internal function to perform UHID write and error checking*/
static int uhid_write(int fd, const struct uhid_event *ev)
{
- ssize_t ret = write(fd, ev, sizeof(*ev));
- ssize_t ret;
- ret = TEMP_FAILURE_RETRY(write(fd, ev, sizeof(*ev)));
++ ssize_t ret = TEMP_FAILURE_RETRY(write(fd, ev, sizeof(*ev)));
+
if (ret < 0){
int rtn = -errno;
APPL_TRACE_ERROR("%s: Cannot write to uhid:%s",
pfds[0].fd = p_dev->fd;
pfds[0].events = POLLIN;
+ // Set the uhid fd as non-blocking to ensure we never block the BTU thread
+ uhid_set_non_blocking(p_dev->fd);
+
while(p_dev->hh_keep_polling){
- ret = poll(pfds, 1, 50);
+ ret = TEMP_FAILURE_RETRY(poll(pfds, 1, 50));
if (ret < 0) {
APPL_TRACE_ERROR("%s: Cannot poll for fds: %s\n", __FUNCTION__, strerror(errno));
break;
{
int addr_fd;
- BTIF_TRACE_DEBUG("local bdaddr is stored in %s", val);
+ BTIF_TRACE_DEBUG("%s, local bdaddr is stored in %s", __func__, val);
- if ((addr_fd = open(val, O_RDONLY)) != -1)
+ if ((addr_fd = TEMP_FAILURE_RETRY(open(val, O_RDONLY))) != -1)
{
memset(val, 0, sizeof(val));
- read(addr_fd, val, FACTORY_BT_BDADDR_STORAGE_LEN);
+ TEMP_FAILURE_RETRY(read(addr_fd, val, FACTORY_BT_BDADDR_STORAGE_LEN));
- string_to_bdaddr(val, local_addr);
/* If this is not a reserved/special bda, then use it */
- if (memcmp(local_addr->address, null_bdaddr, BD_ADDR_LEN) != 0)
+ if ((string_to_bdaddr(val, local_addr)) &&
+ (memcmp(local_addr->address, null_bdaddr, BD_ADDR_LEN) != 0))
{
valid_bda = TRUE;
- BTIF_TRACE_DEBUG("Got Factory BDA %02X:%02X:%02X:%02X:%02X:%02X",
- local_addr->address[0], local_addr->address[1], local_addr->address[2],
- local_addr->address[3], local_addr->address[4], local_addr->address[5]);
+ BTIF_TRACE_DEBUG("%s: Got Factory BDA %s", __func__, val);
}
-
close(addr_fd);
}
}