From: "rob pike" <rob@plan9.bell-labs.com>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] pipefile
Date: Sun, 30 Jul 2000 19:17:32 -0400 [thread overview]
Message-ID: <200007302317.TAA01751@cse.psu.edu> (raw)
Here's a version that doesn't implicitly assume /dev/cons.
I dropped the -b option because it was too hard to make work.
It's a lot shorter as a result; perhaps it could even be a shell
script.
-rob
#include <u.h>
#include <libc.h>
#define TEMP "/n/temp"
void
usage(void)
{
fprint(2, "usage: pipefile [-r command] [-w command] file\n");
exits("usage");
}
void
connect(char *cmd, int fd0, int fd1)
{
switch(rfork(RFPROC|RFFDG|RFREND|RFNOWAIT)){
case -1:
sysfatal("fork %s: %r", cmd);
break;
default:
return;
case 0:
if(fd0 != 0)
dup(fd0, 0);
if(fd1 != 1)
dup(fd1, 1);
execl("/bin/rc", "rc", "-c", cmd, nil);
sysfatal("exec %s: %r", cmd);
break;
}
}
void
main(int argc, char *argv[])
{
char *file;
char *rcmd, *wcmd;
int fd0, fd1, ifd0, ifd1;
rcmd = wcmd = nil;
ARGBEGIN{
case 'r':
rcmd = EARGF(usage());
break;
case 'w':
wcmd = EARGF(usage());
break;
default:
usage();
}ARGEND
if(argc!=1 || (rcmd==nil && wcmd==nil))
usage();
if(rcmd == nil)
rcmd = "/bin/cat";
if(wcmd == nil)
wcmd = "/bin/cat";
file = argv[0];
ifd0 = open(file, OREAD);
if(ifd0 < 0)
sysfatal("open %s: %r", file);
ifd1 = open(file, OWRITE);
if(ifd1 < 0)
sysfatal("open %s: %r", file);
if(bind("#|", TEMP, MREPL) < 0)
sysfatal("bind pipe %s: %r", TEMP);
if(bind(TEMP "/data", file, MREPL) < 0)
sysfatal("bind %s %s: %r", TEMP "/data", file);
fd0 = open(TEMP "/data1", OREAD);
if(fd0 < 0)
sysfatal("open %s: %r", TEMP "/data1");
connect(wcmd, fd0, ifd1);
fd1 = open(TEMP "/data1", OWRITE);
if(fd1 < 0)
sysfatal("open %s: %r", TEMP "/data1");
connect(rcmd, ifd0, fd1);
unmount(nil, TEMP);
exits(nil);
}
next reply other threads:[~2000-07-30 23:17 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-07-30 23:17 rob pike [this message]
-- strict thread matches above, loose matches on Subject: below --
2000-08-03 23:46 okamoto
2000-08-03 4:49 rob pike
2000-08-03 4:15 okamoto
2000-08-03 3:44 okamoto
2000-08-03 7:14 ` Matt
2000-08-03 3:19 okamoto
2000-08-03 0:19 okamoto
2000-08-02 21:19 rob pike
[not found] <rob@plan9.bell-labs.com>
2000-08-02 14:48 ` rob pike
2000-08-02 15:49 ` James A. Robinson
2000-08-02 7:55 okamoto
2000-08-03 8:21 ` Boyd Roberts
2000-07-31 9:47 okamoto
2000-07-31 4:55 rob pike
2000-07-31 4:40 okamoto
2000-07-31 1:14 rob pike
2000-08-02 3:40 ` Skip Tavakkolian
2000-08-03 1:21 ` Skip Tavakkolian
2000-07-30 23:46 Steve Harris
2000-07-30 23:06 rob pike
2000-07-30 22:38 Steve Harris
2000-07-30 19:54 rob pike
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=200007302317.TAA01751@cse.psu.edu \
--to=rob@plan9.bell-labs.com \
--cc=9fans@cse.psu.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).