From: Ian Jackson <ian.jackson@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>
Subject: [PATCH 10/11] xl: Domain creation logging fixes
Date: Thu, 25 Mar 2010 19:04:13 +0000 [thread overview]
Message-ID: <1269543854-7780-11-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <1269543854-7780-1-git-send-email-ian.jackson@eu.citrix.com>
* Make create_domain always return to caller
* Have create_domain set its log callback sooner
* Actually write things to logfile, and some error checking
With some combinations of options, create_domain would never return to
the caller, since it would have called daemon and will later exit. So
we fork an additional time, so that we can call daemon in the child
and also return to the caller in the parent. It's a shame that
there's no version of daemon(3) that allows us to do this without the
extra code and pointless extra fork.
daemon(0,0) closes all the fds. So we need to call daemon(0,1) and
organise detaching our stdin/out/err ourselves. Doing this makes
messages actually appear in the xl logfile in /var/log/xen.
Finally, make create_domain call libxl_ctx_set_log sooner. This makes
some lost messages appear.
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
tools/libxl/xl.c | 43 ++++++++++++++++++++++++++++++++++++-------
1 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c
index f3729f3..7d35db1 100644
--- a/tools/libxl/xl.c
+++ b/tools/libxl/xl.c
@@ -743,7 +743,7 @@ static void create_domain(int debug, int daemonize, const char *config_file, con
int num_disks = 0, num_vifs = 0, num_pcidevs = 0, num_vfbs = 0, num_vkbs = 0;
int i, fd;
int need_daemon = 1;
- int ret;
+ int ret, rc;
libxl_device_model_starting *dm_starting = 0;
libxl_waiter *w1 = NULL, *w2 = NULL;
void *config_data = 0;
@@ -757,6 +757,7 @@ static void create_domain(int debug, int daemonize, const char *config_file, con
fprintf(stderr, "cannot init xl context\n");
exit(1);
}
+ libxl_ctx_set_log(&ctx, log_callback, NULL);
if (restore_file) {
uint8_t *optdata_begin = 0;
@@ -851,8 +852,6 @@ static void create_domain(int debug, int daemonize, const char *config_file, con
start:
domid = 0;
- libxl_ctx_set_log(&ctx, log_callback, NULL);
-
ret = libxl_domain_make(&ctx, &info1, &domid);
if (ret) {
fprintf(stderr, "cannot make domain: %d\n", ret);
@@ -931,17 +930,47 @@ start:
if (need_daemon) {
char *fullname, *name;
+ pid_t child1, got_child;
+ int nullfd;
+
+ child1 = libxl_fork(&ctx);
+ if (child1) {
+ int status;
+ for (;;) {
+ got_child = waitpid(child1, &status, 0);
+ if (got_child == child1) break;
+ assert(got_child == -1);
+ if (errno != EINTR) {
+ perror("failed to wait for daemonizing child");
+ return ERROR_FAIL;
+ }
+ }
+ if (status) {
+ libxl_report_child_exitstatus(&ctx, XL_LOG_ERROR,
+ "daemonizing child", child1, status);
+ return ERROR_FAIL;
+ }
+ return 0; /* caller gets success in parent */
+ }
asprintf(&name, "xl-%s", info1.name);
- libxl_create_logfile(&ctx, name, &fullname);
- logfile = open(fullname, O_WRONLY|O_CREAT, 0644);
+ rc = libxl_create_logfile(&ctx, name, &fullname);
+ if (rc) return rc;
+
+ CHK_ERRNO(( logfile = open(fullname, O_WRONLY|O_CREAT, 0644) )<0);
free(fullname);
free(name);
- daemon(0, 0);
+ CHK_ERRNO(( nullfd = open("/dev/null", O_RDONLY) )<0);
+ dup2(nullfd, 0);
+ dup2(logfile, 1);
+ dup2(logfile, 2);
+
+ daemon(0, 1);
need_daemon = 0;
}
- LOG("Waiting for domain %s (domid %d) to die", info1.name, domid);
+ LOG("Waiting for domain %s (domid %d) to die [pid %ld]",
+ info1.name, domid, (long)getpid());
w1 = (libxl_waiter*) xmalloc(sizeof(libxl_waiter) * num_disks);
w2 = (libxl_waiter*) xmalloc(sizeof(libxl_waiter));
libxl_wait_for_disk_ejects(&ctx, domid, disks, num_disks, w1);
--
1.5.6.5
next prev parent reply other threads:[~2010-03-25 19:04 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-25 19:04 [PATCH 00/11] Migration support for "xl" Ian Jackson
2010-03-25 19:04 ` [PATCH 01/11] libxl: Make logging functions preserve errno Ian Jackson
2010-03-25 19:04 ` [PATCH 02/11] libxl: Report error if logfile rotation fails Ian Jackson
2010-03-25 19:04 ` [PATCH 03/11] libxl: New utility functions in for reading and writing files Ian Jackson
2010-03-25 19:04 ` [PATCH 04/11] libxl: libxl_domain_restore: Put fd back to blocking mode Ian Jackson
2010-03-25 19:04 ` [PATCH 05/11] libxl: Provide libxl_domain_rename Ian Jackson
2010-03-26 10:01 ` Vincent Hanquez
2010-03-26 10:23 ` Ian Jackson
2010-03-26 10:34 ` Vincent Hanquez
2010-03-26 10:40 ` Ian Jackson
2010-04-01 11:00 ` Stefano Stabellini
2010-03-25 19:04 ` [PATCH 06/11] libxl: Expose functions for helping with subprocesses Ian Jackson
2010-03-25 19:04 ` [PATCH 07/11] libxl: Expose libxl_report_exitstatus Ian Jackson
2010-03-25 19:04 ` [PATCH 08/11] libxl: Per-domain data storage for the convenience of the library user Ian Jackson
2010-03-26 10:06 ` Vincent Hanquez
2010-03-26 10:20 ` Ian Jackson
2010-03-26 10:29 ` Vincent Hanquez
2010-03-26 10:34 ` Ian Jackson
2010-03-26 10:41 ` Vincent Hanquez
2010-03-26 10:45 ` Ian Jackson
2010-03-26 11:27 ` Vincent Hanquez
2010-03-26 11:56 ` Ian Jackson
2010-04-01 11:04 ` Stefano Stabellini
2010-03-25 19:04 ` [PATCH 09/11] xl: New savefile format. Save domain config when saving a domain Ian Jackson
2010-04-01 11:08 ` Stefano Stabellini
2010-03-25 19:04 ` Ian Jackson [this message]
2010-03-25 19:04 ` [PATCH 11/11] xl: Migration support Ian Jackson
2010-04-01 11:10 ` Stefano Stabellini
2010-04-01 11:10 ` [PATCH 00/11] Migration support for "xl" Stefano Stabellini
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=1269543854-7780-11-git-send-email-ian.jackson@eu.citrix.com \
--to=ian.jackson@eu.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).