H
Hallvard B Furuseth
Signal handlers may call some OS functions - but these commonly can set
errno. As far as the rest of the program is concerned, errno can thus
be set to a garbage value at any time except when signals are blocked.
What's the best way to deal with this? Should the signal handler just
do
void handler(int sig) {
save_errno = errno; ... errno = save_errno;
}
or are reads safer than writes (even of the same value) so they
should do
... if (errno != save_errno) errno = save_errno;
Or can even a read scramble a an access in the the main program,
so the safest route is "your program should work even if errno
gets set to garbage once in a while"?
errno. As far as the rest of the program is concerned, errno can thus
be set to a garbage value at any time except when signals are blocked.
What's the best way to deal with this? Should the signal handler just
do
void handler(int sig) {
save_errno = errno; ... errno = save_errno;
}
or are reads safer than writes (even of the same value) so they
should do
... if (errno != save_errno) errno = save_errno;
Or can even a read scramble a an access in the the main program,
so the safest route is "your program should work even if errno
gets set to garbage once in a while"?