# HG changeset patch # User Erik Quanstrom # Date 1322902372 -3600 # Node ID d1772e16b9f4b19e6a7a381ea0a4ccf189a4fe5a # Parent e13d35755cd082ac5049029f637d4c92f79c9714 telnet.c: don't ignore segattach failure 1. don't ignore segattach failure. in addition, it's not necessary to tell segattach the virtual address to attach the segment at. (and run the risk of picking a bad address.) as per segattach(2) when given a virtual address of 0, segattach will find a hole in the addres space and attach it there. 2. if posting to /srv to allow later connections, daemonize (fork) so the caller doesn't need to remember to background a task that always runs in the background. 3. supress fiddling with /dev/consctl if posting the connection to /srv. that's the wrong consctl. the console doing the connecting is attaching to the file in /srv, and we don't have access to his consctl. he'll need to make his own arrangements. rawon() and rawoff() were merged to consctl() because the variable bit (the message "rawon" or "rawoff") was much smaller than the common bit (all the checks and opening the console). R=nixiedev, noah.evans CC=nix-dev http://codereview.appspot.com/5432046 Committer: Noah Evans diff -r e13d35755cd0 -r d1772e16b9f4 sys/src/cmd/ip/telnet.c --- a/sys/src/cmd/ip/telnet.c Fri Dec 02 15:24:22 2011 +0100 +++ b/sys/src/cmd/ip/telnet.c Sat Dec 03 09:52:52 2011 +0100 @@ -97,7 +97,12 @@ data = dial(name, 0, devdir, 0); if(data < 0) fatal("%s: %r", name, 0); - fprint(2, "connected to %s on %s\n", name, devdir); + if(srv != nil){ + if(rfork(RFPROC | RFNOWAIT | RFNOTEG) != 0) + exits(""); + } + else + fprint(2, "connected to %s on %s\n", name, devdir); return data; } @@ -317,21 +322,29 @@ } } +void +consctlcmd(char *s) +{ + if(srv != nil) + return; + if(debug) + fprint(2, "consctl: %s\n", s); + if(consctl < 0) + consctl = open("/dev/consctl", OWRITE); + if(consctl < 0){ + fprint(2, "can't open consctl: %r\n"); + return; + } + write(consctl, s, strlen(s)); +} + /* * turn keyboard raw mode on */ void rawon(void) { - if(debug) - fprint(2, "rawon\n"); - if(consctl < 0) - consctl = open("/dev/consctl", OWRITE); - if(consctl < 0){ - fprint(2, "can't open consctl: %r\n"); - return; - } - write(consctl, "rawon", 5); + consctlcmd("rawon"); } /* @@ -340,15 +353,7 @@ void rawoff(void) { - if(debug) - fprint(2, "rawoff\n"); - if(consctl < 0) - consctl = open("/dev/consctl", OWRITE); - if(consctl < 0){ - fprint(2, "can't open consctl: %r\n"); - return; - } - write(consctl, "rawoff", 6); + consctlcmd("rawoff"); } /* @@ -556,21 +561,16 @@ } /* - * create a shared segment. Make is start 2 meg higher than the current - * end of process memory. + * create a shared segment. */ void* share(ulong len) { uchar *vastart; - vastart = sbrk(0); - if(vastart == (void*)-1) - return 0; - vastart += 2*1024*1024; - - if(segattach(0, "shared", vastart, len) == (void*)-1) - return 0; + vastart = segattach(0, "shared", 0, len); + if(vastart== (void*)-1) + sysfatal("segattach: %r"); return vastart; }