All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libxl: prevent xl from running if xend is running.
@ 2012-04-23 15:11 Roger Pau Monne
  2012-04-23 15:26 ` Ian Campbell
  2012-04-24 13:17 ` Ian Jackson
  0 siblings, 2 replies; 13+ messages in thread
From: Roger Pau Monne @ 2012-04-23 15:11 UTC (permalink / raw)
  To: xen-devel; +Cc: george.dunlap, Roger Pau Monne

Prevent xl from doing any operation if xend daemon is running. That prevents
bugs that happened when xl and xend raced to close a domain.

Cc: george.dunlap@eu.citrix.com
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
---
 tools/libxl/xl.c         |   18 +++++++++++++++++-
 tools/libxl/xl_cmdimpl.c |    4 ++--
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c
index 2b14814..dc434cd 100644
--- a/tools/libxl/xl.c
+++ b/tools/libxl/xl.c
@@ -32,8 +32,11 @@
 #include "libxlutil.h"
 #include "xl.h"
 
+#define XEND_LOCK { "/var/lock/subsys/xend", "/var/lock/xend" }
+
 xentoollog_logger_stdiostream *logger;
 int dryrun_only;
+int force_execution;
 int autoballoon = 1;
 char *lockfile;
 char *default_vifscript = NULL;
@@ -103,8 +106,9 @@ int main(int argc, char **argv)
     char *config_file;
     void *config_data = 0;
     int config_len = 0;
+    const char *locks[] = XEND_LOCK;
 
-    while ((opt = getopt(argc, argv, "+vN")) >= 0) {
+    while ((opt = getopt(argc, argv, "+vfN")) >= 0) {
         switch (opt) {
         case 'v':
             if (minmsglevel > 0) minmsglevel--;
@@ -112,6 +116,9 @@ int main(int argc, char **argv)
         case 'N':
             dryrun_only = 1;
             break;
+        case 'f':
+            force_execution = 1;
+            break;
         default:
             fprintf(stderr, "unknown global option\n");
             exit(2);
@@ -126,6 +133,15 @@ int main(int argc, char **argv)
     }
     opterr = 0;
 
+    for (int i = 0; i < sizeof(locks)/sizeof(locks[0]); i++) {
+        if (!access(locks[i], F_OK) && !force_execution) {
+            fprintf(stderr, "xend is running, which prevents xl from working "
+                            "correctly. If you still want to force the "
+                            "execution of xl please use the -f option\n");
+            exit(2);
+        }
+    }
+
     logger = xtl_createlogger_stdiostream(stderr, minmsglevel,  0);
     if (!logger) exit(1);
 
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 6f4dd09..65bc6d6 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -1909,7 +1909,7 @@ void help(const char *command)
     struct cmd_spec *cmd;
 
     if (!command || !strcmp(command, "help")) {
-        printf("Usage xl [-vN] <subcommand> [args]\n\n");
+        printf("Usage xl [-vfN] <subcommand> [args]\n\n");
         printf("xl full list of subcommands:\n\n");
         for (i = 0; i < cmdtable_len; i++) {
             printf(" %-19s ", cmd_table[i].cmd_name);
@@ -1920,7 +1920,7 @@ void help(const char *command)
     } else {
         cmd = cmdtable_lookup(command);
         if (cmd) {
-            printf("Usage: xl [-v%s] %s %s\n\n%s.\n\n",
+            printf("Usage: xl [-vf%s] %s %s\n\n%s.\n\n",
                    cmd->can_dryrun ? "N" : "",
                    cmd->cmd_name,
                    cmd->cmd_usage,
-- 
1.7.7.5 (Apple Git-26)

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2012-04-24 18:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-23 15:11 [PATCH] libxl: prevent xl from running if xend is running Roger Pau Monne
2012-04-23 15:26 ` Ian Campbell
2012-04-24 13:18   ` Ian Jackson
2012-04-24 13:17 ` Ian Jackson
2012-04-24 13:30   ` Ian Campbell
2012-04-24 13:34     ` Ian Jackson
2012-04-24 14:40       ` Ian Campbell
2012-04-24 14:47         ` Ian Jackson
2012-04-24 14:59           ` Ian Campbell
2012-04-24 17:58             ` Roger Pau Monne
2012-04-24 18:00               ` Ian Jackson
2012-04-24 17:07       ` Roger Pau Monne
2012-04-24 17:10         ` Ian Jackson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.