-
, ,
. , , -
,
. , ,
, ,
. , ,
uucp, -
, , -
, . , ,
, , , -
, . -
UNIX , ,
. , ,
open read
, .
13.1.
, , ,
, .
, :
,
.
, , ,
. -
, . -
,
+-----------------------------+ +-----------------------------+
| +------------+ | | +------------+ |
| | | | | | | |
| +-----+------+ | | +-----+------+ |
| ----+-------+------+------- | | ----+-------+------+------- |
| +---+----+ +-------+------+ | | +---+----+ +-------+------+ |
| | | | | | | | | | | |
| | | | | | | | | | | |
| +--------+ +--------------+ +-++-+ +--------+ +--------------+ |
+-----------------------------+ ++ +-----------------------------+
|
+-------------+---------------+
| +------------+ |
| | | |
| +-----+------+ |
| ----+-------+------+------- |
| +---+----+ +-------+------+ |
| | | | | |
| | | | | |
| +--------+ +--------------+ |
+-----------------------------+
13.1.
381
-
.
, , -
:
* , ,
( ) -
. -
.
UNIX. ; -
,
, , -
.
* "Newcastle", -
(
"The Newcastle Connection" - . [Brownbridge 82]).
( ),
, -
. -
, ,
, , .
* "" ,
, , -
;
. , -
, ,
.
; -
, -
, . -
, , , , -
-
, , .
,
,
Newcastle "" , ;
, , -
, , -
.
13.2.
-
-
.
, ,
. -
. ,
-
; ,
.
, -
, , , -
.
382
-
. -,
(. [Birrell 84]); ,
, ,
, -
-
. -
.
,
11: -
, .
- . 13.4 -
-, .
+-----------------------------+ +-----------------------------+
| +------------+ | | +------------+ |
| | | | | | | |
| +-----+------+ | | +-----+------+ |
| ----+-------+------+------- | | ----+-------+-------------- |
| +---+----+ +-------+------+ | | +---+----+ |
| | | | | | | | | |
| | | | | | | | | |
| +--------+ +--------------+ +-++-+ +--------+ |
+-----------------------------+ ++ +-----------------------------+
|
+-------------+---------------+
| +------------+ |
| | | |
| +-----+------+ |
| ----+-------+-------------- |
| +---+----+ |
| | | |
| | | |
| +--------+ |
+-----------------------------+
13.2.
, -
, -.
, ,
sbrk. , -
, , ,
, - ( 13.3).
, , -
- ,
(,
), .
(,
, write).
- ;
, ,
, -
. , ,
383
+----------------+----------+---------------+--------------------+
| | | | |
| -| | -|------- ------|
| | | | |
+----------------+----------+---------------+--------------------+
+------------+-----------+---------+---------------------+
| | | | |
| | | |---- ---|
| | | | |
| | | | |
+------------+-----------+---------+---------------------+
13.3.
( ), -
, , , , .
, , -
.
; -
.
, , ,
: getppid, open, write, fork, exit signal.
getppid ,
, .
, ,
, getppid,
. -
,
, .
, -
. -
, ,
getppid. (, -
-) , -
.
open, -
,
. - -
, -
. -
. ,
; open -
, -.
13.4.
write, -
, write,
. -
-. -
, -
(
-
); .
384
+--------------------------------------+ +---------------------+
| | | |
| - | | |
| - | | |
| | | |
| - | | |
| | | |
| +--------+| | +---------+ |
| +-----+ +-----+ +-----+ |-|----------| | |
| | | | | | | | || | +---------+ |
| +-----+ +-----+ +-----+ +-+------+| | |
| | -+-+ | | ++- -+---+ | | |
| +-----+ | +-----+ |+-----+ - | | |
| | | +-+- -+-+| | | | |
| +-----+ +-----+ +-----+ | | |
| | | | | | | |
| +-----+ +-----+ | | |
| | | | | | | |
| +-----+ +-----+ | | |
+--------------------------------------+ +---------------------+
13.4. open
- ,
,
. read ; -
(
, ). , -
, -
.
, -
, fork.
,
-, ,
. ,
, fork -
, . -
, fork, -
, , -
-
. - ( ) , -
fork;
-, , -
fork. -
fork; -
. -
( )
- .
13.5:
"-", - .
fork , -
,
. -
385
+----------------------+ +----------------------+
| +------------------+ | | +------------------+ |
| | - |-------------| - | |
| +---------+--------+ | | +------------------+ |
| | | | |
| | | | |
| +---------+--------+ | | +------------------+ |
| | -|-------------| - | |
| | | | | | | |
| +------------------+ | | +------------------+ |
+----------------------+ +----------------------+
13.5. fork
: - -
,
.
. , -
- fork, , -
, ,
. , ,
- , -
, , -
. fork
13.6. ,
- . -
- .
+-------------------------------------------------------+
| +------------------+ +-----------------+ |
| | - +----------+ - | |
| +------------------+ +-----------------+ |
| - - |
+-------------------------------------------------------+
- -
+---------------------------+ +---------------------------+
| - | | - |
| +-----------------------+ | | +----------------------+ |
| | | | | | | |
| +-----------------------+ | | +----------------------+ |
+---------------------------+ +---------------------------+
13.6. fork
, -
:
, , , , -
-
, , .
-
, , -
. -
386
, -
. ,
exit:
-, , , .
signal, -
, ,
. - ,
. -
( 13.7): -
, signal -
,
+------------------------------------------------------------+
| sighandle /* */ |
| : |
| : |
| { |
| ( - |
| ) |
| { |
| ( ) |
| ; |
| ( |
| ) |
| -; |
| |
| -|
| ; |
| } |
| /* */ |
| { |
| /* |
| * |
| */ |
| -; |
| } |
| } |
| |
| satellite_end_of_syscall /* - |
| * , - |
| * |
| * */ |
| : |
| : |
| { |
| ( |
| ) |
| - |
| , ; |
| /* |
| * */ |
| : , - |
| ; |
| } |
+------------------------------------------------------------+
13.7.
387
- . .
, ,
- .
, - , -
. .
1. - -
, , -
, -
, .
2. ,
,
longjmp. , -
, .
3. -
( longjmp), -
.
-
-
. , -
: , , -
,
.
-
+------------------------------------------------------------
| read -
| -
| - -
| -
| -
| - -
| - read
| - -
| -
| -
| -
| -
| - -
| - -
| - (
| - "break")
| -
| -
| -
| -
| - -
| - :
| -
| -
|
|
v
13.8.
388
, ,
, ,
- ( 13.8).
(break), -
- . -
,
read.
,
. , -
,
. read -
, , -
-, . -
exit, -
-.
, -
read . ,
stat, (
stat , -
).
. -
.
-
, -
, -
. -
,
.
, -
( ).
,
.
read, , -
, -
. -
: -
, ,
; -
.
, , ,
. ,
, ,
. -
, . -
, ,
.
-
, kill -
-, . -
, , -
, ( -
) .
389
, -
-
()
. , -
, , -
. , -
, , ,
.
, ,
(
), .
.
: , , -
, - , .
, ,
"sftig!/fs1/mjb/rje"
"/fs1/mjb/rje", "sftig".
, -
uucp UNIX.
-
, :
/../sftig/fs1/mjb/rje
"/../" - , , ;
. -
- -
+-----------------------------+ +----------------------------+
| | | - |
| - | | |
| | | (- |
| +------+ | | | | |
| +--------------+--- | | | ) | | |
| | +------+ | | | | |
| | | | | | +-------------+ | |
| | +------+ | | | | |
| | +----+--- | | | | | |
| | | +------+ | | | | |
| | | | | | | | | |
| | | +------+ | | | | |
| | +-----+ | | | | |
+----+---------------+--------+ +----+-----------------+-----+
| | | |
+----+---------------+--------+ +----+-----------------+-----+
| | | | | |
| | | |
| | | | | |
+--------------------+--------+ +----------------------+-----+
| |
+-------------------------------------+
13.9. ()
390
UNIX,
-
, (. [Pike
85]).
,
Newcastle, -
;
-, -
. , -
-
. , -
.
13.9 , -
. , -
. :
open("/../sftig/fs1/mjb/rje/file",O_RDONLY);
open - -
,
"sftig". , -
, , -
, -
, .
, -
, -
,
-.
, -
, . ,
"mjb" , -
. , , -
"mjb"
. ,
,
,
. , -
- .
-
. , --
,
. ,
, ,
. mkdir
(. 7), .
, -
.
mkdir
. , setuid- (
mkdir)
, . , -
, -
; , -
( )
.
391
open , -
,
, -,
. read
write , , ,
. -
, .
, ,
, ,
: .
, . -
, , -
, ,
, -
.
.
, -
, -
, , .
, , -
(/), ,
- , . -
- ,
. chroot
,
; ,
, .
fork, -
. -
--
. - fork, -
; -
-, .
fork -
. , -
, ( exit),
,
. exec exit -
.
Newcastle ,
"" ( ),
. ,
. , -
.
- , -
; -
. -
-
, -
.
- , -
,
. -
,
. , , -
,
; -
. -
392
, .
" " , ,
, , ,
, , ,
-
. , ,
, : -
. ,
13.10, "/usr/src", B, ""
"/usr/src", A. -
,
, "/usr/src".
, A, , -
B, (-
: "/usr/src/cmd/login.c"), ,
. , B, -
( , -
A), , , -
, A. , ,
, , -
,
.
A B
+-----------------------------+ +-----------------------------+
| / | | / |
| | | | | |
| +--------+--------+ | | +-----------+-----------+ |
| | | | | | | | |
| bin usr | | usr bin etc |
| | | | | | |
| +----+----+ +----+--+ | | +-------+ |
| | | | | | | | | |
|login mail bin src| +--->src bin |
| | | | | | | |
| +---+---+ | | | | +------+-----+ |
| | | | | | | | | | |
| troff vi | | | | lib cmd uts |
| | | | | | |
| | | | | +---+---+ |
| | | | | | | |
| | | | | login.c mail.c |
+---------------------------|-+ | +-----------------------------+
+---+
13.10.
-
mount .
.
mount,
393
, .
, "..". -
, -
".."
, , -
. 13.10, , , -
A,
"/usr/src/cmd", ,
cd ../../..
, A, -
B. namei, , -
"..", , -
-, , -
.
:
. -
, , ,
, , -
.
,
5. ,
, -
, -
-
. ,
, , .. -
, -
() -
(. [Sandberg 85]).
(/)
+--------------------+ +----------------------------------------+
| | | |
| +-------+ | | - |
| +-----+ ||-| | +-----+ +-----+ - |
| | | +-+-----+ |- | | | | | |
| +-----+ | | - +-----+ +-----+ - +-------+|
| | | | +------+- -+-+ | | +--+||
| +-----+ | | | | +-----+ | +-----+ | +-------+|
| | | | | | | | | +-+- -++ +-----+ | |
| +-----+ | | | | +-----+ +-----+| | | | |
| | | | | | | | | | || +-----+ | |
| +-----+ | | | | +-----+ +-----++-+- -+-+ |
| | --+----+-----+ | | | | | | +-----+ |
| +-----+ | | +-----+ +-----+ | | |
| | | +-----+ |
+--------------------+ +----------------------------------------+
13.11.
,
"/usr/src/cmd/login.c", "src" - . -
( namei-iget), ,
, , , -
. , -
394
, . -
( , -
), .
open , 5,
,
.
open 13.11.
read, -
, ,
, , -
.
, -
( )
. ,
, . -
read "",
-
. -
( ),
, , ,
.
(
) ,
,
, .
-
.
-
, . , ,
"core"
( 7). ,
, , -
.
open , -
, , -
, , -
.
"/usr/src/cmd/login.c" "cmd/login.c".
, -
, -
. ,
open, -
, -
.
, -
, , , -
,
( 13.11).
, (-
) , , ,
, .
, - -
.
,
(
), -
, , -
. -
395
, -
. ,
,
.
(-) "-
" ,
--
, .
- (. [Sandberg
85] [Cole 85]). () -
-, -
. -
.
,
. ,
- -
, : ,
, .. - -
.
,
.
,
,
. ,
(, read) , , -
, -
: , -
.. -
-, , , -
-
.
- , -
, -
. -
.
, ,
. , , , -
, -
. , .
, , -
, -
, .
, -
. ,
-
-
. ,
-
-. , -
, -
, ,
, .
,
(, -
396
), ,
.
, .
, -.
, -
, 13.14.
, -
-,
, -
- -.
+------------------------------+
| | |
| +------------------------------+
| | Newcastle |
v +------------------------------+
^ +------------------------------+
| | - |
| | |
| +------------------------------+ +
| | <----+ ,
| | | | -
| +------------------------------+ +
| | <------ -
+------------------------------+
13.12. -
, -
.
13.12. -
, , ,
.
,
. Newcastle ("-
") , -
, -.
, ,
, - .
-
, , ,
, .
""
mount. -
, ,
, -
, . "" -
:
( ,
, )
( ).
397
,
- .
*1. exit
. , -
? -
?
2. SIGKILL; ,
, .
*3. exec
.
*4.
,
?
*5. , -
?
?
6. ,
.
execl("/../sftig/bin/sh","sh",0);
,
. , -
.
7. -
Newcastle ,
- ?
*8. exec
, ,
Newcastle .
. .
*9. 13.2, exit
Newcastle -,
.
. , -
, ?
*10. Newcastle,
, -
, ".." (
), ?
11. 7 ,
. -
,
? , -
Newcastle ?
*12.
- ?
*13. , ""
link,
, exec, -
. :
.
*14. -
, . -
, , -
398
. , -
-, , -
-. -
, .
+----------+ +----------+ +----------+
| A | | B | | C |
+----------+ +----------+ +----------+
- - - - - -
getty- - - - - - -
- - - - - -
- - - - - -
+-------------------------------------------+ -
| - - - - - - |
+--+----+----------+----+-----------+----+--+
| | | | | |
tty00 tty01 tty02 tty03 tty04 tty05
13.13.
*15. ,
, ,
. , -
"break",
. ,
, -
( 13.13). -
getty-. -
-, ,
.
open , -
, . -
,
"break", , ?
*16. - , . -
, (-
) ,
. .
*17. 9
.
,
?
*18. , ( )
. -
, -
. , -
, .
*19. ,
, .
"/usr/src/uts/3b2/os", "/usr" - , -
A, "/usr/src" - B,
"/usr/src/uts/3b2" - C.
""
(multihop). , A C -
, B -
. ""
Newcastle "" .
399
Last-modified: Thu, 12 Feb 1998 07:20:51 GMT