From: Roger Pau Monne Subject: [PATCH] libxl: prevent xl from running if xend is running. Date: Mon, 23 Apr 2012 16:11:02 +0100 Message-ID: <1335193862-37069-1-git-send-email-roger.pau@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: george.dunlap@eu.citrix.com, Roger Pau Monne List-Id: xen-devel@lists.xenproject.org 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 --- 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] [args]\n\n"); + printf("Usage xl [-vfN] [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)