kernel: move chdir to libc using devself/devproc

Added wdir to devself and devproc:

- read '#0/wdir' to get the working directory of the calling process
  NOTE that a read(fd, nil, -1) will return the negated length
  of the working directory, just in case you want to
  allocate the memory required

- read '/proc/n/wdir' to know the working directory of process n
  (read(fd, nil, -1) still returns the negated length)

- write '#0/wdir' to change the working directory of the calling process
  NOTE: no offset is allowed and the provided string must
  be null terminated

- write '/proc/n/wdir' to change the working directory of process n
  NOTE: no offset is allowed and the provided string must
  be null terminated; moreover if another process change the working
  directory change during the write, the current process will
  receive an error.

In libc updated getwd() and chdir().
Also modified pwd to get advantage of the new file.

To test, run /arch/amd64/qa/kern/wdir.rc or simply try

	% pwd
	/usr/glenda
	% echo -n /tmp > /proc/$pid/wdir
        % pwd
        /tmp
        % cat '#0/wdir' && echo
        /tmp

The expected use cases for wdir in devproc are rio and acme.

Also, note that we could theoretically remove the cd builtin
from rc and simply implement it as a rc function.
We don't do that to preserve rc portability to other OS.
This commit is contained in:
2016-12-15 22:42:01 +01:00
parent c6de6b66e9
commit 99855d60d6
20 changed files with 357 additions and 308 deletions

View File

@ -597,14 +597,24 @@ mountfix(Chan *c, uint8_t *op, int32_t n, int32_t maxn)
}
long
syspread(int fd, void *p, int32_t n, int64_t off)
syspread(int fd, void *p, long n, int64_t off)
{
int32_t nn;
long nnn;
int sequential;
Chan *c;
p = validaddr(p, n, 1);
if(n >= 0)
p = validaddr(p, n, 1);
else if(p != nil) {
/* in Jehanne, a negative length can be meaningful to
* the target device/server, but with a negative length
* to read the buffer must be nil
*/
pprint("trap: invalid address %#p/%ld in sys call pc=%#P\n", p, n, userpc(nil));
postnote(up, 1, "sys: bad address in syscall", NDebug);
error(Ebadarg);
}
c = fdtochan(fd, OREAD, 1, 1);
@ -679,7 +689,7 @@ syspread(int fd, void *p, int32_t n, int64_t off)
}
long
syspwrite(int fd, void *p, int32_t n, int64_t off)
syspwrite(int fd, void *p, long n, int64_t off)
{
long r;
int sequential;
@ -858,20 +868,6 @@ sysfstat(int fd, uint8_t* p, int n)
return r;
}
int
syschdir(char *aname)
{
Chan *c;
aname = validaddr(aname, 1, 0);
c = namec(aname, Atodir, 0, 0);
cclose(up->dot);
up->dot = c;
return 0;
}
/* white list of devices we allow mounting on.
* At some point we can have build generate this if we ever
* really start using it.