Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
wims-info
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Nicolas Thiery
wims-info
Commits
ac63271d
Commit
ac63271d
authored
9 years ago
by
Nicolas M. Thiéry
Browse files
Options
Downloads
Patches
Plain Diff
Debarasse de docker_old_exec en gerant la redirection à la main
parent
fb061bee
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
test~coding~readingCppPrograms.fr/docker-compile-and-run.cpp
+43
-15
43 additions, 15 deletions
test~coding~readingCppPrograms.fr/docker-compile-and-run.cpp
with
43 additions
and
15 deletions
test~coding~readingCppPrograms.fr/docker-compile-and-run.cpp
+
43
−
15
View file @
ac63271d
...
...
@@ -4,9 +4,10 @@
#include
<sstream>
using
namespace
std
;
#include
<unistd.h>
#include
<sys/types.h>
#include
<sys/wait.h>
#include
<unistd.h>
#include
<stdio.h>
/**
* TODO:
...
...
@@ -32,9 +33,7 @@ int system(string command) {
std
::
system
(
command
.
c_str
());
}
#include
<stdio.h>
void
exec
(
string
cmd
,
const
vector
<
string
>
args
)
{
int
exec
(
string
cmd
,
const
vector
<
string
>
args
,
const
string
in
,
const
string
out
,
const
string
err
)
{
cerr
<<
"Running (exec): "
+
cmd
;
for
(
auto
arg
:
args
)
cerr
<<
" "
<<
arg
;
...
...
@@ -47,10 +46,45 @@ void exec(string cmd, const vector<string> args) {
const
vector
<
const
char
*>
argv2
(
argv
.
begin
(),
argv
.
end
());
int
pid
=
fork
();
if
(
pid
==
0
)
{
// Taken from man waitpid
int
status
;
pid_t
w
;
pid_t
cpid
=
fork
();
if
(
cpid
==
-
1
)
{
perror
(
"fork"
);
exit
(
EXIT_FAILURE
);
}
if
(
cpid
==
0
)
{
/* Code executed by child */
if
(
in
!=
""
)
{
FILE
*
f
=
fopen
(
in
.
c_str
(),
"r"
);
dup2
(
fileno
(
f
),
STDIN_FILENO
);
fclose
(
f
);
}
execv
(
cmd
.
c_str
(),
(
char
*
const
*
)
argv
.
data
());
}
do
{
// TODO: this could be simplified for our purposes
w
=
waitpid
(
cpid
,
&
status
,
WUNTRACED
|
WCONTINUED
);
if
(
w
==
-
1
)
{
perror
(
"waitpid"
);
exit
(
EXIT_FAILURE
);
}
if
(
WIFEXITED
(
status
))
{
cerr
<<
"exited, status="
<<
WEXITSTATUS
(
status
)
<<
endl
;
}
else
if
(
WIFSIGNALED
(
status
))
{
cerr
<<
"killed by signal="
<<
WTERMSIG
(
status
)
<<
endl
;
}
else
if
(
WIFSTOPPED
(
status
))
{
cerr
<<
"stopped by signal "
<<
WSTOPSIG
(
status
)
<<
endl
;
}
else
if
(
WIFCONTINUED
(
status
))
{
cerr
<<
"continued"
<<
endl
;
}
}
while
(
!
WIFEXITED
(
status
)
&&
!
WIFSIGNALED
(
status
));
return
EXIT_SUCCESS
;
}
int
exec
(
string
cmd
,
const
vector
<
string
>
args
)
{
return
exec
(
cmd
,
args
,
""
,
""
,
""
);
}
std
::
string
pexec
(
const
string
cmd
)
{
...
...
@@ -74,12 +108,6 @@ string docker_run(string container, string command) {
return
ID
;
}
void
docker_oldexec
(
string
docker_id
,
string
command
)
{
string
cmd
=
docker
+
" exec -i "
+
docker_id
+
" "
+
command
;
cerr
<<
"Running (docker_oldexec): "
+
cmd
<<
endl
;
system
(
cmd
);
}
void
docker_exec
(
string
docker_id
,
vector
<
string
>
args
)
{
vector
<
string
>
docker_args
=
{
"exec"
,
"-i"
,
docker_id
};
for
(
auto
arg
:
args
)
...
...
@@ -91,7 +119,8 @@ void docker_exec(string docker_id, vector<string> args) {
void
docker_cp
(
string
docker_id
,
string
source
,
string
target
)
{
// See http://stackoverflow.com/questions/22907231/copying-files-from-host-to-docker-container
// Better replace with 'docker cp' of docker 1.8
docker_oldexec
(
docker_id
,
" /bin/bash -c 'cat > "
+
target
+
"' < "
+
source
);
exec
(
docker
,
{
"exec"
,
"-i"
,
docker_id
,
"/bin/bash"
,
"-c"
,
"cat > "
+
target
,},
source
,
""
,
""
);
}
void
docker_rm
(
string
docker_id
)
{
...
...
@@ -117,7 +146,6 @@ int main(int argc, char **argv) {
docker_cp
(
docker_id
,
program
,
program
);
docker_exec
(
docker_id
,
{
"chmod"
,
"700"
,
compile_and_run
});
docker_exec
(
docker_id
,
{
"./"
+
compile_and_run
,
program
});
//docker_oldexec(docker_id, "./"+compile_and_run+" "+program);
docker_rm
(
docker_id
);
cout
.
flush
();
return
0
;
...
...
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