The following rationale is for using the -t option: Currently, lxc-shutdown uses a subprocess for the timeout handling, where a 'sleep $TIMEOUT' is executed, which will kill the main process after the timeout has occurred, thus causing the main process to stop the container hard with lxc-stop.
On the other hand, if the timeout is not reached, the main process kills the subprocess. The trouble now is that if you kill a shell that is running in the background, the kill will only take effect as soon as the program currently running in the shell exits. This in turn means that the subprocess will never terminate before reaching the timeout. In an interactive shell, this does not matter, since people will just not notice the process and lxc-shutdown returns immediately. In a non-interactive enironment, however, there may be circumstances that cause the calling program to wait until even that subprocess is terminated, which means that shutdown will always take as long as the timeout, even if the container shuts down quite a bit earlier. This change makes sure that also all subprocesses of the background process are killed from the main process. This will immediately terminate the background process, thus ensuring the desired behaviour. Signed-off-by: Christian Seiler <christ...@iwakd.de> --- src/lxc/lxc-shutdown.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lxc/lxc-shutdown.in b/src/lxc/lxc-shutdown.in index d82cebf..ee07f75 100644 --- a/src/lxc/lxc-shutdown.in +++ b/src/lxc/lxc-shutdown.in @@ -131,7 +131,7 @@ fi if [ $timeout != "-1" ]; then trap dolxcstop EXIT - alarm $$ $timeout & + alarm $$ $timeout 2>/dev/null & alarmpid=$! fi @@ -141,7 +141,9 @@ done if [ $timeout != "-1" ]; then trap - EXIT - kill $alarmpid + # include subprocesses; otherwise, we may have to wait until sleep completes + # if called from a non-interactive context + kill $alarmpid $(ps --no-headers --ppid $alarmpid -o pid) 2>/dev/null || : fi echo "Container $lxc_name has shut down" -- 1.7.10.4 ------------------------------------------------------------------------------ Own the Future-Intel(R) Level Up Game Demo Contest 2013 Rise to greatness in Intel's independent game demo contest. Compete for recognition, cash, and the chance to get your game on Steam. $5K grand prize plus 10 genre and skill prizes. Submit your demo by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2 _______________________________________________ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel