[libvirt] [PATCH] bye to close(), welcome to VIR_(FORCE_)CLOSE()

Stefan Berger stefanb at us.ibm.com
Fri Oct 22 19:48:28 UTC 2010


libvir-list-bounces at redhat.com wrote on 10/22/2010 02:24:38 PM:


> On 10/22/2010 05:19 AM, Stefan Berger wrote:
> > Using automated replacement with sed and editing I have now replaced 
all
> > occurrences of close() with VIR_(FORCE_)CLOSE() except for one, of
> > course. Some replacements were straight forward, others I needed to 
pay
> > attention. I hope I payed attention in all the right places... Please
> > have a look. This should have at least solved one more double-close
> > error.
> >
> > Signed-off-by: Stefan Berger<stefanb at us.ibm.com>
> >
> > ---
> >   daemon/libvirtd.c                         |   46 ++++++---------
> 
> Continuing on (looks like I'll be replying quite a few times today)...
> 
> > @@ -127,7 +128,7 @@ static int lxcContainerExecInit(virDomai
> >   static int lxcContainerSetStdio(int control, int ttyfd)
> >   {
> >       int rc = -1;
> > -    int open_max, i;
> > +    int open_max, i, tpmfd;
> >
> >       if (setsid()<  0) {
> >           virReportSystemError(errno, "%s",
> > @@ -145,8 +146,10 @@ static int lxcContainerSetStdio(int cont
> >        * close all FDs before executing the container */
> >       open_max = sysconf (_SC_OPEN_MAX);
> >       for (i = 0; i<  open_max; i++)
> > -        if (i != ttyfd&&  i != control)
> > -            close(i);
> > +        if (i != ttyfd&&  i != control) {
> > +            tpmfd = i;
> > +            VIR_FORCE_CLOSE(tpmfd);
> 
> Yeah, I guess you do have to introduce a temporary rather than 
> clobbering your iterator.
> 
> s/tpmfd/tmpfd/, and perhaps reduce it's scope to just the for loop or if 

> statement where it is needed.

ha, what a typo...  making it a local variable.


> > -        close(logfd);
> > +    if (rc != 0)
> > +        VIR_FORCE_CLOSE(priv->monitor);
> > +    VIR_FORCE_CLOSE(parentTty);
> > +    VIR_FORCE_CLOSE(logfd);
> 
> logfd might be one where we want to hoist a normal VIR_CLOSE and check 
> for errors.

Ok, so I call the virReportSystemError() on this now.

   Stefan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20101022/295db900/attachment-0001.htm>


More information about the libvir-list mailing list