From: Patrick McManus <mcmanus@ducksong.com>
To: linux kernel ml <linux-kernel@vger.kernel.org>
Subject: tee(2) and SPLICE_F_NONBLOCK and can't find eof
Date: Tue, 19 Feb 2008 10:41:32 -0500 [thread overview]
Message-ID: <1203435692.5949.84.camel@tng> (raw)
[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
completes.
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?
-Patrick
(This is the sample from the manpage which never completes.. I invoke it
as "cat txt | ./teesample out1 | wc ")
int
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) {
perror("open");
exit(EXIT_FAILURE);
}
do {
/*
* tee stdin to stdout.
*/
len = tee(STDIN_FILENO, STDOUT_FILENO,
INT_MAX, SPLICE_F_NONBLOCK);
if (len < 0) {
if (errno == EAGAIN)
continue;
perror("tee");
exit(EXIT_FAILURE);
} else
if (len == 0)
break;
/*
* 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) {
perror("splice");
break;
}
len -= slen;
}
} while (1);
close(fd);
exit(EXIT_SUCCESS);
}
reply other threads:[~2008-02-19 15:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1203435692.5949.84.camel@tng \
--to=mcmanus@ducksong.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®