From c393ff09ade45d1a2a8f1c12eac5eab4d38947a3 Mon Sep 17 00:00:00 2001 From: Roger Pau Monne Date: Fri, 22 Nov 2013 12:54:09 +0100 Subject: [PATCH] xl: fixes for do_daemonize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix usage of CHK_ERRNO in do_daemonize and also remove the usage of a bogus for(;;). Coverity-ID: 1130516 and 1130520 Signed-off-by: Roger Pau Monné Reviewed-by: Andrew Cooper Acked-by: Ian Campbell Cc: Ian Jackson (cherry picked from commit ed8c9047f6fc6d28fc27d37576ec8c8c1be68efe) Conflicts: tools/libxl/xl_cmdimpl.c --- tools/libxl/xl_cmdimpl.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index e2eb9e0cae..efff1990a7 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -2079,14 +2079,14 @@ start: if (child1) { printf("Daemon running with PID %d\n", child1); - for (;;) { - got_child = xl_waitpid(child_waitdaemon, &status, 0); - if (got_child == child1) break; + got_child = xl_waitpid(child_waitdaemon, &status, 0); + if (got_child != child1) { assert(got_child == -1); - perror("failed to wait for daemonizing child"); + LOG("failed to wait for daemonizing child: %s", strerror(errno)); ret = ERROR_FAIL; goto out; } + if (status) { libxl_report_child_exitstatus(ctx, XTL_ERROR, "daemonizing child", child1, status); @@ -2109,17 +2109,16 @@ start: exit(-1); } - CHK_ERRNO(( logfile = open(fullname, O_WRONLY|O_CREAT|O_APPEND, - 0644) )<0); + CHK_ERRNO(logfile = open(fullname, O_WRONLY|O_CREAT|O_APPEND, 0644)); free(fullname); free(name); - CHK_ERRNO(( nullfd = open("/dev/null", O_RDONLY) )<0); + CHK_ERRNO(nullfd = open("/dev/null", O_RDONLY)); dup2(nullfd, 0); dup2(logfile, 1); dup2(logfile, 2); - CHK_ERRNO(daemon(0, 1) < 0); + CHK_ERRNO(daemon(0, 1)); need_daemon = 0; } LOG("Waiting for domain %s (domid %d) to die [pid %ld]",