git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [msysGit] Re: [PATCH] compat: Add another rudimentary poll() emulation

From
ADAlbert Dvornik <dvornik@gmail.com>
Date
May 27, 2010, 14:05 UTC
Message-ID
<AANLkTimyFxEYjQLefWvExBarhZAwoXNLDUum2lVj4Q3B@mail.gmail.com>
In-Reply-To
<AANLkTikezlVaX8ARkRw8kEk9wL9RL_5I6X3vK83nzFUl@mail.gmail.com>

On Thu, May 27, 2010 at 9:06 AM, Erik Faye-Lund <kusmabite@googlemail.com> wrote: [...]

Show 6 quoted lines
> But perhaps you should include a check along the lines of this:
>
> if (nfds > FD_SETSIZE)
>        return errno = EINVAL, error("poll: nfds must be below %d", FD_SETSIZE);
>
> Just so we can know when the code fails :)

If you're checking against FD_SETSIZE (which is IMO a good idea), you should consider that (a) on the one system I'm aware of where fd_set doesn't use a bitmap (Windows), FD_SETSIZE is a limit on the number of descriptors added to the set, but (b) on systems where fd_set uses a bitmap (i.e. Linux, perhaps all UNIXes, etc), FD_SETSIZE is a limit on *each descriptor value*. This is also what POSIX says.

So on the latter systems, we want something like this before each FD_SET:
if (ufds[i].fd >= FD_SETSIZE) {
    errno = EINVAL;
    return error("poll: each fd must be below %d", FD_SETSIZE);
}

(The reason to have it in the loop, rather than just check maxfd afterwards, is that FD_SET with an argument that's too big can trash the stack.)

Of course, on Windows this would impose a limitation that all descriptors be < 64, which is probably crazy. Which means that you'd have to actually distinguish the two types. Sigh.

--bert
Previous: Albert DvornikNext: Jonathan Nieder
Message 26 of 39 in “Interix support”
  1. 0/3 Interix supportJonathan Callen, May 27, 2010
  2. 1/3 Support building on systems without poll(2)Jonathan Callen, May 27, 2010
  3. Sverre RabbelierMay 27, 2010
  4. Jeff KingMay 27, 2010
  5. Michael J GruberMay 27, 2010
  6. Jonathan CallenMay 27, 2010
  7. compat: Add another rudimentary poll() emulationJonathan Nieder, May 27, 2010
  8. Erik Faye-LundMay 27, 2010
  9. Marko KreenMay 27, 2010
  10. Erik Faye-LundMay 27, 2010
  11. Marko KreenMay 27, 2010
  12. Erik Faye-LundMay 27, 2010
  13. Albert DvornikMay 27, 2010
  14. Paolo BonziniMay 30, 2010
  15. Erik Faye-LundMay 27, 2010
  16. Marko KreenMay 27, 2010
  17. Erik Faye-LundMay 27, 2010
  18. Marko KreenMay 27, 2010
  19. Erik Faye-LundMay 27, 2010
  20. Marko KreenMay 27, 2010
  21. Erik Faye-LundMay 27, 2010
  22. Marko KreenMay 27, 2010
  23. Erik Faye-LundMay 27, 2010
  24. Peter KjellerstedtMay 27, 2010
  25. Albert DvornikMay 27, 2010
  26. Albert DvornikMay 27, 2010
  27. compat: Add another rudimentary poll() emulationJonathan Nieder, May 30, 2010
  28. Johannes SixtMay 30, 2010
  29. Jonathan NiederMay 30, 2010
  30. Joshua JuranMay 30, 2010
  31. Mac OS 9 (Lamp) portJonathan Nieder, May 31, 2010
  32. Joshua JuranMay 31, 2010
  33. Jonathan NiederMay 31, 2010
  34. Albert DvornikMay 31, 2010
  35. Jonathan NiederMay 31, 2010
  36. Albert DvornikMay 31, 2010
  37. 2/3 Support building without inttypes.hJonathan Callen, May 27, 2010
  38. 3/3 Add Interix supportJonathan Callen, May 27, 2010
  39. Jakub NarebskiMay 28, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.