1
Allow to specify a timeout for waiting on state changes via lxc-wait.
2
Helpful for scripts that need to handle errors or excessive delays in
3
state changing procedures.
5
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
7
doc/lxc-wait.sgml.in | 11 +++++++++++
8
src/lxc/arguments.h | 1 +
9
src/lxc/lxc_wait.c | 16 +++++++++++++++-
10
3 files changed, 27 insertions(+), 1 deletions(-)
12
Index: lxc/doc/lxc-wait.sgml.in
13
===================================================================
14
--- lxc.orig/doc/lxc-wait.sgml.in 2012-07-26 17:51:42.145353005 +0000
15
+++ lxc/doc/lxc-wait.sgml.in 2012-07-26 17:51:44.297353675 +0000
22
+ <option>-t <replaceable>timeout</replaceable></option>
26
+ Wait timeout seconds for desired state to be reached.
34
Index: lxc/src/lxc/arguments.h
35
===================================================================
36
--- lxc.orig/src/lxc/arguments.h 2012-07-26 17:51:42.145353005 +0000
37
+++ lxc/src/lxc/arguments.h 2012-07-26 17:51:44.297353675 +0000
44
/* close fds from parent? */
46
Index: lxc/src/lxc/lxc_wait.c
47
===================================================================
48
--- lxc.orig/src/lxc/lxc_wait.c 2012-07-26 17:51:42.145353005 +0000
49
+++ lxc/src/lxc/lxc_wait.c 2012-07-26 17:51:44.301353694 +0000
56
#include <sys/types.h>
62
case 's': args->states = optarg; break;
63
+ case 't': args->timeout = atol(optarg); break;
68
static const struct option my_longopts[] = {
69
{"state", required_argument, 0, 's'},
70
+ {"timeout", required_argument, 0, 't'},
75
-n, --name=NAME NAME for name of the container\n\
76
-s, --state=STATE ORed states to wait for\n\
77
STOPPED, STARTING, RUNNING, STOPPING,\n\
78
- ABORTING, FREEZING, FROZEN\n",
79
+ ABORTING, FREEZING, FROZEN\n\
80
+ -t, --timeout=TMO Seconds to wait for state changes\n",
81
.options = my_longopts,
83
.checker = my_checker,
88
+static void timeout_handler(int signal)
93
int main(int argc, char *argv[])
100
+ signal(SIGALRM, timeout_handler);
101
+ alarm(my_args.timeout);
104
if (lxc_monitor_read(fd, &msg) < 0)