I need to interrupt a syscall (recvfrom in this case) after a timeout. For this I'm using alarm(), however the resulting SIGALRM kills my process instead of only interrupting the syscall.
I've tried calling signal(SIGALRM, SIG_IGN) to handle the SIGALRM, but this causes the syscall to not be interrupted at all! The only way I've got this to work is by creating a custom empty handler (signal(SIGALRM, alrm_handler)) - the handler does nothing, but it still results in the recvfrom being interrupted without the process being killed.
I understand that the default signal handler (SIG_DFL) will kill the process, but I expected SIG_IGN to ignore the signal but still interrupt the syscall. I straced a test program with SIG_IGN and with a custom empty handler, and they both end up calling rt_sigaction(SIGALRM...) without SA_RESTART. As far as I know, if SA_RESTART was set then the syscall would be restarted automatically, but this is happening with SIG_IGN anyway!
Is there any cleaner way to interrupt a syscall with SIGALRM without needing a custom signal handler?