From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <102653652422093.tru64-unix-managers.marc@archive.invalid> From: "Pitt, David" Date: Fri, 27 Jul 2001 03:27:22 +0000 To: tru64-unix-managers Subject: Why do I get EINTR (Interrupted System call) when using sigaction X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=102653652422093 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