Re: epoll design problems with common fork/exec patterns

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <davids@...>
Cc: Linux-Kernel@Vger. Kernel. Org <linux-kernel@...>
Date: Sunday, October 28, 2007 - 5:33 am

David Schwartz a écrit :

Events are not necessarly reported "by descriptors". epoll uses an opaque 
field provided by the user.

It's up to the user to properly chose a tag that will makes sense if the user 
app is playing dup()/close() games for example.

typedef union epoll_data
{
   void *ptr;
   int fd;
   uint32_t u32;
   uint64_t u64;
} epoll_data_t;


It's true some applications are using 'fd' field from epoll_data_t, but in 
this case they should not play dup()/close() games that could change the 
meaning of their 'epoll tags'. They would better use 'ptr/u64' for example to 
map the event to an application object. In this object they might find the 
correct handle (fd) to communicate with the kernel for a given 'file'. This 
handle could then be remapped to another handle using dup()/fcntl()/close()...



Yes, it would be nonsense that the child still tries to get events from the 
epoll set while he cannot possibly use the socket. If you use 'ptr' field to 
retrieve an object, this object probably would have no meaning in the child 
anyway, especially after an exec() syscall.

That kind of user error can also happens with select()/poll(), if you do for 
example :

FD_ZERO(&fdset);
FD_SET(fd, &fdset);
select(fd+1,&fdset, NULL, NULL, NULL);
newfd = dup(fd);
close(fd);
for (i = 0 ; i < maxfd ; i++)
if (FD_ISSET(i, &fdset))
     read(i, ...)


-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
epoll design problems with common fork/exec patterns, Marc Lehmann, (Sat Oct 27, 2:22 am)
Re: epoll design problems with common fork/exec patterns, Davide Libenzi, (Sat Oct 27, 12:59 pm)
RE: epoll design problems with common fork/exec patterns, David Schwartz, (Sun Oct 28, 12:47 am)
RE: epoll design problems with common fork/exec patterns, Davide Libenzi, (Sun Oct 28, 2:48 pm)
Re: epoll design problems with common fork/exec patterns, Eric Dumazet, (Sun Oct 28, 5:33 am)
RE: epoll design problems with common fork/exec patterns, David Schwartz, (Sun Oct 28, 5:04 pm)
RE: epoll design problems with common fork/exec patterns, Davide Libenzi, (Mon Oct 29, 2:55 pm)
Re: epoll design problems with common fork/exec patterns, Michael Kerrisk, (Tue Feb 26, 11:13 am)
Re: epoll design problems with common fork/exec patterns, Davide Libenzi, (Tue Feb 26, 2:51 pm)
Re: epoll design problems with common fork/exec patterns, Davide Libenzi, (Wed Feb 27, 3:35 pm)
Re: epoll design problems with common fork/exec patterns, Michael Kerrisk, (Thu Feb 28, 9:12 am)
Re: epoll design problems with common fork/exec patterns, Davide Libenzi, (Thu Feb 28, 3:23 pm)
Re: epoll design problems with common fork/exec patterns, Michael Kerrisk, (Fri Feb 29, 11:46 am)
Re: epoll design problems with common fork/exec patterns, Davide Libenzi, (Fri Feb 29, 3:19 pm)
Re: epoll design problems with common fork/exec patterns, Michael Kerrisk, (Fri Feb 29, 3:54 pm)
Re: epoll design problems with common fork/exec patterns, Michael Kerrisk, (Thu Feb 28, 9:23 am)
Re: epoll design problems with common fork/exec patterns, Davide Libenzi, (Thu Feb 28, 3:34 pm)
Re: epoll design problems with common fork/exec patterns, Willy Tarreau, (Sat Oct 27, 1:38 pm)
Re: epoll design problems with common fork/exec patterns, Davide Libenzi, (Sat Oct 27, 2:01 pm)