[libvirt] [PATCHv2 24/27] build: don't hand-roll cloexec code

Eric Blake eblake at redhat.com
Wed Jul 13 23:47:38 UTC 2011


On 07/13/2011 07:22 AM, Matthias Bolte wrote:
> 2011/7/8 Eric Blake <eblake at redhat.com>:
>> No need to repeat common code.
>>
>> * src/util/bridge.c (brInit): Use virSetCloseExec.
>> (brSetInterfaceUp): Prefer unsigned flags.
>> * src/uml/uml_driver.c (umlSetCloseExec): Delete.
>> (umlStartVMDaemon): Use util version instead.
>> ---
>>
>> v2: new patch

I've pushed 20-23.

>> -
>> -    if (VIR_ALLOC(*ctlp) < 0) {
>> +    if (fd < 0 ||
>> +        virSetCloseExec(fd) < 0 ||
>> +        VIR_ALLOC(*ctlp) < 0) {
>>         VIR_FORCE_CLOSE(fd);
>> -        return ENOMEM;
>> +        return errno;
>>     }
> 
> Is it guaranteed that calloc will set ENOMEM, or do we need some
> gnulib module to guarantee this?

Well what do you know.  We need to import 'calloc-posix' to get that to
happen on mingw.  :)

> 
>>     (*ctlp)->fd = fd;
>> @@ -599,7 +590,7 @@ brSetInterfaceUp(brControl *ctl,
>>                  int up)
>>  {
>>     struct ifreq ifr;
>> -    int flags;
>> +    unsigned int flags;
> 
> flags is used used with ifr.ifr_flags that is signed (actually it's a
> short). So I'd prefer renaming it to ifflags and keep it as int.
> 
> ACK, with that questions/comments answered/addressed.

Here's what I squashed in before pushing.

diff --git i/bootstrap.conf w/bootstrap.conf
index 3c3d0e0..2fc457e 100644
--- i/bootstrap.conf
+++ w/bootstrap.conf
@@ -27,6 +27,7 @@ byteswap
 c-ctype
 c-strcase
 c-strcasestr
+calloc-posix
 canonicalize-lgpl
 chown
 close
diff --git i/src/util/bridge.c w/src/util/bridge.c
index a6b5768..0f4b639 100644
--- i/src/util/bridge.c
+++ w/src/util/bridge.c
@@ -590,7 +590,7 @@ brSetInterfaceUp(brControl *ctl,
                  int up)
 {
     struct ifreq ifr;
-    unsigned int flags;
+    int ifflags;

     if (!ctl || !ifname)
         return EINVAL;
@@ -603,10 +603,10 @@ brSetInterfaceUp(brControl *ctl,
     if (ioctl(ctl->fd, SIOCGIFFLAGS, &ifr) < 0)
         return errno;

-    flags = up ? (ifr.ifr_flags | IFF_UP) : (ifr.ifr_flags & ~IFF_UP);
+    ifflags = up ? (ifr.ifr_flags | IFF_UP) : (ifr.ifr_flags & ~IFF_UP);

-    if (ifr.ifr_flags != flags) {
-        ifr.ifr_flags = flags;
+    if (ifr.ifr_flags != ifflags) {
+        ifr.ifr_flags = ifflags;

         if (ioctl(ctl->fd, SIOCSIFFLAGS, &ifr) < 0)
             return errno;


-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110713/33443851/attachment-0001.sig>


More information about the libvir-list mailing list