aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/dial.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-01-04 22:30:59 +0000
committerrsc <devnull@localhost>2005-01-04 22:30:59 +0000
commitb2ad2ef1387571c7b917a7fd63e8670582ae8b7f (patch)
treea46fed64d497f15e824a1c394952a583c98c607b /src/cmd/dial.c
parent48bfee4e5b72db021da3538c97ef68ce2308f12b (diff)
downloadplan9port-b2ad2ef1387571c7b917a7fd63e8670582ae8b7f.tar.gz
plan9port-b2ad2ef1387571c7b917a7fd63e8670582ae8b7f.tar.bz2
plan9port-b2ad2ef1387571c7b917a7fd63e8670582ae8b7f.zip
in with the new
Diffstat (limited to 'src/cmd/dial.c')
-rw-r--r--src/cmd/dial.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/cmd/dial.c b/src/cmd/dial.c
new file mode 100644
index 00000000..c2b18f5f
--- /dev/null
+++ b/src/cmd/dial.c
@@ -0,0 +1,62 @@
+#include <u.h>
+#include <libc.h>
+
+void
+usage(void)
+{
+ fprint(2, "usage: dial [-e] addr\n");
+ exits("usage");
+}
+
+void
+killer(void *x, char *msg)
+{
+ USED(x);
+ if(strcmp(msg, "kill") == 0)
+ exits(0);
+ noted(NDFLT);
+}
+
+void
+main(int argc, char **argv)
+{
+ int fd, pid;
+ char buf[8192];
+ int n, waitforeof;
+
+ notify(killer);
+ waitforeof = 0;
+ ARGBEGIN{
+ case 'e':
+ waitforeof = 1;
+ break;
+ default:
+ usage();
+ }ARGEND
+
+ if(argc != 1)
+ usage();
+
+ if((fd = dial(argv[0], nil, nil, nil)) < 0)
+ sysfatal("dial: %r");
+
+ switch(pid = fork()){
+ case -1:
+ sysfatal("fork: %r");
+ case 0:
+ while((n = read(0, buf, sizeof buf)) > 0)
+ if(write(0, buf, n) < 0)
+ break;
+ if(!waitforeof)
+ postnote(PNPROC, getppid(), "kill");
+ exits(nil);
+ }
+
+ while((n = read(fd, buf, sizeof buf)) > 0)
+ if(write(1, buf, n) < 0)
+ break;
+
+ postnote(PNPROC, pid, "kill");
+ waitpid();
+ exits(0);
+}