linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [2.4] Inconsistency in poll(2)
@ 2003-07-16 10:35 Michael Mueller
  2003-07-16 12:07 ` Michael Mueller
  2003-07-18 17:13 ` James Antill
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Mueller @ 2003-07-16 10:35 UTC (permalink / raw)
  To: linux-kernel, glibc-sc

Hi readers of linux-kernel and glibc maintainers,

while hacking on a network application I found following oddity:

poll(pds,nfds,timeout) called with one of the file descriptors listed in
pds being invalid always does return nfds.

Output of appended sample code:
poll returned 2
revent[0]: 0
revent[1]: 32

According to IEEE Std 1003.1, 2003 Edition, the return value should have
been 1 in the above sample.

The kernel is 2.4.20 (debian 2.4.20-3-686). After a short look at the
code for sys_poll I am certain the problem is originated within the
kernel.

Any suggestions which actions to take?


Michael


Simple sample code demonstrating the problem:

#include <stdio.h>
#include <sys/poll.h>

struct pollfd fds[] = {
 { 0, POLLIN, 0 },
 { 110, POLLIN, 0}
};

int main(void)
{
	int r = poll(fds, sizeof fds / sizeof fds[0], -1);
	if ( r < 0 )
		perror("poll");
	else
		printf("poll returned %d\n");

	for ( r=0; r < sizeof fds / sizeof fds[0]; r++ )
		printf("revent[%d]: %hd\n", r, fds[r].revents);

	return 0;
}

-- 
Linux@TekXpress
http://www-users.rwth-aachen.de/Michael.Mueller4/tekxp/tekxp.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [2.4] Inconsistency in poll(2)
  2003-07-16 10:35 [2.4] Inconsistency in poll(2) Michael Mueller
@ 2003-07-16 12:07 ` Michael Mueller
  2003-07-18 17:13 ` James Antill
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Mueller @ 2003-07-16 12:07 UTC (permalink / raw)
  To: linux-kernel, glibc-sc

Hi,

I wrote:
> The kernel is 2.4.20 (debian 2.4.20-3-686). After a short look at the
> code for sys_poll I am certain the problem is originated within the
> kernel.

I should have been more carefully about locating the source. After
trying strace, I know the kernel is not the source of the problem:

poll([{fd=0, events=POLLIN}, {fd=110, events=POLLIN, revents=POLLNVAL}],
2, -1) = 1

sorry for bothering you. I am going to file a bug for the glibc instead
now.


Michael

-- 
Linux@TekXpress
http://www-users.rwth-aachen.de/Michael.Mueller4/tekxp/tekxp.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [2.4] Inconsistency in poll(2)
  2003-07-16 10:35 [2.4] Inconsistency in poll(2) Michael Mueller
  2003-07-16 12:07 ` Michael Mueller
@ 2003-07-18 17:13 ` James Antill
  1 sibling, 0 replies; 3+ messages in thread
From: James Antill @ 2003-07-18 17:13 UTC (permalink / raw)
  To: Michael Mueller; +Cc: linux-kernel, glibc-sc

malware@t-online.de (Michael Mueller) writes:

> Hi readers of linux-kernel and glibc maintainers,
> 
> while hacking on a network application I found following oddity:
> 
> poll(pds,nfds,timeout) called with one of the file descriptors listed in
> pds being invalid always does return nfds.

[snip .. ]

> Simple sample code demonstrating the problem:

 When writing code, always compile with at least -Wall -W
> 
> #include <stdio.h>
> #include <sys/poll.h>
> 
> struct pollfd fds[] = {
>  { 0, POLLIN, 0 },
>  { 110, POLLIN, 0}
> };
> 
> int main(void)
> {
> 	int r = poll(fds, sizeof fds / sizeof fds[0], -1);
> 	if ( r < 0 )
> 		perror("poll");
> 	else
> 		printf("poll returned %d\n");
 		printf("poll returned %d\n", r);

 Is probably what you want.

> 
> 	for ( r=0; r < sizeof fds / sizeof fds[0]; r++ )
> 		printf("revent[%d]: %hd\n", r, fds[r].revents);
> 
> 	return 0;
> }

-- 
James Antill -- james@and.org
Need an efficent and powerful string library for C?
http://www.and.org/vstr/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-07-18 16:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-16 10:35 [2.4] Inconsistency in poll(2) Michael Mueller
2003-07-16 12:07 ` Michael Mueller
2003-07-18 17:13 ` James Antill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).