From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH 6 of 9] libxl/xl: exec xenconsole in current process, defer decision to fork to caller
Date: Mon, 12 Jul 2010 15:01:42 +0100 [thread overview]
Message-ID: <bcea013ddd5a5e46d935.1278943302@localhost.localdomain> (raw)
In-Reply-To: <patchbomb.1278943296@localhost.localdomain>
Use this to run xenconsole as the foreground process and move the
connection to the console in the "create -c" case early enough to be
able to view output from the bootloader. This behaviour is consistent
with how both "xm console" and "xm create -c" operate.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
diff -r 4b41b5e7532c -r bcea013ddd5a tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Mon Jul 12 14:56:37 2010 +0100
+++ b/tools/libxl/libxl.c Mon Jul 12 14:56:37 2010 +0100
@@ -786,12 +786,12 @@
return 0;
}
-int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num)
+int libxl_console_exec(struct libxl_ctx *ctx, uint32_t domid, int cons_num)
{
- char *cmd = libxl_sprintf(
- ctx, "%s/xenconsole %d --num %d",
- libxl_private_bindir_path(), domid, cons_num);
- return (system(cmd) != 0) ? ERROR_FAIL : 0;
+ char *p = libxl_sprintf(ctx, "%s/xenconsole", libxl_private_bindir_path());
+ char *domid_s = libxl_sprintf(ctx, "%d", domid);
+ char *cons_num_s = libxl_sprintf(ctx, "%d", cons_num);
+ return execl(p, p, domid_s, "--num", cons_num_s, (void *)NULL) == 0 ? 0 : ERROR_FAIL;
}
static char ** libxl_build_device_model_args(struct libxl_ctx *ctx,
diff -r 4b41b5e7532c -r bcea013ddd5a tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Mon Jul 12 14:56:37 2010 +0100
+++ b/tools/libxl/libxl.h Mon Jul 12 14:56:37 2010 +0100
@@ -358,7 +358,7 @@
int libxl_domain_setmaxmem(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb);
int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb, int enforce);
-int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
+int libxl_console_exec(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
int libxl_domain_info(struct libxl_ctx*, struct libxl_dominfo *info_r,
uint32_t domid);
diff -r 4b41b5e7532c -r bcea013ddd5a tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Mon Jul 12 14:56:37 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Mon Jul 12 14:56:37 2010 +0100
@@ -931,12 +931,45 @@
return r;
}
+int autoconnect_console(int cons_num)
+{
+ int status;
+ pid_t pid, r;
+
+ /*
+ * Fork for xenconsole. We exec xenconsole in the foreground
+ * process allowing it to retain the tty. xl continues in the
+ * child. The xenconsole client uses a xenstore watch to wait for
+ * the console to be setup so there is no race.
+ */
+ pid = fork();
+ if (pid < 0) {
+ perror("unable to fork xenconsole");
+ return ERROR_FAIL;
+ } else if (pid == 0)
+ return 0;
+
+ /*
+ * Catch failure of the create process.
+ */
+ sleep(1);
+ r = waitpid(pid, &status, WNOHANG);
+ if (r > 0 && WIFEXITED(status) && WEXITSTATUS(status) != 0)
+ _exit(WEXITSTATUS(status));
+
+ libxl_console_exec(&ctx, domid, cons_num);
+ /* Do not return. xl continued in child process */
+ fprintf(stderr, "Unable to attach console\n");
+ _exit(1);
+}
+
struct domain_create {
int debug;
int daemonize;
int paused;
int dryrun;
int quiet;
+ int console_autoconnect;
const char *config_file;
const char *extra_config; /* extra config string */
const char *restore_file;
@@ -1118,6 +1151,12 @@
perror("cannot save config file");
ret = ERROR_FAIL;
goto error_out;
+ }
+
+ if (dom_info->console_autoconnect) {
+ ret = autoconnect_console(0);
+ if (ret)
+ goto error_out;
}
if (!restore_file || !need_daemon) {
@@ -1467,12 +1506,6 @@
exit(0);
}
-void console(char *p, int cons_num)
-{
- find_domain(p);
- libxl_console_attach(&ctx, domid, cons_num);
-}
-
void cd_insert(char *dom, char *virtdev, char *phys)
{
libxl_device_disk disk;
@@ -1570,7 +1603,6 @@
int main_console(int argc, char **argv)
{
int opt = 0, cons_num = 0;
- char *p = NULL;
while ((opt = getopt(argc, argv, "hn:")) != -1) {
switch (opt) {
@@ -1592,10 +1624,10 @@
exit(2);
}
- p = argv[optind];
-
- console(p, cons_num);
- exit(0);
+ find_domain(argv[optind]);
+ libxl_console_exec(&ctx, domid, 0);
+ fprintf(stderr, "Unable to attach console\n");
+ return 1;
}
void pcilist(char *dom)
@@ -2672,7 +2704,6 @@
char *filename = NULL;
char *p, extra_config[1024];
struct domain_create dom_info;
- char dom[10]; /* long enough */
int paused = 0, debug = 0, daemonize = 1, console_autoconnect = 0,
dryrun = 0, quite = 0;
int opt, rc;
@@ -2747,15 +2778,11 @@
dom_info.config_file = filename;
dom_info.extra_config = extra_config;
dom_info.migrate_fd = -1;
+ dom_info.console_autoconnect = console_autoconnect;
rc = create_domain(&dom_info);
if (rc < 0)
exit(-rc);
-
- if (console_autoconnect) {
- snprintf(dom, sizeof(dom), "%d", rc);
- console(dom, 0);
- }
exit(0);
}
next prev parent reply other threads:[~2010-07-12 14:01 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-12 14:01 [PATCH 0 of 9] libxl/xl: support for domain 0 bootloader (e.g. pygrub) Ian Campbell
2010-07-12 14:01 ` [PATCH 1 of 9] pygrub: introduce easier to parse output format Ian Campbell
2010-07-12 14:01 ` [PATCH 2 of 9] xenconsole: do not exit if a pty device is missing Ian Campbell
2010-07-12 14:01 ` [PATCH 3 of 9] libxl: add printf attribute to libxl_xs_write and fixup resulting warnings Ian Campbell
2010-07-12 14:01 ` [PATCH 4 of 9] libxl: add libxl_strdup convenience function Ian Campbell
2010-07-12 14:01 ` [PATCH 5 of 9] libxl: fix typo Ian Campbell
2010-07-12 14:01 ` Ian Campbell [this message]
2010-07-12 14:01 ` [PATCH 7 of 9] libxl: support mapping files rather than carrying paths around Ian Campbell
2010-07-12 14:01 ` [PATCH 8 of 9] libxl: add function to attach/detach a disk to/from the local VM Ian Campbell
2010-07-12 14:01 ` [PATCH 9 of 9] libxl/xl: support running bootloader (e.g. pygrub) in domain 0 Ian Campbell
2010-07-13 18:23 ` [PATCH 0 of 9] libxl/xl: support for domain 0 bootloader (e.g. pygrub) Ian Jackson
2010-07-14 1:24 ` Zhigang Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bcea013ddd5a5e46d935.1278943302@localhost.localdomain \
--to=ian.campbell@citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).