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
af1893bf
Unverified
Commit
af1893bf
authored
May 09, 2019
by
Stéphane Graber
Committed by
GitHub
May 09, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2906 from brauner/2019-03-12/namespace_switching
utils: improve switch_to_ns()
parents
c6494c4b
b280bc38
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
macro.h
src/lxc/macro.h
+1
-0
utils.c
src/lxc/utils.c
+10
-8
No files found.
src/lxc/macro.h
View file @
af1893bf
...
...
@@ -149,6 +149,7 @@
#define LXC_LINELEN 4096
#define LXC_IDMAPLEN 4096
#define LXC_MAX_BUFFER 4096
#define LXC_NAMESPACE_NAME_MAX 256
/* /proc/ = 6
* +
...
...
src/lxc/utils.c
View file @
af1893bf
...
...
@@ -693,15 +693,18 @@ int detect_shared_rootfs(void)
bool
switch_to_ns
(
pid_t
pid
,
const
char
*
ns
)
{
int
fd
,
ret
;
char
nspath
[
PATH_MAX
];
__do_close_prot_errno
int
fd
=
-
EBADF
;
int
ret
;
char
nspath
[
STRLITERALLEN
(
"/proc//ns/"
)
+
INTTYPE_TO_STRLEN
(
pid_t
)
+
LXC_NAMESPACE_NAME_MAX
];
/* Switch to new ns */
ret
=
snprintf
(
nspath
,
PATH_MAX
,
"/proc/%d/ns/%s"
,
pid
,
ns
);
if
(
ret
<
0
||
ret
>=
PATH_MAX
)
ret
=
snprintf
(
nspath
,
sizeof
(
nspath
)
,
"/proc/%d/ns/%s"
,
pid
,
ns
);
if
(
ret
<
0
||
ret
>=
sizeof
(
nspath
)
)
return
false
;
fd
=
open
(
nspath
,
O_RDONLY
);
fd
=
open
(
nspath
,
O_RDONLY
|
O_CLOEXEC
);
if
(
fd
<
0
)
{
SYSERROR
(
"Failed to open
\"
%s
\"
"
,
nspath
);
return
false
;
...
...
@@ -709,12 +712,11 @@ bool switch_to_ns(pid_t pid, const char *ns)
ret
=
setns
(
fd
,
0
);
if
(
ret
)
{
SYSERROR
(
"Failed to set process %d to
\"
%s
\"
of %d."
,
pid
,
ns
,
fd
);
close
(
fd
);
SYSERROR
(
"Failed to set process %d to
\"
%s
\"
of %d."
,
pid
,
ns
,
fd
);
return
false
;
}
close
(
fd
);
return
true
;
}
...
...
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