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
6e48e7c5
Unverified
Commit
6e48e7c5
authored
Jan 29, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync: make all sync helpers return bool
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
2b695e5f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
56 deletions
+46
-56
attach.c
src/lxc/attach.c
+2
-4
start.c
src/lxc/start.c
+10
-20
sync.c
src/lxc/sync.c
+23
-23
sync.h
src/lxc/sync.h
+11
-9
No files found.
src/lxc/attach.c
View file @
6e48e7c5
...
...
@@ -1187,8 +1187,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
}
/* Wait for the parent to have setup cgroups. */
ret
=
sync_wait
(
ipc_sockets
[
1
],
ATTACH_SYNC_CGROUP
);
if
(
ret
)
{
if
(
!
sync_wait
(
ipc_sockets
[
1
],
ATTACH_SYNC_CGROUP
))
{
shutdown
(
ipc_sockets
[
1
],
SHUT_RDWR
);
put_attach_context
(
ctx
);
_exit
(
EXIT_FAILURE
);
...
...
@@ -1333,8 +1332,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
}
/* Let the child process know to go ahead. */
ret
=
sync_wake
(
ipc_sockets
[
0
],
ATTACH_SYNC_CGROUP
);
if
(
ret
)
if
(
!
sync_wake
(
ipc_sockets
[
0
],
ATTACH_SYNC_CGROUP
))
goto
close_mainloop
;
TRACE
(
"Told intermediate process to start initializing"
);
...
...
src/lxc/start.c
View file @
6e48e7c5
...
...
@@ -1069,8 +1069,7 @@ static int do_start(void *data)
/* Don't leak the pinfd to the container. */
close_prot_errno_disarm
(
handler
->
pinfd
);
ret
=
lxc_sync_wait_parent
(
handler
,
START_SYNC_STARTUP
);
if
(
ret
<
0
)
if
(
!
lxc_sync_wait_parent
(
handler
,
START_SYNC_STARTUP
))
goto
out_warn_father
;
/* Unshare CLONE_NEWNET after CLONE_NEWUSER. See
...
...
@@ -1088,8 +1087,7 @@ static int do_start(void *data)
/* Tell the parent task it can begin to configure the container and wait
* for it to finish.
*/
ret
=
lxc_sync_barrier_parent
(
handler
,
START_SYNC_CONFIGURE
);
if
(
ret
<
0
)
if
(
!
lxc_sync_barrier_parent
(
handler
,
START_SYNC_CONFIGURE
))
goto
out_error
;
if
(
handler
->
ns_clone_flags
&
CLONE_NEWNET
)
{
...
...
@@ -1168,8 +1166,7 @@ static int do_start(void *data)
}
/* Ask father to setup cgroups and wait for him to finish. */
ret
=
lxc_sync_barrier_parent
(
handler
,
START_SYNC_CGROUP
);
if
(
ret
<
0
)
if
(
!
lxc_sync_barrier_parent
(
handler
,
START_SYNC_CGROUP
))
goto
out_error
;
/* Unshare cgroup namespace after we have setup our cgroups. If we do it
...
...
@@ -1353,8 +1350,7 @@ static int do_start(void *data)
}
}
ret
=
lxc_sync_barrier_parent
(
handler
,
START_SYNC_CGROUP_LIMITS
);
if
(
ret
<
0
)
if
(
!
lxc_sync_barrier_parent
(
handler
,
START_SYNC_CGROUP_LIMITS
))
goto
out_warn_father
;
/* Reset the environment variables the user requested in a clear
...
...
@@ -1630,8 +1626,7 @@ static int lxc_spawn(struct lxc_handler *handler)
share_ns
=
true
;
}
ret
=
lxc_sync_init
(
handler
);
if
(
ret
<
0
)
if
(
!
lxc_sync_init
(
handler
))
return
-
1
;
ret
=
socketpair
(
AF_UNIX
,
SOCK_STREAM
|
SOCK_CLOEXEC
,
0
,
...
...
@@ -1790,12 +1785,10 @@ static int lxc_spawn(struct lxc_handler *handler)
}
}
ret
=
lxc_sync_wake_child
(
handler
,
START_SYNC_STARTUP
);
if
(
ret
<
0
)
if
(
!
lxc_sync_wake_child
(
handler
,
START_SYNC_STARTUP
))
goto
out_delete_net
;
ret
=
lxc_sync_wait_child
(
handler
,
START_SYNC_CONFIGURE
);
if
(
ret
<
0
)
if
(
!
lxc_sync_wait_child
(
handler
,
START_SYNC_CONFIGURE
))
goto
out_delete_net
;
if
(
!
cgroup_ops
->
setup_limits_legacy
(
cgroup_ops
,
handler
->
conf
,
false
))
{
...
...
@@ -1864,8 +1857,7 @@ static int lxc_spawn(struct lxc_handler *handler)
/* Tell the child to continue its initialization. We'll get
* START_SYNC_CGROUP when it is ready for us to setup cgroups.
*/
ret
=
lxc_sync_barrier_child
(
handler
,
START_SYNC_POST_CONFIGURE
);
if
(
ret
<
0
)
if
(
!
lxc_sync_barrier_child
(
handler
,
START_SYNC_POST_CONFIGURE
))
goto
out_delete_net
;
if
(
!
lxc_list_empty
(
&
conf
->
limits
))
{
...
...
@@ -1876,8 +1868,7 @@ static int lxc_spawn(struct lxc_handler *handler)
}
}
ret
=
lxc_sync_barrier_child
(
handler
,
START_SYNC_CGROUP_UNSHARE
);
if
(
ret
<
0
)
if
(
!
lxc_sync_barrier_child
(
handler
,
START_SYNC_CGROUP_UNSHARE
))
goto
out_delete_net
;
/*
...
...
@@ -1941,8 +1932,7 @@ static int lxc_spawn(struct lxc_handler *handler)
* lxc_sync_barrier_child to return success, or return a different
* value, causing us to error out).
*/
ret
=
lxc_sync_barrier_child
(
handler
,
START_SYNC_READY_START
);
if
(
ret
<
0
)
if
(
!
lxc_sync_barrier_child
(
handler
,
START_SYNC_READY_START
))
goto
out_delete_net
;
if
(
handler
->
ns_clone_flags
&
CLONE_NEWNET
)
{
...
...
src/lxc/sync.c
View file @
6e48e7c5
...
...
@@ -17,44 +17,44 @@
lxc_log_define
(
sync
,
lxc
);
int
sync_wait
(
int
fd
,
int
sequence
)
bool
sync_wait
(
int
fd
,
int
sequence
)
{
int
sync
=
-
1
;
ssize_t
ret
;
ret
=
lxc_read_nointr
(
fd
,
&
sync
,
sizeof
(
sync
));
if
(
ret
<
0
)
return
log_error_errno
(
-
1
,
errno
,
"Sync wait failure"
);
return
log_error_errno
(
false
,
errno
,
"Sync wait failure"
);
if
(
!
ret
)
return
0
;
return
true
;
if
((
size_t
)
ret
!=
sizeof
(
sync
))
return
log_error
(
-
1
,
"Unexpected sync size: %zu expected %zu"
,
(
size_t
)
ret
,
sizeof
(
sync
));
return
log_error
(
false
,
"Unexpected sync size: %zu expected %zu"
,
(
size_t
)
ret
,
sizeof
(
sync
));
if
(
sync
==
SYNC_ERROR
)
return
log_error
(
-
1
,
"An error occurred in another process (expected sequence number %d)"
,
sequence
);
return
log_error
(
false
,
"An error occurred in another process (expected sequence number %d)"
,
sequence
);
if
(
sync
!=
sequence
)
return
log_error
(
-
1
,
"Invalid sequence number %d. Expected sequence number %d"
,
sync
,
sequence
);
return
log_error
(
false
,
"Invalid sequence number %d. Expected sequence number %d"
,
sync
,
sequence
);
return
0
;
return
true
;
}
int
sync_wake
(
int
fd
,
int
sequence
)
bool
sync_wake
(
int
fd
,
int
sequence
)
{
int
sync
=
sequence
;
if
(
lxc_write_nointr
(
fd
,
&
sync
,
sizeof
(
sync
))
<
0
)
return
log_error_errno
(
-
1
,
errno
,
"Sync wake failure"
);
return
log_error_errno
(
false
,
errno
,
"Sync wake failure"
);
return
0
;
return
true
;
}
static
int
__sync_barrier
(
int
fd
,
int
sequence
)
static
bool
__sync_barrier
(
int
fd
,
int
sequence
)
{
if
(
sync_wake
(
fd
,
sequence
))
return
-
1
;
if
(
!
sync_wake
(
fd
,
sequence
))
return
false
;
return
sync_wait
(
fd
,
sequence
+
1
);
}
...
...
@@ -87,59 +87,59 @@ static inline const char *start_sync_to_string(int state)
}
}
int
lxc_sync_barrier_parent
(
struct
lxc_handler
*
handler
,
int
sequence
)
bool
lxc_sync_barrier_parent
(
struct
lxc_handler
*
handler
,
int
sequence
)
{
TRACE
(
"Child waking parent with sequence %s and waiting for sequence %s"
,
start_sync_to_string
(
sequence
),
start_sync_to_string
(
sequence
+
1
));
return
__sync_barrier
(
handler
->
sync_sock
[
0
],
sequence
);
}
int
lxc_sync_barrier_child
(
struct
lxc_handler
*
handler
,
int
sequence
)
bool
lxc_sync_barrier_child
(
struct
lxc_handler
*
handler
,
int
sequence
)
{
TRACE
(
"Parent waking child with sequence %s and waiting with sequence %s"
,
start_sync_to_string
(
sequence
),
start_sync_to_string
(
sequence
+
1
));
return
__sync_barrier
(
handler
->
sync_sock
[
1
],
sequence
);
}
int
lxc_sync_wake_parent
(
struct
lxc_handler
*
handler
,
int
sequence
)
bool
lxc_sync_wake_parent
(
struct
lxc_handler
*
handler
,
int
sequence
)
{
TRACE
(
"Child waking parent with sequence %s"
,
start_sync_to_string
(
sequence
));
return
sync_wake
(
handler
->
sync_sock
[
0
],
sequence
);
}
int
lxc_sync_wait_parent
(
struct
lxc_handler
*
handler
,
int
sequence
)
bool
lxc_sync_wait_parent
(
struct
lxc_handler
*
handler
,
int
sequence
)
{
TRACE
(
"Parent waiting for child with sequence %s"
,
start_sync_to_string
(
sequence
));
return
sync_wait
(
handler
->
sync_sock
[
0
],
sequence
);
}
int
lxc_sync_wait_child
(
struct
lxc_handler
*
handler
,
int
sequence
)
bool
lxc_sync_wait_child
(
struct
lxc_handler
*
handler
,
int
sequence
)
{
TRACE
(
"Child waiting for parent with sequence %s"
,
start_sync_to_string
(
sequence
));
return
sync_wait
(
handler
->
sync_sock
[
1
],
sequence
);
}
int
lxc_sync_wake_child
(
struct
lxc_handler
*
handler
,
int
sequence
)
bool
lxc_sync_wake_child
(
struct
lxc_handler
*
handler
,
int
sequence
)
{
TRACE
(
"Child waking parent with sequence %s"
,
start_sync_to_string
(
sequence
));
return
sync_wake
(
handler
->
sync_sock
[
1
],
sequence
);
}
int
lxc_sync_init
(
struct
lxc_handler
*
handler
)
bool
lxc_sync_init
(
struct
lxc_handler
*
handler
)
{
int
ret
;
ret
=
socketpair
(
AF_LOCAL
,
SOCK_STREAM
,
0
,
handler
->
sync_sock
);
if
(
ret
)
return
log_error_errno
(
-
1
,
errno
,
"failed to create synchronization socketpair"
);
return
log_error_errno
(
false
,
errno
,
"failed to create synchronization socketpair"
);
/* Be sure we don't inherit this after the exec */
ret
=
fcntl
(
handler
->
sync_sock
[
0
],
F_SETFD
,
FD_CLOEXEC
);
if
(
ret
<
0
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to make socket close-on-exec"
);
return
log_error_errno
(
false
,
errno
,
"Failed to make socket close-on-exec"
);
TRACE
(
"Initialized synchronization infrastructure"
);
return
0
;
return
true
;
}
void
lxc_sync_fini_child
(
struct
lxc_handler
*
handler
)
...
...
src/lxc/sync.h
View file @
6e48e7c5
...
...
@@ -3,6 +3,8 @@
#ifndef __LXC_SYNC_H
#define __LXC_SYNC_H
#include <stdbool.h>
#include "compiler.h"
struct
lxc_handler
;
...
...
@@ -27,17 +29,17 @@ enum /* attach */ {
ATTACH_SYNC_CGROUP
=
0
,
};
__hidden
extern
int
lxc_sync_init
(
struct
lxc_handler
*
handler
);
__hidden
extern
bool
lxc_sync_init
(
struct
lxc_handler
*
handler
);
__hidden
extern
void
lxc_sync_fini
(
struct
lxc_handler
*
);
__hidden
extern
void
lxc_sync_fini_parent
(
struct
lxc_handler
*
);
__hidden
extern
void
lxc_sync_fini_child
(
struct
lxc_handler
*
);
__hidden
extern
int
lxc_sync_wake_child
(
struct
lxc_handler
*
,
int
);
__hidden
extern
int
lxc_sync_wait_child
(
struct
lxc_handler
*
,
int
);
__hidden
extern
int
lxc_sync_wake_parent
(
struct
lxc_handler
*
,
int
);
__hidden
extern
int
lxc_sync_wait_parent
(
struct
lxc_handler
*
,
int
);
__hidden
extern
int
lxc_sync_barrier_parent
(
struct
lxc_handler
*
,
int
);
__hidden
extern
int
lxc_sync_barrier_child
(
struct
lxc_handler
*
,
int
);
__hidden
extern
int
sync_wait
(
int
fd
,
int
sequence
);
__hidden
extern
int
sync_wake
(
int
fd
,
int
sequence
);
__hidden
extern
bool
lxc_sync_wake_child
(
struct
lxc_handler
*
,
int
);
__hidden
extern
bool
lxc_sync_wait_child
(
struct
lxc_handler
*
,
int
);
__hidden
extern
bool
lxc_sync_wake_parent
(
struct
lxc_handler
*
,
int
);
__hidden
extern
bool
lxc_sync_wait_parent
(
struct
lxc_handler
*
,
int
);
__hidden
extern
bool
lxc_sync_barrier_parent
(
struct
lxc_handler
*
,
int
);
__hidden
extern
bool
lxc_sync_barrier_child
(
struct
lxc_handler
*
,
int
);
__hidden
extern
bool
sync_wait
(
int
fd
,
int
sequence
);
__hidden
extern
bool
sync_wake
(
int
fd
,
int
sequence
);
#endif
/* __LXC_SYNC_H */
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