From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?ISO-8859-1?Q?Roger_Pau_Monn=E9?= Subject: Re: [PATCH] libxl: libxl__spawn_qdisk_backend closes fds Date: Tue, 18 Mar 2014 10:08:05 +0100 Message-ID: <53280CF5.9040901@citrix.com> References: <1395073963-3737-1-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: <1395073963-3737-1-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 , xen-devel@lists.xensource.com Cc: Ian Campbell , coverity@xenproject.org List-Id: xen-devel@lists.xenproject.org On 17/03/14 17:32, Ian Jackson wrote: > This function needs to close both null and logfile_w on both error and > normal exits. (The child gets its own copy during the fork, and the > parent doesn't need them any more.) > > Use the standard initialise-to-unallocated, always-free style; the > label "out" only makes the callback if rc is nonzero. > > Signed-off-by: Ian Jackson > Coverity-ID: 1130517 and 1130518 There's a similar patch in <21134.22006.356685.408733@mariner.uk.xensource.com>. > Cc: Roger Pau Monne > Cc: Ian Campbell > Cc: coverity@xenproject.org > --- > tools/libxl/libxl_dm.c | 15 ++++++++++++--- > 1 file changed, 12 insertions(+), 3 deletions(-) > > diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c > index 8abed7b..d28ea4d 100644 > --- a/tools/libxl/libxl_dm.c > +++ b/tools/libxl/libxl_dm.c > @@ -1392,7 +1392,7 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) > flexarray_t *dm_args; > char **args; > const char *dm; > - int logfile_w, null, rc; > + int logfile_w = -1, null = -1, rc; > uint32_t domid = dmss->guest_domid; > > /* Always use qemu-xen as device model */ > @@ -1448,12 +1448,21 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss) > libxl__exec(gc, null, logfile_w, logfile_w, dm, args, NULL); > } > > + rc = 0; > + > + out: > + if (logfile_w >= 0) close(logfile_w); > + if (null >= 0) close(null); > + > + /* rc is nonzero iff we had an error; if we had no error then > + * spawn succeeded and we will continue in a further callback */ > + if (rc) > + dmss->callback(egc, dmss, rc); Using the device_model_spawn_outcome helper instead of directly calling the callback will print a nice error message in case spawn has failed. > return; > > error: > assert(rc); > - dmss->callback(egc, dmss, rc); > - return; > + goto out; This jump backwards is kind of strange IMHO, why not just rename the error label to out and use it instead for both the error and non-error exit paths? Roger.