Alessandro Alessandro - 1 month ago 22
Linux Question

Linux driver set cancellation point

I'm writing a simple character device driver for Linux with blocking read() and write().

What I want to do is to set them as cancellation points, so that calling a pthread_cancel on a thread suspended on these functions will cause it to terminate.

How is it possible to set them as cancellation points?

Thanks in advance.

caf caf
Answer

If you're writing the kernel driver, all you need to do to make sure that read() and write() correctly function as cancellation points for userspace is to ensure that they return immediately if a signal is raised on the process while it's waiting in kernel space (either with a short item count or the EINTR error).

This generally means using wait_event_interruptible() followed by a check for if (signal_pending(current)).