shithub: riscv

Download patch

ref: 65977417e7cc5919f7c9787f97a528e8c24d2423
parent: d39d1a5303541539f61488317b220c1eb724d7d3
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Jun 29 20:45:37 EDT 2016

rc: write /dev/wdir after printing the prompt, not after executing "cd" command

--- a/sys/src/cmd/rc/lex.c
+++ b/sys/src/cmd/rc/lex.c
@@ -92,6 +92,16 @@
 	if(runq->iflag){
 		pstr(err, promptstr);
 		flush(err);
+		if(newwdir){
+			char dir[4096];
+			int fd;
+			if((fd=open("/dev/wdir", OWRITE))>=0){
+				getwd(dir, sizeof(dir));
+				write(fd, dir, strlen(dir));
+				close(fd);
+			}
+			newwdir = 0;
+		}
 		prompt = vlook("prompt");
 		if(prompt->val && prompt->val->next)
 			promptstr = prompt->val->next->word;
--- a/sys/src/cmd/rc/rc.h
+++ b/sys/src/cmd/rc/rc.h
@@ -65,6 +65,7 @@
 	char	*s;
 };
 
+int newwdir;
 char *promptstr;
 int doprompt;
 
--- a/sys/src/cmd/rc/simple.c
+++ b/sys/src/cmd/rc/simple.c
@@ -139,14 +139,9 @@
 dochdir(char *word)
 {
 	/* report to /dev/wdir if it exists and we're interactive */
-	if(chdir(word)<0) return -1;
-	if(flag['i']!=0){
-		static int wdirfd = -2;
-		if(wdirfd==-2)	/* try only once */
-			wdirfd = open("/dev/wdir", OWRITE|OCEXEC);
-		if(wdirfd>=0)
-			write(wdirfd, word, strlen(word));
-	}
+	if(chdir(word)<0)
+		return -1;
+	newwdir = 1;
 	return 1;
 }