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
f8bdb6dc
Unverified
Commit
f8bdb6dc
authored
Nov 24, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxccontainer: restore non-blocking shutdown
If timeout is set to 0 don't block. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
bc631984
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
26 deletions
+38
-26
lxccontainer.c
src/lxc/lxccontainer.c
+38
-26
No files found.
src/lxc/lxccontainer.c
View file @
f8bdb6dc
...
...
@@ -1862,10 +1862,9 @@ WRAP_API_1(bool, lxcapi_reboot2, int)
static
bool
do_lxcapi_shutdown
(
struct
lxc_container
*
c
,
int
timeout
)
{
int
ret
,
state_client_fd
=
-
1
;
bool
retv
=
false
;
int
killret
,
ret
;
pid_t
pid
;
int
haltsignal
=
SIGPWR
;
int
haltsignal
=
SIGPWR
,
state_client_fd
=
-
1
;
lxc_state_t
states
[
MAX_STATE
]
=
{
0
};
if
(
!
c
)
...
...
@@ -1873,6 +1872,7 @@ static bool do_lxcapi_shutdown(struct lxc_container *c, int timeout)
if
(
!
do_lxcapi_is_running
(
c
))
return
true
;
pid
=
do_lxcapi_init_pid
(
c
);
if
(
pid
<=
0
)
return
true
;
...
...
@@ -1884,37 +1884,49 @@ static bool do_lxcapi_shutdown(struct lxc_container *c, int timeout)
if
(
c
->
lxc_conf
&&
c
->
lxc_conf
->
haltsignal
)
haltsignal
=
c
->
lxc_conf
->
haltsignal
;
INFO
(
"Using signal number '%d' as halt signal"
,
haltsignal
);
/* Add a new state client before sending the shutdown signal so that we
* don't miss a state.
*/
states
[
STOPPED
]
=
1
;
ret
=
lxc_cmd_add_state_client
(
c
->
name
,
c
->
config_path
,
states
,
&
state_client_fd
);
if
(
timeout
!=
0
)
{
states
[
STOPPED
]
=
1
;
ret
=
lxc_cmd_add_state_client
(
c
->
name
,
c
->
config_path
,
states
,
&
state_client_fd
);
if
(
ret
<
0
)
return
false
;
/* Send shutdown signal to container. */
if
(
kill
(
pid
,
haltsignal
)
<
0
)
WARN
(
"Could not send signal %d to pid %d"
,
haltsignal
,
pid
);
if
(
state_client_fd
<
0
)
return
false
;
if
(
ret
==
STOPPED
)
return
true
;
/* Retrieve the state. */
if
(
state_client_fd
>=
0
)
{
int
state
;
state
=
lxc_cmd_sock_rcv_state
(
state_client_fd
,
timeout
);
close
(
state_client_fd
);
TRACE
(
"Received state
\"
%s
\"
"
,
lxc_state2str
(
state
));
if
(
state
!=
STOPPED
)
if
(
ret
<
MAX_STATE
)
return
false
;
retv
=
true
;
}
else
if
(
ret
==
STOPPED
)
{
TRACE
(
"Container is already stopped"
);
retv
=
true
;
}
else
{
TRACE
(
"Received state
\"
%s
\"
instead of expected
\"
STOPPED
\"
"
,
lxc_state2str
(
ret
));
}
return
retv
;
/* Send shutdown signal to container. */
killret
=
kill
(
pid
,
haltsignal
);
if
(
killret
<
0
)
{
WARN
(
"Could not send signal %d to pid %d"
,
haltsignal
,
pid
);
if
(
state_client_fd
>=
0
)
close
(
state_client_fd
);
return
false
;
}
TRACE
(
"Sent signal %d to pid %d"
,
haltsignal
,
pid
);
if
(
timeout
==
0
)
return
true
;
ret
=
lxc_cmd_sock_rcv_state
(
state_client_fd
,
timeout
);
close
(
state_client_fd
);
if
(
ret
<
0
)
return
false
;
TRACE
(
"Received state
\"
%s
\"
"
,
lxc_state2str
(
ret
));
if
(
ret
!=
STOPPED
)
return
false
;
return
true
;
}
WRAP_API_1
(
bool
,
lxcapi_shutdown
,
int
)
...
...
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