diff options
Diffstat (limited to 'appl/cmd')
| -rw-r--r-- | appl/cmd/ip/virgild.b | 8 | ||||
| -rw-r--r-- | appl/cmd/listen.b | 29 | ||||
| -rw-r--r-- | appl/cmd/mount.b | 29 | ||||
| -rw-r--r-- | appl/cmd/rcmd.b | 26 | ||||
| -rw-r--r-- | appl/cmd/styxlisten.b | 34 |
5 files changed, 51 insertions, 75 deletions
diff --git a/appl/cmd/ip/virgild.b b/appl/cmd/ip/virgild.b index 5e44476e..79c3b24b 100644 --- a/appl/cmd/ip/virgild.b +++ b/appl/cmd/ip/virgild.b @@ -5,6 +5,9 @@ sys: Sys; include "draw.m"; +include "dial.m"; +dial: Dial; + include "ip.m"; Virgild: module @@ -19,6 +22,7 @@ Udphdrsize: con IP->Udphdrlen; init(nil: ref Draw->Context, nil: list of string) { sys = load Sys Sys->PATH; + dial = load Dial Dial->PATH; stderr = sys->fildes(2); @@ -66,8 +70,8 @@ init(nil: ref Draw->Context, nil: list of string) openlisten(): ref Sys->FD { - (ok, c) := sys->announce("udp!*!virgil"); - if(ok < 0){ + c := dial->announce("udp!*!virgil"); + if(c == nil){ sys->fprint(stderr, "virgild: can't open port: %r\n"); return nil; } diff --git a/appl/cmd/listen.b b/appl/cmd/listen.b index 25869223..61c5ecf9 100644 --- a/appl/cmd/listen.b +++ b/appl/cmd/listen.b @@ -7,6 +7,8 @@ include "keyring.m"; keyring: Keyring; include "security.m"; auth: Auth; +include "dial.m"; + dial: Dial; include "sh.m"; sh: Sh; Context: import sh; @@ -31,6 +33,9 @@ init(drawctxt: ref Draw->Context, argv: list of string) auth = load Auth Auth->PATH; if (auth == nil) badmodule(Auth->PATH); + dial = load Dial Dial->PATH; + if (dial == nil) + badmodule(Dial->PATH); sh = load Sh Sh->PATH; if (sh == nil) badmodule(Sh->PATH); @@ -120,8 +125,8 @@ listen1(drawctxt: ref Draw->Context, addr: string, argv: list of string, sys->pctl(Sys->FORKFD, nil); ctxt := Context.new(drawctxt); - (ok, acon) := sys->announce(addr); - if (ok == -1) { + acon := dial->announce(addr); + if (acon == nil) { sys->fprint(stderr(), "listen: failed to announce on '%s': %r\n", addr); sync <-= "cannot announce"; exit; @@ -146,12 +151,12 @@ listen1(drawctxt: ref Draw->Context, addr: string, argv: list of string, } sync <-= nil; - listench := chan of (int, Sys->Connection); - authch := chan of (string, Sys->Connection); + listench := chan of (int, ref Sys->Connection); + authch := chan of (string, ref Sys->Connection); spawn listener(listench, acon, addr); for (;;) { user := ""; - ccon: Sys->Connection; + ccon: ref Sys->Connection; alt { (lok, c) := <-listench => if (lok == -1){ @@ -182,11 +187,11 @@ listen1(drawctxt: ref Draw->Context, addr: string, argv: list of string, } } -listener(listench: chan of (int, Sys->Connection), c: Sys->Connection, addr: string) +listener(listench: chan of (int, ref Sys->Connection), c: ref Sys->Connection, addr: string) { for (;;) { - (ok, nc) := sys->listen(c); - if (ok == -1) { + nc := dial->listen(c); + if (nc == nil) { sys->fprint(stderr(), "listen: listen error on '%s': %r\n", addr); listench <-= (-1, nc); exit; @@ -194,19 +199,19 @@ listener(listench: chan of (int, Sys->Connection), c: Sys->Connection, addr: str if (verbose) sys->fprint(stderr(), "listen: got connection on %s from %s", addr, readfile(nc.dir + "/remote")); - nc.dfd = sys->open(nc.dir + "/data", Sys->ORDWR); + nc.dfd = dial->accept(nc); if (nc.dfd == nil) sys->fprint(stderr(), "listen: cannot open %s: %r\n", nc.dir + "/data"); else{ if(nc.cfd != nil) sys->fprint(nc.cfd, "keepalive"); - listench <-= (ok, nc); + listench <-= (0, nc); } } } -authenticator(authch: chan of (string, Sys->Connection), - c: Sys->Connection, algs: list of string, addr: string) +authenticator(authch: chan of (string, ref Sys->Connection), + c: ref Sys->Connection, algs: list of string, addr: string) { err: string; (c.dfd, err) = auth->server(algs, serverkey, c.dfd, 0); diff --git a/appl/cmd/mount.b b/appl/cmd/mount.b index 5bf4fe7b..9cac7da5 100644 --- a/appl/cmd/mount.b +++ b/appl/cmd/mount.b @@ -5,6 +5,8 @@ include "sys.m"; include "draw.m"; include "keyring.m"; include "security.m"; +include "dial.m"; + dial: Dial; include "factotum.m"; include "styxconv.m"; include "styxpersist.m"; @@ -140,7 +142,7 @@ connect(ctxt: ref Draw->Context, dest: string): ref Sys->FD svc := "styx"; if(do9) svc = "9fs"; - dest = netmkaddr(dest, "net", svc); + dest = dial->netmkaddr(dest, "net", svc); if(persist){ styxpersist := load Styxpersist Styxpersist->PATH; if(styxpersist == nil) @@ -152,8 +154,8 @@ connect(ctxt: ref Draw->Context, dest: string): ref Sys->FD spawn dialler(c, dest); return p[1]; } - (ok, c) := sys->dial(dest, nil); - if(ok < 0) + c := dial->dial(dest, nil); + if(c == nil) fail("dial failed", sys->sprint("can't dial %s: %r", dest)); return c.dfd; } @@ -163,8 +165,8 @@ dialler(dialc: chan of chan of ref Sys->FD, dest: string) while((reply := <-dialc) != nil){ if(verbose) sys->print("dialling %s\n", addr); - (ok, c) := sys->dial(dest, nil); - if(ok == -1){ + c := dial->dial(dest, nil); + if(c == nil){ reply <-= nil; continue; } @@ -237,7 +239,7 @@ authenticate(keyfile, alg: string, dfd: ref Sys->FD, addr: string): (ref Sys->FD kd := "/usr/" + user() + "/keyring/"; if(keyfile == nil) { - cert = kd + netmkaddr(addr, "tcp", ""); + cert = kd + dial->netmkaddr(addr, "tcp", ""); (ok, nil) := sys->stat(cert); if (ok < 0) cert = kd + "default"; @@ -279,21 +281,6 @@ user(): string return string buf[0:n]; } -netmkaddr(addr, net, svc: string): string -{ - if(net == nil) - net = "net"; - (n, nil) := sys->tokenize(addr, "!"); - if(n <= 1){ - if(svc== nil) - return sys->sprint("%s!%s", net, addr); - return sys->sprint("%s!%s!%s", net, addr, svc); - } - if(svc == nil || n > 2) - return addr; - return sys->sprint("%s!%s", addr, svc); -} - kill(pid: int) { if ((fd := sys->open("#p/" + string pid + "/ctl", Sys->OWRITE)) != nil) diff --git a/appl/cmd/rcmd.b b/appl/cmd/rcmd.b index 8815f9b7..5062c708 100644 --- a/appl/cmd/rcmd.b +++ b/appl/cmd/rcmd.b @@ -4,6 +4,7 @@ include "sys.m"; include "draw.m"; include "arg.m"; include "keyring.m"; +include "dial.m"; include "security.m"; Rcmd: module @@ -14,10 +15,14 @@ Rcmd: module DEFAULTALG := "none"; sys: Sys; auth: Auth; +dial: Dial; init(nil: ref Draw->Context, argv: list of string) { sys = load Sys Sys->PATH; + dial = load Dial Dial->PATH; + if(dial == nil) + badmodule(Dial->PATH); arg := load Arg Arg->PATH; if(arg == nil) badmodule(Arg->PATH); @@ -78,9 +83,9 @@ init(nil: ref Draw->Context, argv: list of string) keyfile = "/usr/" + user() + "/keyring/default"; } - (ok, c) := sys->dial(netmkaddr(addr, "tcp", "rstyx"), nil); - if(ok < 0) - error(sys->sprint("dial server failed: %r")); + c := dial->dial(dial->netmkaddr(addr, "tcp", "rstyx"), nil); + if(c == nil) + error(sys->sprint("dial %s failed: %r", addr)); fd := c.dfd; if (doauth) { @@ -137,21 +142,6 @@ user(): string return string buf[0:n]; } -netmkaddr(addr, net, svc: string): string -{ - if(net == nil) - net = "net"; - (n, nil) := sys->tokenize(addr, "!"); - if(n <= 1){ - if(svc== nil) - return sys->sprint("%s!%s", net, addr); - return sys->sprint("%s!%s!%s", net, addr, svc); - } - if(svc == nil || n > 2) - return addr; - return sys->sprint("%s!%s", addr, svc); -} - stderr(): ref Sys->FD { return sys->fildes(2); diff --git a/appl/cmd/styxlisten.b b/appl/cmd/styxlisten.b index df136e47..ae9f7b45 100644 --- a/appl/cmd/styxlisten.b +++ b/appl/cmd/styxlisten.b @@ -6,6 +6,8 @@ include "keyring.m"; keyring: Keyring; include "security.m"; auth: Auth; +include "dial.m"; + dial: Dial; include "arg.m"; include "sh.m"; @@ -28,6 +30,9 @@ init(ctxt: ref Draw->Context, argv: list of string) auth = load Auth Auth->PATH; if (auth == nil) badmodule(Auth->PATH); + dial = load Dial Dial->PATH; + if (dial == nil) + badmodule(Dial->PATH); if ((e := auth->init()) != nil) error("auth init failed: " + e); keyring = load Keyring Keyring->PATH; @@ -76,7 +81,7 @@ init(ctxt: ref Draw->Context, argv: list of string) arg = nil; if (doauth && algs == nil) algs = getalgs(); - addr := netmkaddr(hd argv, "tcp", "styx"); + addr := dial->netmkaddr(hd argv, "tcp", "styx"); cmd := tl argv; authinfo: ref Keyring->Authinfo; @@ -88,8 +93,8 @@ init(ctxt: ref Draw->Context, argv: list of string) error(sys->sprint("cannot read %s: %r", keyfile)); } - (ok, c) := sys->announce(addr); - if (ok == -1) + c := dial->announce(addr); + if (c == nil) error(sys->sprint("cannot announce on %s: %r", addr)); if(!trusted){ sys->unmount(nil, "/mnt/keys"); # should do for now @@ -103,17 +108,17 @@ init(ctxt: ref Draw->Context, argv: list of string) spawn listener(c, popen(ctxt, cmd, lsync), authinfo, algs, lsync); } -listener(c: Sys->Connection, mfd: ref Sys->FD, authinfo: ref Keyring->Authinfo, algs: list of string, lsync: chan of int) +listener(c: ref Sys->Connection, mfd: ref Sys->FD, authinfo: ref Keyring->Authinfo, algs: list of string, lsync: chan of int) { lsync <-= sys->pctl(0, nil); for (;;) { - (n, nc) := sys->listen(c); - if (n == -1) + nc := dial->listen(c); + if (nc == nil) error(sys->sprint("listen failed: %r")); if (verbose) sys->fprint(stderr(), "styxlisten: got connection from %s", readfile(nc.dir + "/remote")); - dfd := sys->open(nc.dir + "/data", Sys->ORDWR); + dfd := dial->accept(nc); if (dfd != nil) { if(nc.cfd != nil) sys->fprint(nc.cfd, "keepalive"); @@ -245,18 +250,3 @@ stderr(): ref Sys->FD { return sys->fildes(2); } - -netmkaddr(addr, net, svc: string): string -{ - if(net == nil) - net = "net"; - (n, nil) := sys->tokenize(addr, "!"); - if(n <= 1){ - if(svc== nil) - return sys->sprint("%s!%s", net, addr); - return sys->sprint("%s!%s!%s", net, addr, svc); - } - if(svc == nil || n > 2) - return addr; - return sys->sprint("%s!%s", addr, svc); -} |
