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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




libvir-list-bounces@xxxxxxxxxx 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@xxxxxxxxxx>
> >
> > ---
> >   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
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]