From: jnc@mercury.lcs.mit.edu (Noel Chiappa)
Subject: [TUHS] Excise process from a pipe
Date: Fri, 18 Jul 2014 11:33:45 -0400 (EDT) [thread overview]
Message-ID: <20140718153345.DC5EA18C0B4@mercury.lcs.mit.edu> (raw)
>> the downstream process is in the middle of a read call (waiting for
>> more data to be put in the pipe), and it has already computed a pointer
>> to the pipe's inode, and it's looping waiting for that inode to have
>> data.
> I think it would be necessary to make non-trivial adjustments to the
> pipe and file reading/writing code to make this work; either i) some
> sort of flag bit to say 'you've been spliced, take appropriate action'
> which the pipe code would have to check on being woken up, and then
> back out to let the main file reading/writing code take another crack
> at it
> ...
> I'm not sure I want to do the work to make this actually work - it's
> not clear if anyone is really that interested? And it's not something
> that I'm interested in having for my own use.
So I decided that it was silly to put all that work into this, and not get it
to work. I did 'cut a corner', by not handling the case where it's the first
or last process which is bailing (which requires a file-pipe splice, not a
pipe-pipe; the former is more complex); i.e. I was just doing a 'working proof
of concept', not a full implementation.
I used the 'flag bit on the inode' approach; the pipe-pipe case could be dealt
with entirely inside pipe.c/readp(). Here's the added code in readp() (at the
loop start):
if ((ip->i_flag & ISPLICE) != 0) {
closei(ip, 0);
ip = rp->f_inode;
}
It worked first time!
In more detail, I had written a 'splicetest' program that simply passed input
to its output, looking for a line with a single keyword ("stop"); at that
point, it did a splice() call and exited. When I did "cat input | splicetest
| cat > output", with appropriate test data in "input", all of the test data
(less the "stop" line) appeared in the output file!
For the first time (AFAIK) a process succesfully departed a pipeline, which
continued to operate! So it is do-able. (If anyone has any interest in the
code, let me know.)
Noel
next reply other threads:[~2014-07-18 15:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-18 15:33 Noel Chiappa [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-07-17 15:42 Noel Chiappa
2014-07-16 21:31 Noel Chiappa
2014-07-14 15:12 Noel Chiappa
2014-07-14 14:13 Doug McIlroy
2014-07-10 16:12 Noel Chiappa
2014-07-10 16:06 Noel Chiappa
2014-07-10 16:04 ` Larry McVoy
2014-07-10 15:10 Noel Chiappa
2014-07-10 15:11 ` Larry McVoy
2014-07-10 2:49 [TUHS] Subject:unpipeIt'seasy for a process to insert a new process intoapipelineeither upstream or down unpipe Doug McIlroy
2014-07-10 4:52 ` [TUHS] Excise process from a pipe Warren Toomey
2014-07-10 5:00 ` Dave Horsfall
2014-07-10 5:06 ` Christopher Vance
2014-07-10 8:43 ` Warren Toomey
2014-07-10 12:03 ` Doug McIlroy
2014-07-10 12:04 ` Doug McIlroy
2014-07-10 14:45 ` Larry McVoy
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=20140718153345.DC5EA18C0B4@mercury.lcs.mit.edu \
--to=jnc@mercury.lcs.mit.edu \
/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;
as well as URLs for NNTP newsgroup(s).