Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.apps > #693
| From | Rainer Weikusat <rweikusat@mobileactivedefense.com> |
|---|---|
| Newsgroups | comp.os.linux.development.apps, comp.unix.programmer |
| Subject | Re: Linux O_NONBLOCK bug/ quirk |
| Followup-To | comp.unix.programmer |
| Date | 2014-04-16 12:42 +0100 |
| Message-ID | <877g6pv6tc.fsf@sable.mobileactivedefense.com> (permalink) |
| References | <878urvu0gx.fsf@sable.mobileactivedefense.com> <lh4vnk$bdu$1@dont-email.me> |
Cross-posted to 2 groups.
Followups directed to: comp.unix.programmer
Lusotec <nomail@nomail.not> writes:
[demonstration of Linux bug]
> a fcntl must affect a already running operations. I think this
> is very problematic.
NB: This is crossposted to comp.unix.programmer with a followup-to set
as it is (in my opinion) mostly about POSIX/ UNIX(*) implementation
quirks.
NB^2: This has been tested on Linux 3.2.9 without the recent "nonblocking fix"
applied, I'm totally innocent of this mess.
As someone named John McCue discovered, the fcntl does actually affect
the running operation, although in rather strange ways: In case a
non-blocking read which happened to be blocking is interrupted (this
shouldn't happen because it shouldn't block aka 'go to sleep in the
kernel until some external event occurs'), the kernel tries to hide that
by silently returning an EAGAIN error instead of an EINTR error. But it
doesn't keep track of which calls were blocking and which
weren't. The net effect is that a blocking call supposed to be restarted
in case it was interrupted by a signal actually aborts with EAGAIN since
glibc "doesn't expect that" (apparently a lesser problem, given that
nobody uses it ...).
Sample program:
---------------
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/socket.h>
#include <unistd.h>
static void dummy(int unused)
{
(void)unused;
}
int main(void)
{
struct sigaction sa;
int sk, rc;
pid_t pid;
sk = socket(AF_UNIX, SOCK_DGRAM, 0);
if (sk == -1) {
perror("socket");
exit(1);
}
switch (pid = fork()) {
case -1:
perror("fork");
exit(1);
case 0:
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sa.sa_handler = dummy;
sigaction(SIGALRM, &sa, NULL);
alarm(5);
rc = read(sk, &pid, sizeof(pid));
if (rc == -1 && errno == EAGAIN)
puts("Holy cow! How did this happen to me??");
_exit(0);
}
sleep(1);
rc = fcntl(sk, F_GETFL);
fcntl(sk, F_SETFL, rc | O_NONBLOCK);
wait(NULL);
return 0;
}
Back to comp.os.linux.development.apps | Previous | Next — Previous in thread | Next in thread | Find similar
Linux O_NONBLOCK bug/ quirk Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2014-03-27 15:26 +0000
Re: Linux O_NONBLOCK bug/ quirk crankypuss <crankypuss@nomail.invalid> - 2014-03-28 02:08 -0600
Re: Linux O_NONBLOCK bug/ quirk Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2014-03-28 12:45 +0000
Re: Linux O_NONBLOCK bug/ quirk crankypuss <crankypuss@nomail.invalid> - 2014-03-29 05:19 -0600
Re: Linux O_NONBLOCK bug/ quirk Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2014-03-28 20:12 +0000
Re: Linux O_NONBLOCK bug/ quirk unixb4coffee <unixb4coffee@gmail.com> - 2014-04-02 11:13 -0700
Re: Linux O_NONBLOCK bug/ quirk Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2014-04-03 16:36 +0100
Re: Linux O_NONBLOCK bug/ quirk unixb4coffee <unixb4coffee@gmail.com> - 2014-04-03 11:43 -0700
Re: Linux O_NONBLOCK bug/ quirk Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2014-04-03 21:31 +0100
Re: Linux O_NONBLOCK bug/ quirk Lusotec <nomail@nomail.not> - 2014-03-28 23:13 +0000
Re: Linux O_NONBLOCK bug/ quirk Richard Kettlewell <rjk@greenend.org.uk> - 2014-03-29 11:15 +0000
Re: Linux O_NONBLOCK bug/ quirk Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2014-03-30 19:42 +0100
Re: Linux O_NONBLOCK bug/ quirk Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2014-04-16 12:42 +0100
Re: Linux O_NONBLOCK bug/ quirk Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2014-04-16 13:36 +0100
csiph-web