Re: epoll gives broken results when interrupted with a signal

From: Ben Mansell
Date: Mon Nov 03 2003 - 06:08:20 EST

On Thu, 30 Oct 2003, Davide Libenzi wrote:

> Could you try to poison the event buffer before an epoll_wait() to see how
> many bytes are effectively written by the function?
> memset(events, 'e', num * sizeof(epoll_event));

aha! This is interesting. When epoll seems to go wrong, the of the second event is unwritten, but the .events field
is zeroed. Sometimes though, the final call to epoll_wait() returns just
one event instead of the two, and in that case, the high 32 bits of the
first are unwritten. The lower 32 bits contain the
right data, and as the code treats this as a (int) FD, the top 32 bits
are discarded anyway.

Drat! I've just looked back at the kernel headers and noticed the
following, prior to the epoll_event definition:

* On x86-64 make the 64bit structure have the same alignment as the
* 32bit structure. This makes 32bit emulation easier.
#ifdef __x86_64__
#define EPOLL_PACKED __attribute__((packed))

struct epoll_event {
__u32 events;
__u64 data;

Now, my code can't pull in the kernel headers so it has its own
epoll_event definition, which is missing the packed attribute. D'oh!
Guess what, everything works properly when I add it in. Looks like this
bug has been of my own making all along...

Sorry for taking up your time!


Ben Mansell, <ben@xxxxxxxx> Zeus Technology Ltd
Download the world's fastest webserver! Universally Serving the Net
T:+44(0)1223 525000 F:+44(0)1223 525100
Zeus House, Cowley Road, Cambridge, CB4 0ZT, ENGLAND
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at