Browse Source

Plan 9 from Bell Labs 2003-01-13

David du Colombier 19 years ago
parent
commit
a41256def3
7 changed files with 350 additions and 17 deletions
  1. 10 6
      dist/replica/plan9.db
  2. 13 0
      dist/replica/plan9.log
  3. 23 0
      rc/bin/rwd
  4. 146 0
      sys/man/1/rwd
  5. 145 0
      sys/src/cmd/aux/conswdir.c
  6. 10 9
      sys/src/cmd/ssh/ssh.c
  7. 3 2
      sys/src/cmd/vnc/draw.c

+ 10 - 6
dist/replica/plan9.db

@@ -77,6 +77,7 @@
 386/bin/aux/cddb - 775 sys sys 1039758537 70432
 386/bin/aux/clog - 775 sys sys 1039758538 65408
 386/bin/aux/consolefs - 775 sys sys 1039758538 152994
+386/bin/aux/conswdir - 775 sys sys 1042425147 38855
 386/bin/aux/cropmarks - 775 sys sys 1020319062 1808
 386/bin/aux/data2s - 775 sys sys 1039758538 59178
 386/bin/aux/depend - 775 sys sys 1039758538 145132
@@ -199,9 +200,9 @@
 386/bin/fmt - 775 sys sys 1039758560 63811
 386/bin/fortune - 775 sys sys 1039758560 66329
 386/bin/fossil - 20000000775 sys sys 1042005470 0
-386/bin/fossil/flchk - 775 sys sys 1042220704 227245
-386/bin/fossil/flfmt - 775 sys sys 1042220705 225830
-386/bin/fossil/fossil - 775 sys sys 1042220706 329526
+386/bin/fossil/flchk - 775 sys sys 1042352737 227864
+386/bin/fossil/flfmt - 775 sys sys 1042352739 226447
+386/bin/fossil/fossil - 775 sys sys 1042352736 330877
 386/bin/freq - 775 sys sys 1039758560 60443
 386/bin/fs - 20000000775 sys sys 954380769 0
 386/bin/fs/32vfs - 775 sys sys 1039758560 96155
@@ -353,7 +354,7 @@
 386/bin/srv - 775 sys sys 1039758591 80150
 386/bin/srvfs - 775 sys sys 1039758592 39914
 386/bin/srvold9p - 775 sys sys 1039758592 130502
-386/bin/ssh - 775 sys sys 1039758592 209655
+386/bin/ssh - 775 sys sys 1042424645 209316
 386/bin/sshnet - 775 sys sys 1039758593 281010
 386/bin/stats - 775 sys sys 1039758593 184849
 386/bin/strings - 775 sys sys 1039758593 60879
@@ -2922,6 +2923,7 @@ rc/bin/replica/pull - 775 sys sys 1019526606 1422
 rc/bin/replica/push - 775 sys sys 1019276168 349
 rc/bin/replica/scan - 775 sys sys 1018323467 401
 rc/bin/replica/setupdirs - 775 sys sys 1018321122 408
+rc/bin/rwd - 775 sys sys 1042418590 349
 rc/bin/seemail - 775 sys sys 945617208 59
 rc/bin/service - 20000000775 sys sys 1018831800 0
 rc/bin/service.auth - 20000000775 sys sys 1018029993 0
@@ -4497,6 +4499,7 @@ sys/man/1/resample - 664 sys sys 1015024740 1083
 sys/man/1/rio - 664 sys sys 1015024740 14087
 sys/man/1/rm - 664 sys sys 944959673 515
 sys/man/1/rtstats - 664 sys sys 1018897631 2108
+sys/man/1/rwd - 664 sys sys 1042428060 2601
 sys/man/1/sam - 664 sys sys 984709628 18107
 sys/man/1/secstore - 664 sys sys 1041890056 3434
 sys/man/1/sed - 664 sys sys 944959674 6884
@@ -6520,6 +6523,7 @@ sys/src/cmd/aux/astarld.c - 664 sys sys 1015008684 4638
 sys/src/cmd/aux/cddb.c - 664 sys sys 1032059267 4303
 sys/src/cmd/aux/clog.c - 664 sys sys 1014925109 1000
 sys/src/cmd/aux/consolefs.c - 664 sys sys 1014925110 20022
+sys/src/cmd/aux/conswdir.c - 664 sys sys 1042425146 2071
 sys/src/cmd/aux/data2s.c - 664 sys sys 1032059295 796
 sys/src/cmd/aux/depend.c - 664 sys sys 1015008684 25780
 sys/src/cmd/aux/disksim.c - 664 sys sys 1032325930 10218
@@ -9828,7 +9832,7 @@ sys/src/cmd/ssh/msg.c - 664 sys sys 1038293465 7740
 sys/src/cmd/ssh/pubkey.c - 664 sys sys 1019928902 3974
 sys/src/cmd/ssh/scp.c - 664 sys sys 1016466380 13768
 sys/src/cmd/ssh/smsg.c - 664 sys sys 1016466380 4225
-sys/src/cmd/ssh/ssh.c - 664 sys sys 1038445589 9529
+sys/src/cmd/ssh/ssh.c - 664 sys sys 1042424644 9603
 sys/src/cmd/ssh/ssh.h - 664 sys sys 1038293464 6011
 sys/src/cmd/ssh/ssh_genkey.c - 664 sys sys 1016466380 1563
 sys/src/cmd/ssh/sshnet.c - 664 sys sys 1038293468 17653
@@ -10474,7 +10478,7 @@ sys/src/cmd/vnc/dev.c - 664 sys sys 1014925997 5502
 sys/src/cmd/vnc/devcons.c - 664 sys sys 1034430139 6915
 sys/src/cmd/vnc/devdraw.c - 664 sys sys 1039753056 42068
 sys/src/cmd/vnc/devmouse.c - 664 sys sys 1034430139 7386
-sys/src/cmd/vnc/draw.c - 664 sys sys 1034430140 6947
+sys/src/cmd/vnc/draw.c - 664 sys sys 1042391341 6958
 sys/src/cmd/vnc/error.h - 664 sys sys 1014925998 2482
 sys/src/cmd/vnc/errstr.h - 664 sys sys 1014925998 2018
 sys/src/cmd/vnc/exporter.c - 664 sys sys 1014925998 1312

+ 13 - 0
dist/replica/plan9.log

@@ -17026,3 +17026,16 @@
 1042311764 10 c sys/src/cmd/fossil/source.c - 664 sys sys 1042311692 18406
 1042312269 0 c sys/man/8/fossilcons - 664 sys sys 1042312265 12639
 1042331465 0 c sys/man/1/ssh - 664 sys sys 1042330461 6968
+1042353085 0 c 386/bin/fossil/flchk - 775 sys sys 1042352737 227864
+1042353085 1 c 386/bin/fossil/flfmt - 775 sys sys 1042352739 226447
+1042353085 2 c 386/bin/fossil/fossil - 775 sys sys 1042352736 330877
+1042392740 0 c sys/src/cmd/vnc/draw.c - 664 sys sys 1042391341 6958
+1042418618 0 a 386/bin/aux/conswdir - 775 sys sys 1042418599 38018
+1042418618 1 a rc/bin/rwd - 775 sys sys 1042418590 349
+1042418618 2 a sys/man/1/rwd - 664 sys sys 1042418606 2558
+1042418618 3 a sys/src/cmd/aux/conswdir.c - 664 sys sys 1042418595 1802
+1042424651 0 c 386/bin/ssh - 775 sys sys 1042424645 209316
+1042424651 1 c sys/src/cmd/ssh/ssh.c - 664 sys sys 1042424644 9603
+1042425176 0 c 386/bin/aux/conswdir - 775 sys sys 1042425147 38855
+1042425176 1 c sys/src/cmd/aux/conswdir.c - 664 sys sys 1042425146 2071
+1042428779 0 c sys/man/1/rwd - 664 sys sys 1042428060 2601

+ 23 - 0
rc/bin/rwd

@@ -0,0 +1,23 @@
+#!/bin/rc
+
+rfork e
+if(! ~ $#* 1){
+	echo 'usage: remotesys=xxx rwd dir' >[1=2]
+	exit usage
+}
+
+suf=''
+if(~ $#remotesys 1)
+	suf = @$remotesys
+if not
+	remotesys=''
+
+echo -n $1 >/dev/wdir
+b=`{basename $1}
+if(! ~ $#b 1)
+	b=/
+echo -n $b^$suf >/dev/label
+if(test -f /dev/acme/ctl){
+	echo name $1/-$remotesys >/dev/acme/ctl
+	echo dumpdir $1 >/dev/acme/ctl
+}

+ 146 - 0
sys/man/1/rwd

@@ -0,0 +1,146 @@
+.TH RWD 1
+.SH NAME
+rwd, conswdir \- maintain remote working directory
+.SH SYNOPSIS
+.B rwd
+.I path
+.PP
+.B conswdir
+[
+.I prog
+]
+.SH DESCRIPTION
+.I Rwd
+and
+.I conswdir
+conspire to keep 
+.IR rio (4)
+and
+.IR acme (4)
+informed about the current directory on
+remote systems during login sessions.
+.I Rio
+and
+.I acme
+include this information in plumb messages sent to
+.IR plumber (4).
+If the remote system's name space is mounted in the
+plumber's name space,
+the end result is that file paths printed during the session
+are plumbable.
+.PP
+.I Rwd
+informs
+.IR rio
+and
+.IR acme
+of directory changes.
+The name of the remote machine is taken from
+the environment variable
+.BR $remotesys .
+.I Rwd
+writes the full path to
+.BR /dev/wdir ;
+writes the last element of the path,
+suffixed by
+.BI @ remotesys \fR,
+to
+.BR /dev/label ;
+and when run inside a 
+.I win
+(see
+.IR acme (1))
+window, changes the window title to
+.IB path /- remotesys
+using
+.BR /dev/acme/ctl .
+.PP
+.I Conswdir
+copies standard input to standard output, looking for in-band messages
+about directory changes.
+The messages are of the form:
+.IP
+.EX
+\e033];\fIpath\fP\e007
+.EE
+.LP
+where
+.B \e033
+and
+.B \e007
+are ASCII escape and bell characters.
+Such messages are removed from the stream and not printed to standard output;
+for each such message
+.I conswdir
+runs
+.I prog
+(default
+.BR /bin/rwd )
+with
+.I path
+as its only argument.
+.SH EXAMPLES
+Add this plumbing rule (see
+.IR plumb (6))
+in order to run commands in the plumber's name space:
+.IP
+.EX
+# have plumber run command
+kind is text
+data matches 'Local (.*)'
+plumb to none
+plumb start rc -c $1
+.EE
+.PP
+Mount a Unix system in your name space and the plumber's:
+.IP
+.EX
+% 9fs unix
+% plumb 'Local 9fs unix'
+.EE
+.LP
+(If you're using acme, execute
+.B "Local 9fs unix
+with the middle button to mount the Unix system in acme's name space.)
+.PP
+Connect to the Unix system, processing in-band directory change messages:
+.IP
+.EX
+% ssh unix | aux/conswdir
+.EE
+.PP
+Add this shell function to your
+.B .profile
+on the Unix system
+to generate directory change messages every time a
+.B cd
+command is executed:
+.IP
+.EX
+H=`hostname | sed 's/\e..*//'`
+_cd () {
+	\ecd $* &&
+	case $- in
+	*i*)
+		_dir=`pwd`
+		echo /n/$H$_dir | awk '{printf("\e033];%s\e007", $1);}'
+	esac
+}
+alias cd=_cd
+.EE
+.SH SOURCE
+.B /rc/bin/rwd
+.br
+.B /sys/src/cmd/aux/conswdir.c
+.SH SEE ALSO
+.IR plumber (4),
+.IR plumb (6),
+.IR srv (4)
+.SH BUGS
+This mechanism is clunky, but Unix and SSH
+make it hard to build a better one.
+.PP
+This doesn't handle rooted path names.
+.PP
+The escape sequence was chosen because
+it changes the title on xterm windows.

+ 145 - 0
sys/src/cmd/aux/conswdir.c

@@ -0,0 +1,145 @@
+/*
+ * Process in-band messages about window title changes.
+ * The messages are of the form:
+ *
+ *	\033];xxx\007
+ *
+ * where xxx is the new directory.  This format was chosen
+ * because it changes the label on xterm windows.
+ */
+
+#include <u.h>
+#include <libc.h>
+
+char *prog = "/bin/rwd";
+
+void
+usage(void)
+{
+	fprint(2, "usage: conswdir [/bin/rwd]\n");
+	exits("usage");
+}
+
+void
+setpath(char *s)
+{
+	switch(rfork(RFPROC|RFNOWAIT)){
+	case 0:
+		execl(prog, prog, s, nil);
+		_exits(nil);
+	}
+}
+
+enum
+{
+	None,
+	Esc,
+	Brack,
+	Semi,
+	Bell,
+};
+
+int
+process(char *buf, int n, int *pn)
+{
+	char *p;
+	char path[4096];
+	int start, state;
+
+	start = 0;
+	state = None;
+	for(p=buf; p<buf+n; p++){
+		switch(state){
+		case None:
+			if(*p == '\033'){
+				start = p-buf;
+				state++;
+			}
+			break;
+		case Esc:
+			if(*p == ']')
+				state++;
+			else
+				state = None;
+			break;
+		case Brack:
+			if(*p == ';')
+				state++;
+			else
+				state = None;
+			break;
+		case Semi:
+			if(*p == '\007')
+				state++;
+			else if((uchar)*p < 040)
+				state = None;
+			break;
+		}
+		if(state == Bell){
+			memmove(path, buf+start+3, p - (buf+start+3));
+			path[p-(buf+start+3)] = 0;
+			p++;
+			memmove(buf+start, p, n-(p-buf));
+			n -= p-(buf+start);
+			p = buf+start;
+			p--;
+			start = 0;
+			state = None;
+			setpath(path);
+		}
+	}
+	/* give up if we go too long without seeing the close */
+	*pn = n;
+	if(state == None || p-(buf+start) >= 2048)
+		return (p - buf);
+	else
+		return start;
+}
+
+static void
+catchint(void*, char *msg)
+{
+	if(strstr(msg, "interrupt"))
+		noted(NCONT);
+	else if(strstr(msg, "kill"))
+		noted(NDFLT);
+	else
+		noted(NCONT);
+}
+
+void
+main(int argc, char **argv)
+{
+	char buf[4096];
+	int n, m;
+
+	notify(catchint);
+
+	ARGBEGIN{
+	default:
+		usage();
+	}ARGEND
+
+	if(argc > 1)
+		usage();
+	if(argc == 1)
+		prog = argv[0];
+
+	n = 0;
+	for(;;){
+		m = read(0, buf+n, sizeof buf-n);
+		if(m < 0){
+			rerrstr(buf, sizeof buf);
+			if(strstr(buf, "interrupt"))
+				continue;
+			exits(nil);
+		}
+		n += m;
+		m = process(buf, n, &n);
+		if(m > 0){
+			write(1, buf, m);
+			memmove(buf, buf+m, n-m);
+			n -= m;
+		}
+	}
+}

+ 10 - 9
sys/src/cmd/ssh/ssh.c

@@ -1,6 +1,7 @@
 #include "ssh.h"
 
-int cooked = 0;
+int cooked = 0;		/* user wants cooked mode */
+int raw = 0;		/* console is in raw mode */
 int crstrip;
 int interactive = -1;
 int usemenu = 1;
@@ -315,7 +316,6 @@ fromnet(Conn *c)
  * Lifted from telnet.c, con.c
  */
 
-static int raw;
 static int consctl = -1;
 static int outfd1=1, outfd2=2;	/* changed during system */
 static void system(Conn*, char*);
@@ -330,7 +330,8 @@ rawon(void)
 		return;
 	if(consctl < 0)
 		return;
-	write(consctl, "rawon", 5);
+	if(write(consctl, "rawon", 5) != 5)
+		return;
 	raw = 1;
 }
 
@@ -344,7 +345,8 @@ rawoff(void)
 		return;
 	if(consctl < 0)
 		return;
-	write(consctl, "rawoff", 6);
+	if(write(consctl, "rawoff", 6) != 6)
+		return;
 	raw = 0;
 }
 
@@ -522,20 +524,19 @@ fromstdin(Conn *c)
 	atexit(atexitkiller);
 	if(interactive){
 		consctl = open("/dev/consctl", OWRITE);
-		if(cooked==0)
+		if(!cooked)
 			rawon();
 	}else
 		consctl = -1;
 
-	if(cooked)
-		notify(cookedcatchint);
+	notify(cookedcatchint);
 
 	eofs = 0;
 	for(;;){
 		n = read(0, buf, sizeof(buf));
 		if(n < 0){
 			if(wasintr()){
-				if(cooked){
+				if(!raw){
 					buf[0] = 0x7f;
 					n = 1;
 				}else
@@ -555,7 +556,7 @@ fromstdin(Conn *c)
 			}
 			continue;
 		}
-		if(cooked && n==0){
+		if(!raw && n==0){
 			buf[0] = 0x4;
 			n = 1;
 		}

+ 3 - 2
sys/src/cmd/vnc/draw.c

@@ -236,8 +236,9 @@ dorectangle(Vnc *v)
 	Rectangle r, subr, maxr;
 
 	r = vncrdrect(v);
-	if(!rectinrect(r, Rpt(ZP, v->dim))
-	|| r.min.x == r.max.x || r.min.y == r.max.y)
+	if(r.min.x == r.max.x || r.min.y == r.max.y)
+		return;
+	if(!rectinrect(r, Rpt(ZP, v->dim)))
 		sysfatal("bad rectangle from server: %R not in %R", r, Rpt(ZP, v->dim));
 	stride = Dx(r) * pixb;
 	type = vncrdlong(v);