I need to investigate/test the behavior of some code on Linux under conditions where close might be interrupted by signal handlers (either with or without SA_RESTART). What is the most convenient setup to make the close syscall sleep for a measurable window of time during which I could try to hit the process with a signal? Some ideas:
- Intentionally slow/non-responsive NFS mount
- Custom FUSE driver
But since these are a bit of a pain to setup, I’m wondering if there’s anything more off-the-shelf I could use that could give the desired behavior.
If nobody else has a better idea…
You could implement your own character device driver. Start with the template from Chapter 3 in Linux Device Drivers (3rd edition), and tweak it to do nothing except block for a while on close(). (You can use
msleepormsleep_interruptiblefrom Chapter 7 to do the blocking.)Actually, if nobody else suggests something else, I can probably whip this up pretty quickly by adapting some existing code I have. How soon do you need it?
[edit]
OK, try this…
Makefile:
closer.c:
Load the module using “insmod closer.o”. If you have a reasonably modern/complete Linux environment, udev will wake up and generate /dev/closer automatically. If not, you can create the device node yourself:
(That is, /sys/class/misc/closer/dev indicates the major:minor to use.)
Reads and writes work like /dev/null; i.e., EOF on any read, success on any write.
I have verified that “cat < /dev/closer” blocks in
close()for 10 seconds. I have not created a test to catchSIGINT(or whatever) and verify that it actually results inEINTR.Built against a 2.6.32 kernel. Let me know how it works for you.