Fixing the errno race

The fix for the previous race is actually quite simple.

Whenever you have a signal handler with code within it that could possibly cause the errno value to change, save errno upon function entry and restore it just before returning from the handler.

Gain access to the errno variable simply by including its header file. Here is a quick example code snippet of a signal handler that does this:

<...>
include <errno.h>
<...>

static void handle_sigusr(int signum)
{
int myerrno = errno;
<... do the handling ...>
<... syscalls, etc ...>
errno = myerror;
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset