poll() returns -1 but errno not set!
From: Raj Kotaru (raj_kotaru_at_hotmail.com)
Date: 10/29/04
- Previous message: jpd: "Re: Clone a Windows XP with dd"
- Next in thread: Casper H.S. ***: "Re: poll() returns -1 but errno not set!"
- Reply: Casper H.S. ***: "Re: poll() returns -1 but errno not set!"
- Reply: Roger Faulkner: "Re: poll() returns -1 but errno not set!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 Oct 2004 15:20:55 -0700
Hello all,
I am running a program compiled on a Sun Solaris machine with SunOS
5.7 using the GNU egcs1.1.2 g++ compiler. The program opens a socket
and uses the poll() system call to see if data is available for
reading.
I specify INFTIM as the timeout parameter to poll() to cause it to
hang until data is available. I am also guarding against poll() being
interrupted by a signal by checking errno against EINTR and re-issuing
the poll() call if a signal interrupts it.
If I send an interrupt to the program, I find that poll returns -1 but
errno is not set. A print statement shows that errno remains 0 after
the poll() returns.
truss output shows that within poll() errno is being temporarily set
to ERESTART, but when poll() returns errno is being reset to 0.
According to the Solaris man page on poll(), errno will be set to a
non-zero value any time poll() returns -1. But this is not happening.
The really strange part is that even though errno remains set to 0, a
call to perror() results in "Interrupted system call", implying that
errno must be EINTR. Has anyone encountered this bug? Is there a
patch fix for it?
Thanks
Raj
See code snippet below:
static char framebuf [MAX_FRAME_SIZE];
struct pollfd fds[1];
char *frameptr = framebuf;
int bytes_read = 0;
int status = 0;
int frame_error_flag = 0;
fds[0].fd = _sock;
fds[0].events = POLLIN | POLLHUP | POLLPRI | POLLRDBAND;
for (;;)
{
/*
* use poll () to sleep until there's something to read or
hangup
*/
fds[0].revents = 0;
while (((status = poll (fds, 1, INFTIM)) < 0) && (errno ==
EINTR))
{
cout << "******* Inside while **********" << endl;
cout << "status = " << status << endl;
cout << "errno = " << errno << endl;
cout << "fds[0].fd = " << fds[0].fd << endl;
cout << "fds[0].events = " << fds[0].events << endl;
cout << "fds[0].revents = " << fds[0].revents << endl;
}
cout << "@@@@@@@@@ Outside while @@@@@@@@@@" << endl;
cout << "status = " << status << endl;
cout << "errno = " << errno << endl;
cout << "fds[0].fd = " << fds[0].fd << endl;
cout << "fds[0].events = " << fds[0].events << endl;
cout << "fds[0].revents = " << fds[0].revents << endl;
if (status < 0)
{
perror ("poll()");
terminate (-17);
}
See program output below:
^C@@@@@@@@@ Outside while @@@@@@@@@@
status = -1
errno = 0
fds[0].fd = 6
fds[0].events = 147
fds[0].revents = 0
poll(): Interrupted system call
See truss output below:
door_return(0x00000000, 0, 0x00000000, 0) (sleeping...)
lwp_sema_wait(0xFF24DF08) (sleeping...)
signotifywait() = 2
lwp_sigredirect(6, SIGINT) = 0
Received signal #2, SIGINT, in poll() [caught]
poll(0xFF0879B8, 1, -1) Err#91 ERESTART
sysconfig(_CONFIG_SIGRT_MIN) = 38
sigprocmask(SIG_SETMASK, 0xFF24D520, 0x00000000) = 0
sigaction(SIGINT, 0xFF087280, 0xFF087420) = 0
sigaction(SIGINT, 0xFF087280, 0xFF087420) = 0
sysconfig(_CONFIG_SIGRT_MIN) = 38
setcontext(0xFF087380)
write(1, " @ @ @ @ @ @ @ @ @ O u".., 35) = 35
write(1, " s t a t u s = - 1\n", 12) = 12
write(1, " e r r n o = 0\n", 10) = 10
write(1, " f d s [ 0 ] . f d = ".., 14) = 14
write(1, " f d s [ 0 ] . e v e n t".., 20) = 20
write(1, " f d s [ 0 ] . r e v e n".., 19) = 19
write(2, " p o l l ( )", 6) = 6
write(2, " : ", 2) = 2
write(2, " I n t e r r u p t e d ".., 23) = 23
- Previous message: jpd: "Re: Clone a Windows XP with dd"
- Next in thread: Casper H.S. ***: "Re: poll() returns -1 but errno not set!"
- Reply: Casper H.S. ***: "Re: poll() returns -1 but errno not set!"
- Reply: Roger Faulkner: "Re: poll() returns -1 but errno not set!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]