I have a Linux character character driver that creates the /dev/mything
, and then a C ++ / Qt program that opens the device and uses it. If this program crashes with exit()
, the device closes and the driver correctly resets itself. But if the program exits abnormally, through segfault or SIGINT
or something else, the device is not closed properly.
My current workaround is to restart the driver if it is stuck in an βopenβ state.
This line in the driver tries to prevent the simultaneous use of several programs using the device:
int mything_open( struct inode* inode, struct file* filp ) { ... if ( port->rings[bufcount].virt_addr ) return -EBUSY; ... }
Then it will clear:
int mything_release( struct inode* inode, struct file* filp ) { ... port->rings[bufcount].virt_addr = NULL; ... }
I think exit()
calls mything_release
, but SIGINT
not. How can I make the driver more reliable in this situation?
EDIT:
Here are the operations that I performed. Maybe I missed something?
static struct file_operations fatpipe_fops = { .owner = THIS_MODULE, .open = mything_open, .release = mything_release, .read = mything_read, .write = mything_write, .ioctl = mything_ioctl };
source share