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
80308d07
Unverified
Commit
80308d07
authored
May 29, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start: add reboot macros
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
5c478fb5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
17 deletions
+24
-17
lxccontainer.c
src/lxc/lxccontainer.c
+4
-4
start.c
src/lxc/start.c
+14
-13
state.h
src/lxc/state.h
+6
-0
No files found.
src/lxc/lxccontainer.c
View file @
80308d07
...
@@ -1036,7 +1036,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
...
@@ -1036,7 +1036,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
}
}
}
}
conf
->
reboot
=
0
;
conf
->
reboot
=
REBOOT_NONE
;
/* Unshare the mount namespace if requested */
/* Unshare the mount namespace if requested */
if
(
conf
->
monitor_unshare
)
{
if
(
conf
->
monitor_unshare
)
{
...
@@ -1058,7 +1058,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
...
@@ -1058,7 +1058,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
}
}
reboot
:
reboot
:
if
(
conf
->
reboot
==
2
)
{
if
(
conf
->
reboot
==
REBOOT_INIT
)
{
/* initialize handler */
/* initialize handler */
handler
=
lxc_init_handler
(
c
->
name
,
conf
,
c
->
config_path
,
c
->
daemonize
);
handler
=
lxc_init_handler
(
c
->
name
,
conf
,
c
->
config_path
,
c
->
daemonize
);
if
(
!
handler
)
{
if
(
!
handler
)
{
...
@@ -1085,9 +1085,9 @@ reboot:
...
@@ -1085,9 +1085,9 @@ reboot:
ret
=
lxc_start
(
c
->
name
,
argv
,
handler
,
c
->
config_path
,
ret
=
lxc_start
(
c
->
name
,
argv
,
handler
,
c
->
config_path
,
c
->
daemonize
,
&
c
->
error_num
);
c
->
daemonize
,
&
c
->
error_num
);
if
(
conf
->
reboot
==
1
)
{
if
(
conf
->
reboot
==
REBOOT_REQ
)
{
INFO
(
"Container requested reboot"
);
INFO
(
"Container requested reboot"
);
conf
->
reboot
=
2
;
conf
->
reboot
=
REBOOT_INIT
;
goto
reboot
;
goto
reboot
;
}
}
...
...
src/lxc/start.c
View file @
80308d07
...
@@ -646,7 +646,7 @@ void lxc_free_handler(struct lxc_handler *handler)
...
@@ -646,7 +646,7 @@ void lxc_free_handler(struct lxc_handler *handler)
lxc_put_nsfds
(
handler
);
lxc_put_nsfds
(
handler
);
if
(
handler
->
conf
&&
handler
->
conf
->
reboot
==
0
)
if
(
handler
->
conf
&&
handler
->
conf
->
reboot
==
REBOOT_NONE
)
if
(
handler
->
conf
->
maincmd_fd
>=
0
)
if
(
handler
->
conf
->
maincmd_fd
>=
0
)
close
(
handler
->
conf
->
maincmd_fd
);
close
(
handler
->
conf
->
maincmd_fd
);
...
@@ -684,7 +684,7 @@ struct lxc_handler *lxc_init_handler(const char *name, struct lxc_conf *conf,
...
@@ -684,7 +684,7 @@ struct lxc_handler *lxc_init_handler(const char *name, struct lxc_conf *conf,
handler
->
sigfd
=
-
EBADF
;
handler
->
sigfd
=
-
EBADF
;
handler
->
init_died
=
false
;
handler
->
init_died
=
false
;
handler
->
state_socket_pair
[
0
]
=
handler
->
state_socket_pair
[
1
]
=
-
1
;
handler
->
state_socket_pair
[
0
]
=
handler
->
state_socket_pair
[
1
]
=
-
1
;
if
(
handler
->
conf
->
reboot
==
0
)
if
(
handler
->
conf
->
reboot
==
REBOOT_NONE
)
lxc_list_init
(
&
handler
->
conf
->
state_clients
);
lxc_list_init
(
&
handler
->
conf
->
state_clients
);
for
(
i
=
0
;
i
<
LXC_NS_MAX
;
i
++
)
for
(
i
=
0
;
i
<
LXC_NS_MAX
;
i
++
)
...
@@ -692,7 +692,7 @@ struct lxc_handler *lxc_init_handler(const char *name, struct lxc_conf *conf,
...
@@ -692,7 +692,7 @@ struct lxc_handler *lxc_init_handler(const char *name, struct lxc_conf *conf,
handler
->
name
=
name
;
handler
->
name
=
name
;
if
(
daemonize
&&
!
handler
->
conf
->
reboot
)
{
if
(
daemonize
&&
handler
->
conf
->
reboot
==
REBOOT_NONE
)
{
/* Create socketpair() to synchronize on daemonized startup.
/* Create socketpair() to synchronize on daemonized startup.
* When the container reboots we don't need to synchronize
* When the container reboots we don't need to synchronize
* again currently so don't open another socketpair().
* again currently so don't open another socketpair().
...
@@ -708,7 +708,7 @@ struct lxc_handler *lxc_init_handler(const char *name, struct lxc_conf *conf,
...
@@ -708,7 +708,7 @@ struct lxc_handler *lxc_init_handler(const char *name, struct lxc_conf *conf,
handler
->
state_socket_pair
[
1
]);
handler
->
state_socket_pair
[
1
]);
}
}
if
(
handler
->
conf
->
reboot
==
0
)
{
if
(
handler
->
conf
->
reboot
==
REBOOT_NONE
)
{
handler
->
conf
->
maincmd_fd
=
lxc_cmd_init
(
name
,
lxcpath
,
"command"
);
handler
->
conf
->
maincmd_fd
=
lxc_cmd_init
(
name
,
lxcpath
,
"command"
);
if
(
handler
->
conf
->
maincmd_fd
<
0
)
{
if
(
handler
->
conf
->
maincmd_fd
<
0
)
{
ERROR
(
"Failed to set up command socket"
);
ERROR
(
"Failed to set up command socket"
);
...
@@ -918,14 +918,14 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
...
@@ -918,14 +918,14 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
}
}
namespaces
[
namespace_count
]
=
NULL
;
namespaces
[
namespace_count
]
=
NULL
;
if
(
handler
->
conf
->
reboot
)
{
if
(
handler
->
conf
->
reboot
>
REBOOT_NONE
)
{
ret
=
setenv
(
"LXC_TARGET"
,
"reboot"
,
1
);
ret
=
setenv
(
"LXC_TARGET"
,
"reboot"
,
1
);
if
(
ret
<
0
)
if
(
ret
<
0
)
SYSERROR
(
"Failed to set environment variable: "
SYSERROR
(
"Failed to set environment variable: "
"LXC_TARGET=reboot"
);
"LXC_TARGET=reboot"
);
}
}
if
(
!
handler
->
conf
->
reboot
)
{
if
(
handler
->
conf
->
reboot
==
REBOOT_NONE
)
{
ret
=
setenv
(
"LXC_TARGET"
,
"stop"
,
1
);
ret
=
setenv
(
"LXC_TARGET"
,
"stop"
,
1
);
if
(
ret
<
0
)
if
(
ret
<
0
)
SYSERROR
(
"Failed to set environment variable: "
SYSERROR
(
"Failed to set environment variable: "
...
@@ -945,7 +945,7 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
...
@@ -945,7 +945,7 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
cgroup_ops
->
destroy
(
cgroup_ops
,
handler
);
cgroup_ops
->
destroy
(
cgroup_ops
,
handler
);
cgroup_exit
(
cgroup_ops
);
cgroup_exit
(
cgroup_ops
);
if
(
handler
->
conf
->
reboot
==
0
)
{
if
(
handler
->
conf
->
reboot
==
REBOOT_NONE
)
{
/* For all new state clients simply close the command socket.
/* For all new state clients simply close the command socket.
* This will inform all state clients that the container is
* This will inform all state clients that the container is
* STOPPED and also prevents a race between a open()/close() on
* STOPPED and also prevents a race between a open()/close() on
...
@@ -973,9 +973,9 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
...
@@ -973,9 +973,9 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
ret
=
run_lxc_hooks
(
name
,
"post-stop"
,
handler
->
conf
,
NULL
);
ret
=
run_lxc_hooks
(
name
,
"post-stop"
,
handler
->
conf
,
NULL
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to run lxc.hook.post-stop for container
\"
%s
\"
"
,
name
);
ERROR
(
"Failed to run lxc.hook.post-stop for container
\"
%s
\"
"
,
name
);
if
(
handler
->
conf
->
reboot
)
{
if
(
handler
->
conf
->
reboot
>
REBOOT_NONE
)
{
WARN
(
"Container will be stopped instead of rebooted"
);
WARN
(
"Container will be stopped instead of rebooted"
);
handler
->
conf
->
reboot
=
0
;
handler
->
conf
->
reboot
=
REBOOT_NONE
;
ret
=
setenv
(
"LXC_TARGET"
,
"stop"
,
1
);
ret
=
setenv
(
"LXC_TARGET"
,
"stop"
,
1
);
if
(
ret
<
0
)
if
(
ret
<
0
)
...
@@ -999,7 +999,8 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
...
@@ -999,7 +999,8 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
struct
lxc_state_client
*
client
=
cur
->
elem
;
struct
lxc_state_client
*
client
=
cur
->
elem
;
/* Keep state clients that want to be notified about reboots. */
/* Keep state clients that want to be notified about reboots. */
if
((
handler
->
conf
->
reboot
>
0
)
&&
(
client
->
states
[
RUNNING
]
==
2
))
if
((
handler
->
conf
->
reboot
>
REBOOT_NONE
)
&&
(
client
->
states
[
RUNNING
]
==
2
))
continue
;
continue
;
/* close state client socket */
/* close state client socket */
...
@@ -1009,7 +1010,7 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
...
@@ -1009,7 +1010,7 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
free
(
cur
);
free
(
cur
);
}
}
if
(
handler
->
conf
->
ephemeral
==
1
&&
handler
->
conf
->
reboot
!=
1
)
if
(
handler
->
conf
->
ephemeral
==
1
&&
handler
->
conf
->
reboot
!=
REBOOT_REQ
)
lxc_destroy_container_on_signal
(
handler
,
name
);
lxc_destroy_container_on_signal
(
handler
,
name
);
lxc_free_handler
(
handler
);
lxc_free_handler
(
handler
);
...
@@ -1892,7 +1893,7 @@ int __lxc_start(const char *name, struct lxc_handler *handler,
...
@@ -1892,7 +1893,7 @@ int __lxc_start(const char *name, struct lxc_handler *handler,
close
(
handler
->
data_sock
[
1
]);
close
(
handler
->
data_sock
[
1
]);
handler
->
data_sock
[
1
]
=
-
1
;
handler
->
data_sock
[
1
]
=
-
1
;
handler
->
conf
->
reboot
=
0
;
handler
->
conf
->
reboot
=
REBOOT_NONE
;
ret
=
lxc_poll
(
name
,
handler
);
ret
=
lxc_poll
(
name
,
handler
);
if
(
ret
)
{
if
(
ret
)
{
...
@@ -1915,7 +1916,7 @@ int __lxc_start(const char *name, struct lxc_handler *handler,
...
@@ -1915,7 +1916,7 @@ int __lxc_start(const char *name, struct lxc_handler *handler,
break
;
break
;
case
SIGHUP
:
/* reboot */
case
SIGHUP
:
/* reboot */
DEBUG
(
"Container
\"
%s
\"
is rebooting"
,
name
);
DEBUG
(
"Container
\"
%s
\"
is rebooting"
,
name
);
handler
->
conf
->
reboot
=
1
;
handler
->
conf
->
reboot
=
REBOOT_REQ
;
break
;
break
;
case
SIGSYS
:
/* seccomp */
case
SIGSYS
:
/* seccomp */
DEBUG
(
"Container
\"
%s
\"
violated its seccomp policy"
,
name
);
DEBUG
(
"Container
\"
%s
\"
violated its seccomp policy"
,
name
);
...
...
src/lxc/state.h
View file @
80308d07
...
@@ -35,6 +35,12 @@ typedef enum {
...
@@ -35,6 +35,12 @@ typedef enum {
MAX_STATE
,
MAX_STATE
,
}
lxc_state_t
;
}
lxc_state_t
;
enum
{
REBOOT_NONE
,
REBOOT_REQ
,
REBOOT_INIT
};
extern
lxc_state_t
lxc_getstate
(
const
char
*
name
,
const
char
*
lxcpath
);
extern
lxc_state_t
lxc_getstate
(
const
char
*
name
,
const
char
*
lxcpath
);
extern
lxc_state_t
lxc_str2state
(
const
char
*
state
);
extern
lxc_state_t
lxc_str2state
(
const
char
*
state
);
...
...
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