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

@ -370,6 +370,7 @@ extern int atoi(const char*);
extern int32_t atol(const char*);
extern int64_t atoll(const char*);
extern double charstod(int(*)(void*), void*);
extern int chdir(const char *dirname);
extern char* cleanname(char*);
extern int decrypt(void*, void*, int);
extern int encrypt(void*, void*, int);
@ -387,7 +388,7 @@ extern char* getenv(const char*);
extern int getfields(char*, char**, int, int, const char*);
extern int gettokens(char *, char **, int, const char *);
extern char* getuser(void);
extern char* getwd(char*, int);
extern long getwd(char*, int);
extern int iounit(int);
extern int32_t labs(int32_t);
extern double ldexp(double, int);