[systemd-devel] Some thoughts about loop_read/loop_write in util.c

cee1 fykcee1 at gmail.com
Wed Sep 11 06:50:55 PDT 2013


Hi all,

loop_read/loop_write:
http://cgit.freedesktop.org/systemd/systemd/tree/src/shared/util.c#n2179

In a scenario of pipes, loop_read on read side, if the write side is
closed, loop_read will return 0 if do_poll is false(let's assume no
data available to read). When do_poll is true, it will return:
1) 0, if write side is closed while loop_read is just doing a read
2) or -EIO when poll returns pollfd.revent with POLLHUP flag set

The behavior is not very consistent.
IMHO, it's preferred loop_read follows read behavior as much as
possible -- returns 0 to indicate end of a file here, e.g. We can try
to read 0 bytes when pollfd.revents != POLLIN.

The same with loop_write.


-- 
Regards,

- cee1


More information about the systemd-devel mailing list