* Why do I get EINTR (Interrupted System call) when using sigaction
@ 2001-07-27 3:27 Pitt, David
0 siblings, 0 replies; only message in thread
From: Pitt, David @ 2001-07-27 3:27 UTC (permalink / raw)
To: tru64-unix-managers
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@rlmsystems.com.au
+61-3-9259 3775
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2001-07-27 3:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-07-27 3:27 Why do I get EINTR (Interrupted System call) when using sigaction Pitt, David
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox