1 b2ad2ef1 2005-01-04 devnull #include <u.h>
2 b2ad2ef1 2005-01-04 devnull #include <libc.h>
5 b2ad2ef1 2005-01-04 devnull usage(void)
7 b2ad2ef1 2005-01-04 devnull fprint(2, "usage: dial [-e] addr\n");
8 b2ad2ef1 2005-01-04 devnull exits("usage");
12 b2ad2ef1 2005-01-04 devnull killer(void *x, char *msg)
15 b2ad2ef1 2005-01-04 devnull if(strcmp(msg, "kill") == 0)
16 b2ad2ef1 2005-01-04 devnull exits(0);
17 b2ad2ef1 2005-01-04 devnull noted(NDFLT);
21 b2ad2ef1 2005-01-04 devnull main(int argc, char **argv)
23 b2ad2ef1 2005-01-04 devnull int fd, pid;
24 b2ad2ef1 2005-01-04 devnull char buf[8192];
25 b2ad2ef1 2005-01-04 devnull int n, waitforeof;
27 b2ad2ef1 2005-01-04 devnull notify(killer);
28 b2ad2ef1 2005-01-04 devnull waitforeof = 0;
29 b2ad2ef1 2005-01-04 devnull ARGBEGIN{
30 b2ad2ef1 2005-01-04 devnull case 'e':
31 b2ad2ef1 2005-01-04 devnull waitforeof = 1;
37 b2ad2ef1 2005-01-04 devnull if(argc != 1)
40 b2ad2ef1 2005-01-04 devnull if((fd = dial(argv[0], nil, nil, nil)) < 0)
41 b2ad2ef1 2005-01-04 devnull sysfatal("dial: %r");
43 b2ad2ef1 2005-01-04 devnull switch(pid = fork()){
45 b2ad2ef1 2005-01-04 devnull sysfatal("fork: %r");
47 b2ad2ef1 2005-01-04 devnull while((n = read(0, buf, sizeof buf)) > 0)
48 9d597981 2005-02-11 devnull if(write(fd, buf, n) < 0)
50 b2ad2ef1 2005-01-04 devnull if(!waitforeof)
51 b2ad2ef1 2005-01-04 devnull postnote(PNPROC, getppid(), "kill");
52 b2ad2ef1 2005-01-04 devnull exits(nil);
55 b2ad2ef1 2005-01-04 devnull while((n = read(fd, buf, sizeof buf)) > 0)
56 b2ad2ef1 2005-01-04 devnull if(write(1, buf, n) < 0)
59 b2ad2ef1 2005-01-04 devnull postnote(PNPROC, pid, "kill");
60 b2ad2ef1 2005-01-04 devnull waitpid();
61 b2ad2ef1 2005-01-04 devnull exits(0);