Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Rainer Weikusat Newsgroups: comp.os.linux.development.apps Subject: Linux O_NONBLOCK bug/ quirk Date: Thu, 27 Mar 2014 15:26:22 +0000 Lines: 38 Message-ID: <878urvu0gx.fsf@sable.mobileactivedefense.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: individual.net 7joNofU8LzNdfnPw5t7elwes6Y9jZtSGBNMqKy9yBfY8kA+Og= Cancel-Lock: sha1:q0TrmgERHyoeQ3AqkMU0hRv2UoI= sha1:HziHYD+KmOKAswp8nApLcm30Gfg= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Xref: csiph.com comp.os.linux.development.apps:665 As part of one of the usual 'pleasant exchanges' with the people whose ability to make a living depends on controlling access to the Linux code base, it came to light that a receive operation on a socket in non-blocking mode can actually be blocked forever on Linux, example code: --------- #include #include #include #include int main(void) { struct sockaddr_un sun; int fd; fd = socket(AF_UNIX, SOCK_DGRAM, 0); sun.sun_family = AF_UNIX; strncpy(sun.sun_path, "/tmp/bla", sizeof(sun.sun_path)); bind(fd, (struct sockaddr *)&sun, sizeof(sun)); if (fork() == 0) read(fd, &fd, sizeof(fd)); sleep(1); fcntl(fd, F_SETFL, O_NONBLOCK); read(fd, &fd, sizeof(fd)); return 0; } -------- Killing the forked process results in the other aborting the read call with EAGAIN, as can be determined with strace. I don't think this is of much practical relevance but it is something worth knowing about.