~serge-hallyn/ubuntu/quantal/lxc/lxc-fixapi

« back to all changes in this revision

Viewing changes to debian/patches/0096-lxc-wait-add-timeout.patch

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2012-08-08 18:11:21 UTC
  • Revision ID: package-import@ubuntu.com-20120808181121-dvfay08v7hxmaqc1
Tags: 0.8.0~rc1-4ubuntu23
* fix FTBFS
  - add libseccomp to build-deps
  - add autoreconf to build-deps to regenerate Makefile.in at build time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
4
 
 
5
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
 
6
---
 
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(-)
 
11
 
 
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
 
16
@@ -79,6 +79,17 @@
 
17
        </listitem>
 
18
       </varlistentry>
 
19
 
 
20
+      <varlistentry>
 
21
+       <term>
 
22
+         <option>-t <replaceable>timeout</replaceable></option>
 
23
+       </term>
 
24
+       <listitem>
 
25
+         <para>
 
26
+           Wait timeout seconds for desired state to be reached.
 
27
+         </para>
 
28
+       </listitem>
 
29
+      </varlistentry>
 
30
+
 
31
     </variablelist>
 
32
 
 
33
   </refsect1>
 
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
 
38
@@ -57,6 +57,7 @@
 
39
 
 
40
        /* for lxc-wait */
 
41
        char *states;
 
42
+       long timeout;
 
43
 
 
44
        /* close fds from parent? */
 
45
        int close_all_fds;
 
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
 
50
@@ -24,6 +24,8 @@
 
51
 #include <string.h>
 
52
 #include <libgen.h>
 
53
 #include <unistd.h>
 
54
+#include <stdlib.h>
 
55
+#include <signal.h>
 
56
 #include <sys/types.h>
 
57
 
 
58
 #include <lxc/lxc.h>
 
59
@@ -46,12 +48,14 @@
 
60
 {
 
61
        switch (c) {
 
62
        case 's': args->states = optarg; break;
 
63
+       case 't': args->timeout = atol(optarg); break;
 
64
        }
 
65
        return 0;
 
66
 }
 
67
 
 
68
 static const struct option my_longopts[] = {
 
69
        {"state", required_argument, 0, 's'},
 
70
+       {"timeout", required_argument, 0, 't'},
 
71
        LXC_COMMON_OPTIONS
 
72
 };
 
73
 
 
74
@@ -66,7 +70,8 @@
 
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,
 
82
        .parser   = my_parser,
 
83
        .checker  = my_checker,
 
84
@@ -91,6 +96,11 @@
 
85
        return 0;
 
86
 }
 
87
 
 
88
+static void timeout_handler(int signal)
 
89
+{
 
90
+       exit(-1);
 
91
+}
 
92
+
 
93
 int main(int argc, char *argv[])
 
94
 {
 
95
        struct lxc_msg msg;
 
96
@@ -124,6 +134,9 @@
 
97
                goto out_close;
 
98
        }
 
99
 
 
100
+       signal(SIGALRM, timeout_handler);
 
101
+       alarm(my_args.timeout);
 
102
+
 
103
        for (;;) {
 
104
                if (lxc_monitor_read(fd, &msg) < 0)
 
105
                        goto out_close;
 
106
@@ -140,6 +153,7 @@
 
107
                        }
 
108
 
 
109
                        if (s[msg.value]) {
 
110
+                               alarm(0);
 
111
                                ret = 0;
 
112
                                goto out_close;
 
113
                        }