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
6f0c2cea
Unverified
Commit
6f0c2cea
authored
Feb 01, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
attach: file descriptor based fdinfo handling
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
8e5d1759
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
15 deletions
+13
-15
attach.c
src/lxc/attach.c
+13
-15
No files found.
src/lxc/attach.c
View file @
6f0c2cea
...
@@ -104,24 +104,22 @@ struct attach_context {
...
@@ -104,24 +104,22 @@ struct attach_context {
struct
lsm_ops
*
lsm_ops
;
struct
lsm_ops
*
lsm_ops
;
};
};
static
pid_t
pidfd_get_pid
(
int
pidfd
)
static
pid_t
pidfd_get_pid
(
int
dfd_init_pid
,
int
pidfd
)
{
{
__do_free
char
*
line
=
NULL
;
__do_free
char
*
line
=
NULL
;
__do_fclose
FILE
*
f
=
NULL
;
__do_fclose
FILE
*
f
=
NULL
;
size_t
len
=
0
;
size_t
len
=
0
;
char
path
[
STRLITERALLEN
(
"/proc/self/fdinfo/"
)
+
char
path
[
STRLITERALLEN
(
"fdinfo/"
)
+
INTTYPE_TO_STRLEN
(
int
)
+
1
]
=
"fdinfo/"
;
INTTYPE_TO_STRLEN
(
int
)
+
1
]
=
"/proc/self/fdinfo/"
;
int
ret
;
int
ret
;
if
(
pidfd
<
0
)
if
(
dfd_init_pid
<
0
||
pidfd
<
0
)
return
-
EBADF
;
return
ret_errno
(
EBADF
)
;
ret
=
snprintf
(
path
+
STRLITERALLEN
(
"/proc/self/fdinfo/"
),
ret
=
snprintf
(
path
+
STRLITERALLEN
(
"fdinfo/"
),
INTTYPE_TO_STRLEN
(
int
),
"%d"
,
pidfd
);
INTTYPE_TO_STRLEN
(
int
),
"%d"
,
pidfd
);
if
(
ret
<
0
||
ret
>
(
size_t
)
INTTYPE_TO_STRLEN
(
int
))
if
(
ret
<
0
||
ret
>
(
size_t
)
INTTYPE_TO_STRLEN
(
int
))
return
ret_errno
(
EIO
);
return
ret_errno
(
EIO
);
f
=
f
open_cloexec
(
path
,
"re"
);
f
=
f
dopen_at
(
dfd_init_pid
,
path
,
"re"
,
PROTECT_OPEN
,
PROTECT_LOOKUP_BENEATH
);
if
(
!
f
)
if
(
!
f
)
return
-
errno
;
return
-
errno
;
...
@@ -380,21 +378,21 @@ static int get_attach_context(struct attach_context *ctx,
...
@@ -380,21 +378,21 @@ static int get_attach_context(struct attach_context *ctx,
ctx
->
container
=
container
;
ctx
->
container
=
container
;
ctx
->
attach_flags
=
options
->
attach_flags
;
ctx
->
attach_flags
=
options
->
attach_flags
;
ctx
->
dfd_self_pid
=
open_at
(
-
EBADF
,
"/proc/self"
,
PROTECT_OPATH_FILE
&
~
O_NOFOLLOW
,
(
PROTECT_LOOKUP_ABSOLUTE_WITH_SYMLINKS
&
~
RESOLVE_NO_XDEV
),
0
);
if
(
ctx
->
dfd_self_pid
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to open /proc/self"
);
init_pidfd
=
lxc_cmd_get_init_pidfd
(
container
->
name
,
container
->
config_path
);
init_pidfd
=
lxc_cmd_get_init_pidfd
(
container
->
name
,
container
->
config_path
);
if
(
init_pidfd
>=
0
)
if
(
init_pidfd
>=
0
)
ctx
->
init_pid
=
pidfd_get_pid
(
init_pidfd
);
ctx
->
init_pid
=
pidfd_get_pid
(
ctx
->
dfd_self_pid
,
init_pidfd
);
else
else
ctx
->
init_pid
=
lxc_cmd_get_init_pid
(
container
->
name
,
container
->
config_path
);
ctx
->
init_pid
=
lxc_cmd_get_init_pid
(
container
->
name
,
container
->
config_path
);
if
(
ctx
->
init_pid
<
0
)
if
(
ctx
->
init_pid
<
0
)
return
log_error
(
-
1
,
"Failed to get init pid"
);
return
log_error
(
-
1
,
"Failed to get init pid"
);
ctx
->
dfd_self_pid
=
open_at
(
-
EBADF
,
"/proc/self"
,
PROTECT_OPATH_FILE
&
~
O_NOFOLLOW
,
(
PROTECT_LOOKUP_ABSOLUTE_WITH_SYMLINKS
&
~
RESOLVE_NO_XDEV
),
0
);
if
(
ctx
->
dfd_self_pid
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to open /proc/self"
);
ret
=
snprintf
(
path
,
sizeof
(
path
),
"/proc/%d"
,
ctx
->
init_pid
);
ret
=
snprintf
(
path
,
sizeof
(
path
),
"/proc/%d"
,
ctx
->
init_pid
);
if
(
ret
<
0
||
ret
>=
sizeof
(
path
))
if
(
ret
<
0
||
ret
>=
sizeof
(
path
))
return
ret_errno
(
EIO
);
return
ret_errno
(
EIO
);
...
...
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