2

The situation is that I have a shell and an interactive X-based application that receives commands over a socket dup2'd over stdin. Code follows

// shell init
int sockfds[2] = { -1, -1 };
socketpair(AF_UNIX, SOCK_STREAM, 0, sockfds);

int epfd = epoll_create1(EPOLL_CLOEXEC);
struct epoll_event events[1];

events[0].events = EPOLLIN;
events[0].data.fd = sockfds[0];
epoll_ctl(epfd, EPOLL_CTL_ADD, &events[0]);

// shell child
dup2(sockfds[1], STDIN_FILENO);
dup2(sockfds[1], STDOUT_FILENO);
dup2(sockfds[1], STDERR_FILENO);

close(sockfds[0]);
close(sockfds[1]);
// shell parent
// continues loop and blocks on readline(3) and parses the returned string; send a message unconditionally
char msg[] = "hello, world\n";
write(sockfds[0], msg, sizeof msg);


// X application
int epollfd = epoll_create1(0);
struct epoll_event stdin_event, ev;

stdin_event.events = EPOLLIN;
stdin_event.data.fd = STDIN_FILENO;
epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &stdin_event);

while(is_running) {
    int is_command_pending = epoll_wait(epollfd, &ev, 1, 0);
    if(is_command_pending > 0) {
        is_running = 0;
    }
}

While I send a message in the shell process, no message shows up in the child over epoll. Did I run into a corner case wrt epoll?

Jesse Lactin
  • 191
  • 1
  • 10

0 Answers0