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

This commit is contained in:
cinap_lenrek 2016-06-30 00:45:37 +02:00
parent d39d1a5303
commit 65977417e7
3 changed files with 14 additions and 8 deletions

View file

@ -92,6 +92,16 @@ pprompt(void)
if(runq->iflag){ if(runq->iflag){
pstr(err, promptstr); pstr(err, promptstr);
flush(err); 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"); prompt = vlook("prompt");
if(prompt->val && prompt->val->next) if(prompt->val && prompt->val->next)
promptstr = prompt->val->next->word; promptstr = prompt->val->next->word;

View file

@ -65,6 +65,7 @@ union code{
char *s; char *s;
}; };
int newwdir;
char *promptstr; char *promptstr;
int doprompt; int doprompt;

View file

@ -139,14 +139,9 @@ int
dochdir(char *word) dochdir(char *word)
{ {
/* report to /dev/wdir if it exists and we're interactive */ /* report to /dev/wdir if it exists and we're interactive */
if(chdir(word)<0) return -1; if(chdir(word)<0)
if(flag['i']!=0){ return -1;
static int wdirfd = -2; newwdir = 1;
if(wdirfd==-2) /* try only once */
wdirfd = open("/dev/wdir", OWRITE|OCEXEC);
if(wdirfd>=0)
write(wdirfd, word, strlen(word));
}
return 1; return 1;
} }