LKML Archive on
help / color / mirror / Atom feed
* tee(2) and SPLICE_F_NONBLOCK and can't find eof
@ 2008-02-19 15:41 Patrick McManus
  0 siblings, 0 replies; only message in thread
From: Patrick McManus @ 2008-02-19 15:41 UTC (permalink / raw)
  To: linux kernel ml

[I initially sent this query inappropriately to an individual instead of
the list. My apologies.]

re: tee().. I was just playing around with the simple sample on the
manpage (included below) - it uses SPLICE_F_NONBLOCK as a flag. 

on 2.6.22 X86_64 (ubuntu 7.10) when I run the sample. the tee() system
call returns the right number of bytes from the input - sometimes as the
sum of multiple calls. When the input is exhauted tee() starts returning
(-1,EAGAIN) forever.. it never returns 0 and the program never

without a 0, how is EOF indicated?

do_tee() contains:
       if (!ret && (flags & SPLICE_F_NONBLOCK))
               ret = -EAGAIN;

so it's pretty clear where it comes from.. but finding EOF eludes me ;)
remove the NONBLOCK flag and 0 happens just fine.

NONBLOCK seems gratuitous in the sample, but it would make sense in some
code I am contemplating.. 

Any suggestions?


(This is the sample from the manpage which never completes.. I invoke it
as "cat txt | ./teesample out1 | wc ")

main(int argc, char *argv[])
    int fd;
    int len, slen;

    assert(argc == 2);

    fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
    if (fd == -1) {

    do {
         * tee stdin to stdout.
        len = tee(STDIN_FILENO, STDOUT_FILENO,
                  INT_MAX, SPLICE_F_NONBLOCK);

        if (len < 0) {
            if (errno == EAGAIN)
        } else
            if (len == 0)

         * Consume stdin by splicing it to a file.
        while (len > 0) {
            slen = splice(STDIN_FILENO, NULL, fd, NULL,
                          len, SPLICE_F_MOVE);
            if (slen < 0) {
            len -= slen;
    } while (1);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-02-19 15:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-19 15:41 tee(2) and SPLICE_F_NONBLOCK and can't find eof Patrick McManus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).