Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
5846c3b4
Unverified
Commit
5846c3b4
authored
Sep 13, 2017
by
Christian Brauner
Committed by
Stéphane Graber
Sep 24, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: duplicate stderr as well in lxc_popen()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
19615db8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
7 deletions
+24
-7
utils.c
src/lxc/utils.c
+24
-7
No files found.
src/lxc/utils.c
View file @
5846c3b4
...
...
@@ -472,6 +472,7 @@ const char** lxc_va_arg_list_to_argv_const(va_list ap, size_t skip)
extern
struct
lxc_popen_FILE
*
lxc_popen
(
const
char
*
command
)
{
int
ret
;
struct
lxc_popen_FILE
*
fp
=
NULL
;
int
parent_end
=
-
1
,
child_end
=
-
1
;
int
pipe_fds
[
2
];
...
...
@@ -491,24 +492,40 @@ extern struct lxc_popen_FILE *lxc_popen(const char *command)
if
(
child_pid
==
0
)
{
/* child */
int
child_std_end
=
STDOUT_FILENO
;
close
(
parent_end
);
if
(
child_end
!=
child_std_end
)
{
if
(
child_end
!=
STDOUT_FILENO
)
{
/* dup2() doesn't dup close-on-exec flag */
dup2
(
child_end
,
child_std_end
);
/* it's safe not to close child_end here
* as it's marked close-on-exec anyway
ret
=
dup2
(
child_end
,
STDOUT_FILENO
);
if
(
ret
<
0
)
WARN
(
"Failed to duplicate stdout fd"
);
}
else
{
/*
* The descriptor is already the one we will use.
* But it must not be marked close-on-exec.
* Undo the effects.
*/
ret
=
fcntl
(
child_end
,
F_SETFD
,
0
);
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to remove FD_CLOEXEC from fd."
);
exit
(
127
);
}
}
if
(
child_end
!=
STDERR_FILENO
)
{
/* dup2() doesn't dup close-on-exec flag */
ret
=
dup2
(
child_end
,
STDERR_FILENO
);
if
(
ret
<
0
)
WARN
(
"Failed to duplicate stdout fd"
);
}
else
{
/*
* The descriptor is already the one we will use.
* But it must not be marked close-on-exec.
* Undo the effects.
*/
if
(
fcntl
(
child_end
,
F_SETFD
,
0
)
!=
0
)
{
ret
=
fcntl
(
child_end
,
F_SETFD
,
0
);
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to remove FD_CLOEXEC from fd."
);
exit
(
127
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment