tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: "Pitt, David" <pitt () rlmsystems ! com ! au>
To: tru64-unix-managers
Subject: Why do I get EINTR (Interrupted System call) when using sigaction
Date: Fri, 27 Jul 2001 03:27:22 +0000	[thread overview]
Message-ID: <102653652422093.tru64-unix-managers.marc@archive.invalid> (raw)

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

                 reply	other threads:[~2001-07-27  3:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox