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
2c8089b4
Unverified
Commit
2c8089b4
authored
Feb 23, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
attach: fix namespace preservation
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
aeadb8f5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
15 deletions
+24
-15
attach.c
src/lxc/attach.c
+24
-15
No files found.
src/lxc/attach.c
View file @
2c8089b4
...
@@ -487,16 +487,16 @@ static int same_nsfd(int dfd_pid1, int dfd_pid2, const char *ns_path)
...
@@ -487,16 +487,16 @@ static int same_nsfd(int dfd_pid1, int dfd_pid2, const char *ns_path)
ret
=
fstatat
(
dfd_pid1
,
ns_path
,
&
ns_st1
,
0
);
ret
=
fstatat
(
dfd_pid1
,
ns_path
,
&
ns_st1
,
0
);
if
(
ret
)
if
(
ret
)
return
-
1
;
return
-
errno
;
ret
=
fstatat
(
dfd_pid2
,
ns_path
,
&
ns_st2
,
0
);
ret
=
fstatat
(
dfd_pid2
,
ns_path
,
&
ns_st2
,
0
);
if
(
ret
)
if
(
ret
)
return
-
1
;
return
-
errno
;
/* processes are in the same namespace */
/* processes are in the same namespace */
if
((
ns_st1
.
st_dev
==
ns_st2
.
st_dev
)
&&
if
((
ns_st1
.
st_dev
==
ns_st2
.
st_dev
)
&&
(
ns_st1
.
st_ino
==
ns_st2
.
st_ino
))
(
ns_st1
.
st_ino
==
ns_st2
.
st_ino
))
return
-
EINVAL
;
return
1
;
return
0
;
return
0
;
}
}
...
@@ -510,19 +510,23 @@ static int same_ns(int dfd_pid1, int dfd_pid2, const char *ns_path)
...
@@ -510,19 +510,23 @@ static int same_ns(int dfd_pid1, int dfd_pid2, const char *ns_path)
(
PROTECT_LOOKUP_BENEATH_WITH_MAGICLINKS
&
(
PROTECT_LOOKUP_BENEATH_WITH_MAGICLINKS
&
~
(
RESOLVE_NO_XDEV
|
RESOLVE_BENEATH
)),
0
);
~
(
RESOLVE_NO_XDEV
|
RESOLVE_BENEATH
)),
0
);
if
(
ns_fd2
<
0
)
{
if
(
ns_fd2
<
0
)
{
/* The kernel does not support this namespace. This is not an error. */
if
(
errno
==
ENOENT
)
if
(
errno
==
ENOENT
)
return
-
ENOENT
;
return
-
ENOENT
;
return
log_error_errno
(
-
errno
,
errno
,
"Failed to open %d(%s)"
,
return
syserrno
(
-
errno
,
"Failed to open %d(%s)"
,
dfd_pid2
,
ns_path
);
dfd_pid2
,
ns_path
);
}
}
ret
=
same_nsfd
(
dfd_pid1
,
dfd_pid2
,
ns_path
);
ret
=
same_nsfd
(
dfd_pid1
,
dfd_pid2
,
ns_path
);
if
(
ret
<
0
)
switch
(
ret
)
{
return
ret
;
case
-
ENOENT
:
__fallthrough
;
case
1
:
return
ret_errno
(
ENOENT
);
case
0
:
/* processes are in different namespaces */
/* processes are in different namespaces */
return
move_fd
(
ns_fd2
);
return
move_fd
(
ns_fd2
);
}
return
ret
;
}
}
static
int
__prepare_namespaces_pidfd
(
struct
attach_context
*
ctx
)
static
int
__prepare_namespaces_pidfd
(
struct
attach_context
*
ctx
)
...
@@ -536,14 +540,19 @@ static int __prepare_namespaces_pidfd(struct attach_context *ctx)
...
@@ -536,14 +540,19 @@ static int __prepare_namespaces_pidfd(struct attach_context *ctx)
ret
=
same_nsfd
(
ctx
->
dfd_self_pid
,
ret
=
same_nsfd
(
ctx
->
dfd_self_pid
,
ctx
->
dfd_init_pid
,
ctx
->
dfd_init_pid
,
ns_info
[
i
].
proc_path
);
ns_info
[
i
].
proc_path
);
if
(
ret
==
-
EINVAL
)
switch
(
ret
)
{
case
-
ENOENT
:
__fallthrough
;
case
1
:
ctx
->
ns_inherited
&=
~
ns_info
[
i
].
clone_flag
;
ctx
->
ns_inherited
&=
~
ns_info
[
i
].
clone_flag
;
else
if
(
ret
<
0
)
break
;
return
log_error_errno
(
-
1
,
errno
,
case
0
:
"Failed to determine whether %s namespace is shared"
,
ns_info
[
i
].
proc_name
);
else
TRACE
(
"Shared %s namespace needs attach"
,
ns_info
[
i
].
proc_name
);
TRACE
(
"Shared %s namespace needs attach"
,
ns_info
[
i
].
proc_name
);
break
;
}
return
syserrno
(
-
errno
,
"Failed to determine whether %s namespace is shared"
,
ns_info
[
i
].
proc_name
);
}
}
return
0
;
return
0
;
...
...
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