[Libevent-users] read stdin pipe

Niels Provos provos at citi.umich.edu
Sat Sep 8 16:49:22 EDT 2007


When the read returns 0, it means that you have EOF on the file
descriptor.   You need to delete the read event at that point.   It's
not entirely surprising that stdin goes away when you daemonize a
program.

Niels.

On 9/8/07, tom <pomarancde23 at post.cz> wrote:
> Hi,
>
>  I'm writing a daemon using libevent. The daemon is started like this:
> "program_A | daemon"
> It gets a pipe on standard input. The program_A is writing to this pipe and the daemon must process the input gathered from the pipe. I must be doing something wrong as my callback function set in event_set is called nonstop. A trace had shown that epoll_wait() in epoll_dispatch() is not waiting at all and afterwards the read() in the callback returns always 0. When I start the daemon like this "./daemon" and write on the console, it all works fine as it should.
>
> Here is my daemon skeleton:
>
> struct event ev;
>
> void read_stdin (int fd, short flags, void *data)
> {
>  ..
>  ret = read(fd, buf, BUFSIZE);
>  ..
> }
>
> main ()
> {
>  base = event_init();
>  event_set(&ev, 0, EV_READ | EV_PERSIST, read_stdin, NULL);
>  event_add(&ev, NULL);
>  event_base_loop(base, 0);
> }
>
>
> Thanks for any advice in advanced,
> Tom
> _______________________________________________
> Libevent-users mailing list
> Libevent-users at monkey.org
> http://monkey.org/mailman/listinfo/libevent-users
>
>


More information about the Libevent-users mailing list