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
7ebcd704
Unverified
Commit
7ebcd704
authored
May 15, 2020
by
Christian Brauner
Committed by
Stéphane Graber
May 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
process_utils: make lxc use clone3() whenever possible
No more weird api quirks between architectures and cool new features. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
0842a465
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
26 deletions
+37
-26
configure.ac
configure.ac
+0
-1
process_utils.c
src/lxc/process_utils.c
+26
-9
process_utils.h
src/lxc/process_utils.h
+11
-16
No files found.
configure.ac
View file @
7ebcd704
...
@@ -623,7 +623,6 @@ AC_HEADER_MAJOR
...
@@ -623,7 +623,6 @@ AC_HEADER_MAJOR
# Check for some syscalls functions
# Check for some syscalls functions
AC_CHECK_FUNCS([setns pivot_root sethostname unshare rand_r confstr faccessat gettid memfd_create move_mount open_tree execveat clone3])
AC_CHECK_FUNCS([setns pivot_root sethostname unshare rand_r confstr faccessat gettid memfd_create move_mount open_tree execveat clone3])
# HAVE_STRUCT_CLONE_ARGS={0,1}
AC_CHECK_TYPES([struct clone_args], [], [], [[#include <linux/sched.h>]])
AC_CHECK_TYPES([struct clone_args], [], [], [[#include <linux/sched.h>]])
AC_CHECK_MEMBERS([struct clone_args.set_tid],[],[],[[#include <linux/sched.h>]])
AC_CHECK_MEMBERS([struct clone_args.set_tid],[],[],[[#include <linux/sched.h>]])
AC_CHECK_MEMBERS([struct clone_args.cgroup],[],[],[[#include <linux/sched.h>]])
AC_CHECK_MEMBERS([struct clone_args.cgroup],[],[],[[#include <linux/sched.h>]])
...
...
src/lxc/process_utils.c
View file @
7ebcd704
...
@@ -28,16 +28,8 @@ lxc_log_define(process_utils, lxc);
...
@@ -28,16 +28,8 @@ lxc_log_define(process_utils, lxc);
* The nice thing about this is that we get fork() behavior. That is
* The nice thing about this is that we get fork() behavior. That is
* lxc_raw_clone() returns 0 in the child and the child pid in the parent.
* lxc_raw_clone() returns 0 in the child and the child pid in the parent.
*/
*/
__returns_twice
pid_t
lxc_raw_clone
(
unsigned
long
flags
,
int
*
pidfd
)
__returns_twice
static
pid_t
__
lxc_raw_clone
(
unsigned
long
flags
,
int
*
pidfd
)
{
{
/*
* These flags don't interest at all so we don't jump through any hoops
* of retrieving them and passing them to the kernel.
*/
errno
=
EINVAL
;
if
((
flags
&
(
CLONE_VM
|
CLONE_PARENT_SETTID
|
CLONE_CHILD_SETTID
|
CLONE_CHILD_CLEARTID
|
CLONE_SETTLS
)))
return
-
EINVAL
;
#if defined(__s390x__) || defined(__s390__) || defined(__CRIS__)
#if defined(__s390x__) || defined(__s390__) || defined(__CRIS__)
/* On s390/s390x and cris the order of the first and second arguments
/* On s390/s390x and cris the order of the first and second arguments
...
@@ -97,6 +89,31 @@ __returns_twice pid_t lxc_raw_clone(unsigned long flags, int *pidfd)
...
@@ -97,6 +89,31 @@ __returns_twice pid_t lxc_raw_clone(unsigned long flags, int *pidfd)
#endif
#endif
}
}
__returns_twice
pid_t
lxc_raw_clone
(
unsigned
long
flags
,
int
*
pidfd
)
{
pid_t
pid
;
struct
lxc_clone_args
args
=
{
.
flags
=
flags
,
.
pidfd
=
ptr_to_u64
(
pidfd
),
};
if
(
flags
&
(
CLONE_VM
|
CLONE_PARENT_SETTID
|
CLONE_CHILD_SETTID
|
CLONE_CHILD_CLEARTID
|
CLONE_SETTLS
))
return
ret_errno
(
EINVAL
);
/* On CLONE_PARENT we inherit the parent's exit signal. */
if
(
!
(
flags
&
CLONE_PARENT
))
args
.
exit_signal
=
SIGCHLD
;
pid
=
lxc_clone3
(
&
args
,
CLONE_ARGS_SIZE_VER0
);
if
(
pid
<
0
&&
errno
==
ENOSYS
)
{
SYSTRACE
(
"Falling back to legacy clone"
);
return
__lxc_raw_clone
(
flags
,
pidfd
);
}
return
pid
;
}
pid_t
lxc_raw_clone_cb
(
int
(
*
fn
)(
void
*
),
void
*
args
,
unsigned
long
flags
,
pid_t
lxc_raw_clone_cb
(
int
(
*
fn
)(
void
*
),
void
*
args
,
unsigned
long
flags
,
int
*
pidfd
)
int
*
pidfd
)
{
{
...
...
src/lxc/process_utils.h
View file @
7ebcd704
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#include <sys/syscall.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <unistd.h>
#include "compiler.h"
#include "config.h"
#include "config.h"
#include "syscall_numbers.h"
#include "syscall_numbers.h"
...
@@ -152,8 +153,14 @@
...
@@ -152,8 +153,14 @@
#define CLONE_ARGS_SIZE_VER2 88
/* sizeof third published struct */
#define CLONE_ARGS_SIZE_VER2 88
/* sizeof third published struct */
#endif
#endif
#ifndef HAVE_STRUCT_CLONE_ARGS
#ifndef ptr_to_u64
struct
clone_args
{
#define ptr_to_u64(ptr) ((__u64)((uintptr_t)(ptr)))
#endif
#ifndef u64_to_ptr
#define u64_to_ptr(x) ((void *)(uintptr_t)x)
#endif
struct
lxc_clone_args
{
__aligned_u64
flags
;
__aligned_u64
flags
;
__aligned_u64
pidfd
;
__aligned_u64
pidfd
;
__aligned_u64
child_tid
;
__aligned_u64
child_tid
;
...
@@ -166,22 +173,10 @@ struct clone_args {
...
@@ -166,22 +173,10 @@ struct clone_args {
__aligned_u64
set_tid_size
;
__aligned_u64
set_tid_size
;
__aligned_u64
cgroup
;
__aligned_u64
cgroup
;
};
};
#endif
struct
lxc_clone_args
{
struct
clone_args
;
#ifndef HAVE_STRUCT_CLONE_ARGS_SET_TID
__aligned_u64
set_tid
;
__aligned_u64
set_tid_size
;
#endif
#ifndef HAVE_STRUCT_CLONE_ARGS_CGROUP
__aligned_u64
cgroup
;
#endif
};
static
inline
pid_t
lxc_clone3
(
struct
lxc_clone_args
*
args
,
size_t
size
)
__returns_twice
static
inline
pid_t
lxc_clone3
(
struct
lxc_clone_args
*
args
,
size_t
size
)
{
{
return
syscall
(
__NR_clone3
,
(
struct
clone_args
*
)
args
,
size
);
return
syscall
(
__NR_clone3
,
args
,
size
);
}
}
#if defined(__ia64__)
#if defined(__ia64__)
...
...
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