Eric Blake <ebl...@redhat.com> wrote on 03/10/2014 02:09:58 PM: > From: Eric Blake <ebl...@redhat.com> > To: Stefan Berger/Watson/IBM@IBMUS, libvir-list@redhat.com, > Cc: la...@laine.org > Date: 03/10/2014 02:24 PM > Subject: Re: [libvirt] [PATCH] BZ1072677: Avoid freeing of 0 file descriptor > > On 03/08/2014 04:29 PM, Stefan Berger wrote: > > From: Stefan Berger <stef...@linux.vnet.ibm.com> > > > > Avoid the freeing of an array of zero file descriptors in case > > of error. Introduce a macro VIR_INIT_N_FD to initialize such > > an array's elements to -1. > > > > Signed-off-by: Stefan Berger <stef...@linux.vnet.ibm.com> > > --- > > src/qemu/qemu_hotplug.c | 14 +++++++++++--- > > src/util/virfile.h | 12 ++++++++++++ > > 2 files changed, 23 insertions(+), 3 deletions(-) > > > > > +++ b/src/util/virfile.h > > @@ -75,6 +75,18 @@ FILE *virFileFdopen(int *fdptr, const char > *mode) ATTRIBUTE_RETURN_CHECK; > > VIR_FILE_CLOSE_PRESERVE_ERRNO | \ > > VIR_FILE_CLOSE_DONT_LOG)) > > > > +static inline void vir_init_n_int(int *ptr, int count, int value) > > +{ > > + int i; > > + > > + for (i = 0; i < count; i++) > > + ptr[i] = value; > > +} > > Do we ever plan on using this for values other than '-1'?
It's probably too general for the fd purpose here only. > > > + > > +/* Initialize an array of file descriptors to -1 */ > > +# define VIR_INIT_N_FD(ptr, count) \ > > + vir_init_n_int(ptr, count, -1) > > Could also be spelled: > > memset(ptr, -1, sizeof(*ptr) * count)) > > which goes back to why we need vir_init_n_int(). Also this would be possible. > > I agree that the fix to qemu_hotplug.c to not close fd 0 on failure is > needed, but am not sure about the complexity of the virfile.h addition. > So a simple memset() would do? Having a macro for VIR_ALLOC_N_FD() would probably be too much, eh? Stefan
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list