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
5e6e38bd
Unverified
Commit
5e6e38bd
authored
Feb 18, 2019
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rexec: try sendfile() fallback to fd_to_fd()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
cd1372e2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
25 deletions
+29
-25
rexec.c
src/lxc/rexec.c
+29
-25
No files found.
src/lxc/rexec.c
View file @
5e6e38bd
...
...
@@ -105,8 +105,11 @@ static int is_memfd(void)
static
void
lxc_rexec_as_memfd
(
char
**
argv
,
char
**
envp
,
const
char
*
memfd_name
)
{
__do_close_prot_errno
int
fd
=
-
EBADF
,
memfd
=
-
EBADF
,
tmpfd
=
-
EBADF
;
__do_close_prot_errno
int
execfd
=
-
EBADF
,
fd
=
-
EBADF
,
memfd
=
-
EBADF
,
tmpfd
=
-
EBADF
;
int
ret
;
ssize_t
bytes_sent
=
0
;
struct
stat
st
=
{
0
};
memfd
=
memfd_create
(
memfd_name
,
MFD_ALLOW_SEALING
|
MFD_CLOEXEC
);
if
(
memfd
<
0
)
{
...
...
@@ -131,35 +134,35 @@ static void lxc_rexec_as_memfd(char **argv, char **envp, const char *memfd_name)
return
;
/* sendfile() handles up to 2GB. */
if
(
memfd
>=
0
)
{
ssize_t
bytes_sent
=
0
;
struct
stat
st
=
{
0
}
;
ret
=
fstat
(
fd
,
&
st
);
if
(
ret
)
return
;
ret
=
fstat
(
fd
,
&
st
);
if
(
ret
)
return
;
while
(
bytes_sent
<
st
.
st_size
)
{
ssize_t
sent
;
while
(
bytes_sent
<
st
.
st_size
)
{
ssize_t
sent
;
sent
=
lxc_sendfile_nointr
(
memfd
,
fd
,
NULL
,
st
.
st_size
-
bytes_sent
);
if
(
sent
<
0
)
return
;
bytes_sent
+=
sent
;
sent
=
lxc_sendfile_nointr
(
memfd
>=
0
?
memfd
:
tmpfd
,
fd
,
NULL
,
st
.
st_size
-
bytes_sent
);
if
(
sent
<
0
)
{
/* Fallback to shoveling data between kernel- and
* userspace.
*/
lseek
(
fd
,
0
,
SEEK_SET
);
if
(
fd_to_fd
(
fd
,
memfd
>=
0
?
memfd
:
tmpfd
))
break
;
return
;
}
}
else
if
(
fd_to_fd
(
fd
,
tmpfd
))
{
return
;
bytes_sent
+=
sent
;
}
close_prot_errno_disarm
(
fd
);
if
(
memfd
>=
0
&&
fcntl
(
memfd
,
F_ADD_SEALS
,
LXC_MEMFD_REXEC_SEALS
))
return
;
if
(
memfd
>=
0
)
{
fexecve
(
memfd
,
argv
,
envp
);
if
(
fcntl
(
memfd
,
F_ADD_SEALS
,
LXC_MEMFD_REXEC_SEALS
))
return
;
execfd
=
memfd
;
}
else
{
__do_close_prot_errno
int
execfd
=
-
EBADF
;
char
procfd
[
LXC_PROC_PID_FD_LEN
];
ret
=
snprintf
(
procfd
,
sizeof
(
procfd
),
"/proc/self/fd/%d"
,
tmpfd
);
...
...
@@ -168,11 +171,12 @@ static void lxc_rexec_as_memfd(char **argv, char **envp, const char *memfd_name)
execfd
=
open
(
procfd
,
O_PATH
|
O_CLOEXEC
);
close_prot_errno_disarm
(
tmpfd
);
if
(
execfd
<
0
)
return
;
fexecve
(
execfd
,
argv
,
envp
);
}
if
(
execfd
<
0
)
return
;
fexecve
(
execfd
,
argv
,
envp
);
}
/*
...
...
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