Can someone help me with this?
I have a problem using sigaction with SA_RESTART. Consider the following
program fragments:
void sighandler(int sig, siginfo_t *sip, void *extra)
{
fprintf(stderr, "Caught signal %d\n", sig);
}
int
main()
{
...
struct sigaction sa = { 0 };
...
sa.sa_sigaction = sighandler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sigaction(SIGINT, &sa, 0);
...
while ((nr = read(if, buf, sizeof(buf))) > 0)
{
nw = write(of, buf, nr);
if (nw == -1)
{
perror(ofile);
exit(1);
}
if (nw < nr)
fprintf(stderr, "short write, ignoring\n");
}
if (nr == -1)
{
perror(ifile);
exit(1);
}
...
}
When the target of the write is (e.g.) an NFS file, sending SIGINT to the
process during a write(2) operation
causes a short write (expected, the program can deal with that). However the
next write(2) can fail with
errno set to EINTR. The man page for sigaction(2) implies that you cannot
get EINTR if you are using
SA_RESTART, but it seems that I have to handle EINTR myself via:
do {
nw = write(...);
} while (nw == -1 && errno == EINTR);
If so, SA_RESTART is useless. What is going on?
David Pitt
RLM Systems
d.pitt_at_rlmsystems.com.au
+61-3-9259 3775
Received on Fri Jul 27 2001 - 03:27:12 NZST