Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Googletest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Meng
Googletest
Commits
1e315c5b
Commit
1e315c5b
authored
4 years ago
by
vslashg
Browse files
Options
Downloads
Plain Diff
Merge pull request #2895 from lantw44:wip/lantw/Avoid-using-environ-on-FreeBSD
PiperOrigin-RevId: 327799934
parents
ec9be15b
2e8ebe69
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
googletest/src/gtest-death-test.cc
+8
-21
8 additions, 21 deletions
googletest/src/gtest-death-test.cc
with
8 additions
and
21 deletions
googletest/src/gtest-death-test.cc
+
8
−
21
View file @
1e315c5b
...
...
@@ -1225,21 +1225,9 @@ struct ExecDeathTestArgs {
int
close_fd
;
// File descriptor to close; the read end of a pipe
};
# if GTEST_OS_MAC
inline
char
**
GetEnviron
()
{
// When Google Test is built as a framework on MacOS X, the environ variable
// is unavailable. Apple's documentation (man environ) recommends using
// _NSGetEnviron() instead.
return
*
_NSGetEnviron
();
}
# else
// Some POSIX platforms expect you to declare environ. extern "C" makes
// it reside in the global namespace.
# if GTEST_OS_QNX
extern
"C"
char
**
environ
;
inline
char
**
GetEnviron
()
{
return
environ
;
}
# endif // GTEST_OS_MAC
# if !GTEST_OS_QNX
# else // GTEST_OS_QNX
// The main function for a threadsafe-style death test child process.
// This function is called in a clone()-ed process and thus must avoid
// any potentially unsafe operations like malloc or libc functions.
...
...
@@ -1259,18 +1247,18 @@ static int ExecDeathTestChildMain(void* child_arg) {
return
EXIT_FAILURE
;
}
// We can safely call execv
e
() as it's a direct system call.
We
// We can safely call execv() as it's
almost
a direct system call. We
// cannot use execvp() as it's a libc function and thus potentially
// unsafe. Since execv
e
() doesn't search the PATH, the user must
// unsafe. Since execv() doesn't search the PATH, the user must
// invoke the test program via a valid path that contains at least
// one path separator.
execv
e
(
args
->
argv
[
0
],
args
->
argv
,
GetEnviron
()
);
DeathTestAbort
(
std
::
string
(
"execv
e
("
)
+
args
->
argv
[
0
]
+
", ...) in "
+
execv
(
args
->
argv
[
0
],
args
->
argv
);
DeathTestAbort
(
std
::
string
(
"execv("
)
+
args
->
argv
[
0
]
+
", ...) in "
+
original_dir
+
" failed: "
+
GetLastErrnoDescription
());
return
EXIT_FAILURE
;
}
# endif //
!
GTEST_OS_QNX
# endif // GTEST_OS_QNX
# if GTEST_HAS_CLONE
// Two utility routines that together determine the direction the stack
...
...
@@ -1344,8 +1332,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
fd_flags
|
FD_CLOEXEC
));
struct
inheritance
inherit
=
{
0
};
// spawn is a system call.
child_pid
=
spawn
(
args
.
argv
[
0
],
0
,
nullptr
,
&
inherit
,
args
.
argv
,
GetEnviron
());
child_pid
=
spawn
(
args
.
argv
[
0
],
0
,
nullptr
,
&
inherit
,
args
.
argv
,
environ
);
// Restores the current working directory.
GTEST_DEATH_TEST_CHECK_
(
fchdir
(
cwd_fd
)
!=
-
1
);
GTEST_DEATH_TEST_CHECK_SYSCALL_
(
close
(
cwd_fd
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment