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
0c2a98bd
Unverified
Commit
0c2a98bd
authored
Dec 15, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
namespace: add lxc_raw_clone_cb()
This is a copy-on-write (no stack passed) variant of lxc_clone(). Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
718dbb8c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
1 deletion
+31
-1
namespace.c
src/lxc/namespace.c
+17
-0
namespace.h
src/lxc/namespace.h
+14
-1
No files found.
src/lxc/namespace.c
View file @
0c2a98bd
...
@@ -127,6 +127,23 @@ pid_t lxc_raw_clone(unsigned long flags)
...
@@ -127,6 +127,23 @@ pid_t lxc_raw_clone(unsigned long flags)
#endif
#endif
}
}
pid_t
lxc_raw_clone_cb
(
int
(
*
fn
)(
void
*
),
void
*
args
,
unsigned
long
flags
)
{
pid_t
pid
;
pid
=
lxc_raw_clone
(
flags
);
if
(
pid
<
0
)
return
-
1
;
/* exit() is not thread-safe and might mess with the parent's signal
* handlers and other stuff when exec() fails.
*/
if
(
pid
==
0
)
_exit
(
fn
(
args
));
return
pid
;
}
/* Leave the user namespace at the first position in the array of structs so
/* Leave the user namespace at the first position in the array of structs so
* that we always attach to it first when iterating over the struct and using
* that we always attach to it first when iterating over the struct and using
* setns() to switch namespaces. This especially affects lxc_attach(): Suppose
* setns() to switch namespaces. This especially affects lxc_attach(): Suppose
...
...
src/lxc/namespace.h
View file @
0c2a98bd
...
@@ -130,7 +130,7 @@ int clone(int (*fn)(void *), void *child_stack,
...
@@ -130,7 +130,7 @@ int clone(int (*fn)(void *), void *child_stack,
* corresponding libc wrapper. glibc currently does not run pthread_atfork()
* corresponding libc wrapper. glibc currently does not run pthread_atfork()
* handlers but does not guarantee that they are not. Other libcs might or
* handlers but does not guarantee that they are not. Other libcs might or
* might not run pthread_atfork() handlers. If you require guarantees please
* might not run pthread_atfork() handlers. If you require guarantees please
* refer to the lxc_raw_clone
() function
below.
* refer to the lxc_raw_clone
*() functions
below.
*
*
* - should call lxc_raw_getpid():
* - should call lxc_raw_getpid():
* The child should use lxc_raw_getpid() to retrieve its pid.
* The child should use lxc_raw_getpid() to retrieve its pid.
...
@@ -165,6 +165,19 @@ extern pid_t lxc_clone(int (*fn)(void *), void *arg, int flags);
...
@@ -165,6 +165,19 @@ extern pid_t lxc_clone(int (*fn)(void *), void *arg, int flags);
* The child must use lxc_raw_getpid() to retrieve its pid.
* The child must use lxc_raw_getpid() to retrieve its pid.
*/
*/
extern
pid_t
lxc_raw_clone
(
unsigned
long
flags
);
extern
pid_t
lxc_raw_clone
(
unsigned
long
flags
);
/**
* lxc_raw_clone_cb() - create a new process
*
* - non-fork() behavior:
* Function does return pid of the child or -1 on error. Pass in a callback
* function via the "fn" argument that gets executed in the child process. The
* "args" argument is passed to "fn".
*
* All other comments that apply to lxc_raw_clone() apply to lxc_raw_clone_cb()
* as well.
*/
extern
pid_t
lxc_raw_clone_cb
(
int
(
*
fn
)(
void
*
),
void
*
args
,
unsigned
long
flags
);
extern
int
lxc_namespace_2_cloneflag
(
const
char
*
namespace
);
extern
int
lxc_namespace_2_cloneflag
(
const
char
*
namespace
);
extern
int
lxc_namespace_2_ns_idx
(
const
char
*
namespace
);
extern
int
lxc_namespace_2_ns_idx
(
const
char
*
namespace
);
...
...
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