This repository has been archived by the owner on Jun 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
10.9 | ||
|
||
mofaph@gmail.com | ||
2013-5-11 | ||
bskim45@gmail.com | ||
2013-12-17 | ||
-------------------------------------------------------------------------------- | ||
|
||
Before the call to execve, the child process opens foo.txt as descriptor 3, redirects stdin to foo.txt, | ||
and then (here is the kicker) closes descriptor 3: | ||
|
||
if (Fork() == 0) { /* Child */ | ||
/* The Shell may be run these code? */ | ||
1. close all the open file descriptor | ||
2. open standard input, and bind it to fd 0 | ||
3. open standard output, and bind it to fd 1 | ||
4. open standard error output, and bind it to fd 2 | ||
fd = Open(‘‘foo.txt’’, O_RDONLY, 0); /* fd == 3 */ | ||
Dup2(fd, STDIN_FILENO); | ||
Close(fd); | ||
Execve("fstatcheck", argv, envp); | ||
} | ||
|
||
When fstatcheck begins running in the child, there are exactly three open files, corresponding to descriptors | ||
0, 1, and 2, with descriptor 1 redirected to foo.txt. |