Better error handling on ioctl call