From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Campbell Subject: Re: [PATCH 05/23] libxl: init: Provide a gc later in libxl_ctx_alloc Date: Thu, 19 Dec 2013 12:51:22 +0000 Message-ID: <1387457482.9925.61.camel@kazak.uk.xensource.com> References: <1387305337-15355-1-git-send-email-ian.jackson@eu.citrix.com> <1387305337-15355-6-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1387305337-15355-6-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Jackson Cc: Shriram Rajagopalan , George Dunlap , xen-devel@lists.xensource.com, Stefano Stabellini List-Id: xen-devel@lists.xenproject.org On Tue, 2013-12-17 at 18:35 +0000, Ian Jackson wrote: > Provide libxl__gc *gc for the second half of libxl_ctx_alloc. > (For the first half of the function, gc is in scope but set to NULL.) libxl uses -Wno-declaration-after-statement so it would be valid to just declare it at the point it becomes valid, would avoid mistakes with people adding uses before this point. > This makes it possible to make gc-requiring calls. For example, it > makes error logging more convenient. > > Make use of this by changing the logging calls to use the LOG* > convenience macros. > > Signed-off-by: Ian Jackson > CC: Stefano Stabellini > CC: Ian Campbell > --- > tools/libxl/libxl.c | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c > index e8ad610..cfd1435 100644 > --- a/tools/libxl/libxl.c > +++ b/tools/libxl/libxl.c > @@ -25,6 +25,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, > unsigned flags, xentoollog_logger * lg) > { > libxl_ctx *ctx = NULL; > + libxl__gc gc_buf, *gc = NULL; > int rc; > > if (version != LIBXL_VERSION) { rc = ERROR_VERSION; goto out; } > @@ -79,6 +80,9 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, > } > > /* Now ctx is safe for ctx_free; failures simply set rc and "goto out" */ > + LIBXL_INIT_GC(gc_buf,ctx); > + gc = &gc_buf; > + /* Now gc is useable */ > > rc = libxl__atfork_init(ctx); > if (rc) goto out; > @@ -88,8 +92,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, > > ctx->xch = xc_interface_open(lg,lg,0); > if (!ctx->xch) { > - LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, errno, > - "cannot open libxc handle"); > + LOGEV(ERROR, errno, "cannot open libxc handle"); > rc = ERROR_FAIL; goto out; > } > > @@ -97,8 +100,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, > if (!ctx->xsh) > ctx->xsh = xs_domain_open(); > if (!ctx->xsh) { > - LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, errno, > - "cannot connect to xenstore"); > + LOGEV(ERROR, errno, "cannot connect to xenstore"); > rc = ERROR_FAIL; goto out; > } > > @@ -106,6 +108,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, > return 0; > > out: > + if (gc) libxl__free_all(gc); > libxl_ctx_free(ctx); > *pctx = NULL; > return rc;