Giacomo Tesio
99855d60d6
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.
34 lines
1.5 KiB
Bash
34 lines
1.5 KiB
Bash
#!/cmd/rc
|
|
|
|
rm -fr /tmp/abcdefghijklmnopqrstuvwxyz/
|
|
|
|
dir=/tmp/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz
|
|
|
|
mkdir -p $dir
|
|
cd $dir
|
|
|
|
cwd=`{pwd}
|
|
|
|
if ( ! ~ $dir $cwd ) {
|
|
echo FAIL: '''pwd''' returned $cwd instead of '$dir'
|
|
exit FAIL
|
|
}
|
|
|
|
cwd=`{cat '#0/wdir'}
|
|
if ( ! ~ $dir $cwd ) {
|
|
echo FAIL: '''cat #0/wdir''' returned $cwd instead of '$dir'
|
|
exit FAIL
|
|
}
|
|
|
|
ppath=/proc/$pid/wdir
|
|
|
|
cwd=`{cat $ppath}
|
|
if ( ! ~ $dir $cwd ) {
|
|
echo FAIL: cat $ppath returned $cwd instead of '$dir'
|
|
exit FAIL
|
|
}
|
|
|
|
rm -fr /tmp/abcdefghijklmnopqrstuvwxyz/
|
|
echo PASS
|
|
exit PASS
|