[haiku-development] Re: poll(2) with nfds=0

  • From: "François Revol" <revol@xxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Fri, 20 Mar 2009 18:30:28 +0100 CET

> #include <poll.h>
> #include <stdio.h>
>
> int main()
> {
>         int i = poll(NULL, 0, 2000);
>         fprintf(stderr, "%d\n", i);
>         return 0;
> }
>
> Haiku: immiedately prints -1
> Linux: sleeps for 2 seconds and prints 0
>
> This program passes fds = NULL but at the same time, nfds = 0; so
> there isn't any actual null pointer dereference. The docs
> http://www.opengroup.org/onlinepubs/007908799/xsh/poll.html don't
> seem
> to cover this issue. Unless specifically configured not to, glib will
> use this construct and expect it to follow the second behaviour.
> Should glib be always configured to avoid this construct or should
> the
> Haiku's implementation allow it?

While it's a bad idea to use expected undocumented/nonstandardized
behaviour, it's probably ok to change our poll() to do the same as
Linux here.
What does BSD do in this case ?

François.

Other related posts: