| 22 Dec 2025 |
Randy Eckenrode | I wonder what they mean by “broken”. | 15:35:04 |
Randy Eckenrode | Sometimes “broken” means “conforms to POSIX but doesn’t do what GNU does”. | 15:35:48 |
Ihar Hrachyshka | /* The poll() emulation on OS/X doesn't handle fds=NULL, nfds=0,
* so we prefer our own poll emulation.
| 15:35:50 |
Ihar Hrachyshka | the MR that mentions tap networking broken? https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2571 | 15:39:46 |
Ihar Hrachyshka | there's a "check" they use to detect a "broken" poll here: https://gitlab.gnome.org/GNOME/glib/-/commit/caecf2dda082e9c46c4157cdc10763deb8dcfc27
but afaiu it is no longer needed and just forced on darwin. wonder if the check would pass now... | 15:40:56 |
Ihar Hrachyshka | * there's a "check" they use to detect a "broken" poll here: https://gitlab.gnome.org/GNOME/glib/-/commit/caecf2dda082e9c46c4157cdc10763deb8dcfc27
but afaiu it is no longer used and just forced on darwin. wonder if the check would pass now... | 15:41:04 |
Randy Eckenrode | According to POSIX, fds is an array. My understanding is that NULL is not a valid value for an array in C. | 15:41:55 |
Ihar Hrachyshka | the check compiled with xcode clang returns 1 | 15:42:22 |
Randy Eckenrode | https://pubs.opengroup.org/onlinepubs/9799919799/functions/poll.html | 15:42:38 |
Randy Eckenrode | ppoll is apparently part of POSIX now. No idea if or when Apple will add it. | 15:43:07 |
Ihar Hrachyshka | they could at least maybe conditionalize it. like if it's null and the user needs some non-standard behavior, go through select. otherwise...
I think main loop for qemu doesn't pass nulls there. | 15:43:45 |
Ihar Hrachyshka | it's 2024 posix so rather new | 15:43:59 |
Randy Eckenrode | Yeah. Apple is adding newer stuff, but they still only go for UNIX03 when they certify. | 15:44:53 |
Randy Eckenrode | So no guarantee, particularly if they have alternative APIs already. | 15:45:24 |
Randy Eckenrode | Does that means it works now? | 15:46:11 |
Ihar Hrachyshka | exit(1); /* Does not work for devices -- fail */ | 15:46:34 |
Randy Eckenrode | That code is almost twenty years old. It wouldn’t be the first time Glib makes an assumption that doesn’t apply on modern Darwin. | 15:46:48 |
Randy Eckenrode | What is the expected semantics when the user provides NULL fds and nfds 0? | 15:47:44 |
Randy Eckenrode | * What are the expected semantics when the user provides NULL fds and nfds 0? | 15:47:57 |
Randy Eckenrode | Is it equivalent to passing an empty array? | 15:48:53 |
Randy Eckenrode | macOS supports pselect but not ppoll? | 15:51:13 |
Randy Eckenrode | Let’s look at the implementation. The signature takes a pointer, so NULL should be valid. | 15:52:54 |
Ihar Hrachyshka | one could probably implement g_poll conditioning to default to poll but fall back to select if a) any device fds passed or b) fds is null. then for most calls we would use poll. | 15:53:06 |
Ihar Hrachyshka | that's on nixos
(ins)[nix-shell:/tmp]$ ./a.out
poll() returned: 0
(ins)[nix-shell:/tmp]$ cat test.c
#include <stdio.h>
#include <poll.h>
#include <errno.h>
#include <string.h>
int main() {
int result = poll(NULL, 0, 1000);
printf("poll() returned: %d\n", result);
if (result == -1) {
printf("Error: %s\n", strerror(errno));
}
return 0;
}
(ins)[nix-shell:/tmp]$ clang ./test.c
(ins)[nix-shell:/tmp]$ ./a.out
poll() returned: 0
| 15:53:15 |
Ihar Hrachyshka | actuall it returns the same zero on darwin, not sure if there's more than just that they are looking for... | 15:54:09 |
Ihar Hrachyshka | maybe the original reasoning documented in the comment is no longer applicable, but tap device polling is still an issue. | 15:55:30 |
Randy Eckenrode | Maybe it only works on newer macOS? | 15:57:29 |
hexa | it's a bit surprising that nix-darwin does not have a system.autoUpgrade like option 🤔 | 15:58:04 |
hexa | what I need is to keep the machines in sync with a flake ref | 15:58:43 |
Randy Eckenrode | The test is whether it supports devices. According to POSIX:
The poll() and ppoll() functions shall support regular files, terminal and pseudo-terminal devices, FIFOs, pipes, and sockets. The behavior of poll() and ppoll() on elements of fds that refer to other types of file is unspecified.
| 16:00:23 |