Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
6d2990b1
Commit
6d2990b1
authored
8 years ago
by
Eric Cano
Browse files
Options
Downloads
Patches
Plain Diff
Switched posix_spawnp to using vfork instead of fork.
parent
8d57d22f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/Subprocess.cpp
+24
-5
24 additions, 5 deletions
tests/Subprocess.cpp
with
24 additions
and
5 deletions
tests/Subprocess.cpp
+
24
−
5
View file @
6d2990b1
...
...
@@ -28,12 +28,12 @@
#include
<memory>
namespace
{
class
ScopedPosixFileActions
{
class
ScopedPosix
Spawn
FileActions
{
public:
ScopedPosixFileActions
()
{
ScopedPosix
Spawn
FileActions
()
{
::
posix_spawn_file_actions_init
(
&
m_action
);
}
~
ScopedPosixFileActions
()
{
~
ScopedPosix
Spawn
FileActions
()
{
::
posix_spawn_file_actions_destroy
(
&
m_action
);
}
operator
::
posix_spawn_file_actions_t
*
()
{
return
&
m_action
;
}
...
...
@@ -42,6 +42,21 @@ private:
};
}
namespace
{
class
ScopedPosixSpawnAttr
{
public:
ScopedPosixSpawnAttr
()
{
::
posix_spawnattr_init
(
&
m_attr
);
}
~
ScopedPosixSpawnAttr
()
{
::
posix_spawnattr_destroy
(
&
m_attr
);
}
operator
::
posix_spawnattr_t
*
()
{
return
&
m_attr
;
}
private
:
::
posix_spawnattr_t
m_attr
;
};
}
namespace
systemTests
{
Subprocess
::
Subprocess
(
const
std
::
string
&
executable
,
const
std
::
list
<
std
::
string
>&
argv
)
{
// Sanity checks
...
...
@@ -58,7 +73,7 @@ Subprocess::Subprocess(const std::string & executable, const std::list<std::stri
cta
::
exception
::
Errnum
::
throwOnNonZero
(
::
pipe2
(
stderrPipe
,
O_NONBLOCK
),
"In Subprocess::Subprocess failed to create the stderr pipe"
);
// Prepare the actions to be taken on file descriptors
ScopedPosixFileActions
fileActions
;
ScopedPosix
Spawn
FileActions
fileActions
;
// We will be the child process. Close the read sides of the pipes.
cta
::
exception
::
Errnum
::
throwOnReturnedErrno
(
posix_spawn_file_actions_addclose
(
fileActions
,
stdoutPipe
[
readSide
]),
"In Subprocess::Subprocess(): failed to posix_spawn_file_actions_addclose() (1)"
);
...
...
@@ -75,13 +90,17 @@ Subprocess::Subprocess(const std::string & executable, const std::list<std::stri
cta
::
exception
::
Errnum
::
throwOnReturnedErrno
(
posix_spawn_file_actions_addclose
(
fileActions
,
stderrPipe
[
writeSide
]),
"In Subprocess::Subprocess(): failed to posix_spawn_file_actions_addclose() (4)"
);
// And finally spawn the subprocess
// Prepare the spawn attributes (we need vfork)
ScopedPosixSpawnAttr
attr
;
cta
::
exception
::
Errnum
::
throwOnReturnedErrno
(
posix_spawnattr_setflags
(
attr
,
POSIX_SPAWN_USEVFORK
),
"In Subprocess::Subprocess(): failed to posix_spawnattr_setflags()"
);
char
**
cargv
=
new
char
*
[
argv
.
size
()
+
1
];
int
index
=
0
;
for
(
auto
a
=
argv
.
cbegin
();
a
!=
argv
.
cend
();
a
++
)
{
cargv
[
index
++
]
=
::
strdup
(
a
->
c_str
());
}
cargv
[
argv
.
size
()]
=
NULL
;
int
spawnRc
=::
posix_spawnp
(
&
m_child
,
executable
.
c_str
(),
fileActions
,
NULL
,
cargv
,
::
environ
);
int
spawnRc
=::
posix_spawnp
(
&
m_child
,
executable
.
c_str
(),
fileActions
,
attr
,
cargv
,
::
environ
);
cta
::
exception
::
Errnum
::
throwOnReturnedErrno
(
spawnRc
,
"In Subprocess::Subprocess failed to posix_spawn()"
);
// We are the parent process. Close the write sides of pipes.
::
close
(
stdoutPipe
[
writeSide
]);
...
...
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