Re: OS X poll breakage (Was: Please help test recent changes)

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

 



On Tue, 11 Jan 2022, Damien Miller wrote:

> Wow, it looks like Darwin's poll(2) is completely broken for character-
> special devices (at least). E.g. the attached program spins shows similar
> behaviour when run on /dev/null - it spins, returning revents=POLLNVAL.

oops, this was the test program I was using.

Compare "./demo -" and "./demo /dev/null"

#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <poll.h>
#include <err.h>

int
main(int argc, char **argv)
{
	struct pollfd p;
	struct stat s;
	int r;
	char c;

	setlinebuf(stdout);
	p.fd = 0;
	if (argc > 1 && strcmp(argv[1], "-") != 0) {
		if ((p.fd = open(argv[1], O_RDONLY)) == -1)
			err(1, "open %s", argv[1]);
	}
	if (fstat(p.fd, &s) != 0)
		err(1, "stat");
	printf("fd %d mode 0%o\n", p.fd, s.st_mode);
	for (;;) {
		p.events = POLLIN;
		r = poll(&p, 1, -1);
		if (r == -1)
			err(1, "poll");
		printf("poll %d rev 0x%02x\n", r, p.revents);
		if ((p.revents & (POLLIN|POLLHUP)) == 0)
			continue;
		r = read(p.fd, &c, 1);
		if (r == -1)
			err(1, "read");
		if (r == 0)
			break;
	}
	return 0;
}


_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@xxxxxxxxxxx
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev



[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux