[libvirt] [PATCH 19/34] network: use g_strdup instead of VIR_STRDUP

Ján Tomko jtomko at redhat.com
Sun Oct 20 12:55:37 UTC 2019


Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/network/bridge_driver.c | 49 ++++++++++++-------------------------
 src/network/leaseshelper.c  |  6 ++---
 2 files changed, 18 insertions(+), 37 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 9dce161937..fcaa6a48ae 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -739,19 +739,12 @@ networkStateInitialize(bool privileged,
      * /etc/libvirt/... && /var/(run|lib)/libvirt/... (system/privileged).
      */
     if (privileged) {
-        if (VIR_STRDUP(network_driver->networkConfigDir,
-                       SYSCONFDIR "/libvirt/qemu/networks") < 0 ||
-            VIR_STRDUP(network_driver->networkAutostartDir,
-                       SYSCONFDIR "/libvirt/qemu/networks/autostart") < 0 ||
-            VIR_STRDUP(network_driver->stateDir,
-                       RUNSTATEDIR "/libvirt/network") < 0 ||
-            VIR_STRDUP(network_driver->pidDir,
-                       RUNSTATEDIR "/libvirt/network") < 0 ||
-            VIR_STRDUP(network_driver->dnsmasqStateDir,
-                       LOCALSTATEDIR "/lib/libvirt/dnsmasq") < 0 ||
-            VIR_STRDUP(network_driver->radvdStateDir,
-                       LOCALSTATEDIR "/lib/libvirt/radvd") < 0)
-            goto error;
+        network_driver->networkConfigDir = g_strdup(SYSCONFDIR "/libvirt/qemu/networks");
+        network_driver->networkAutostartDir = g_strdup(SYSCONFDIR "/libvirt/qemu/networks/autostart");
+        network_driver->stateDir = g_strdup(RUNSTATEDIR "/libvirt/network");
+        network_driver->pidDir = g_strdup(RUNSTATEDIR "/libvirt/network");
+        network_driver->dnsmasqStateDir = g_strdup(LOCALSTATEDIR "/lib/libvirt/dnsmasq");
+        network_driver->radvdStateDir = g_strdup(LOCALSTATEDIR "/lib/libvirt/radvd");
     } else {
         configdir = virGetUserConfigDirectory();
         rundir = virGetUserRuntimeDirectory();
@@ -2817,8 +2810,7 @@ networkCreateInterfacePool(virNetworkDefPtr netdef)
         case VIR_NETWORK_FORWARD_VEPA:
         case VIR_NETWORK_FORWARD_PASSTHROUGH:
             if (thisName) {
-                if (VIR_STRDUP(thisIf->device.dev, thisName) < 0)
-                    goto cleanup;
+                thisIf->device.dev = g_strdup(thisName);
                 thisIf->type = VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV;
                 netdef->forward.nifs++;
             } else {
@@ -4437,19 +4429,14 @@ networkGetDHCPLeases(virNetworkPtr net,
                 }
             }
 
-            if ((VIR_STRDUP(lease->mac, mac_tmp) < 0) ||
-                (VIR_STRDUP(lease->ipaddr, ip_tmp) < 0) ||
-                (VIR_STRDUP(lease->iface, def->bridge) < 0))
-                goto error;
+            lease->mac = g_strdup(mac_tmp);
+            lease->ipaddr = g_strdup(ip_tmp);
+            lease->iface = g_strdup(def->bridge);
 
             /* Fields that can be NULL */
-            if ((VIR_STRDUP(lease->iaid,
-                            virJSONValueObjectGetString(lease_tmp, "iaid")) < 0) ||
-                (VIR_STRDUP(lease->clientid,
-                            virJSONValueObjectGetString(lease_tmp, "client-id")) < 0) ||
-                (VIR_STRDUP(lease->hostname,
-                            virJSONValueObjectGetString(lease_tmp, "hostname")) < 0))
-                goto error;
+            lease->iaid = g_strdup(virJSONValueObjectGetString(lease_tmp, "iaid"));
+            lease->clientid = g_strdup(virJSONValueObjectGetString(lease_tmp, "client-id"));
+            lease->hostname = g_strdup(virJSONValueObjectGetString(lease_tmp, "hostname"));
 
             if (VIR_INSERT_ELEMENT(leases_ret, nleases, nleases, lease) < 0)
                 goto error;
@@ -4622,8 +4609,7 @@ networkAllocatePort(virNetworkObjPtr obj,
          */
         port->plugtype = VIR_NETWORK_PORT_PLUG_TYPE_NETWORK;
 
-        if (VIR_STRDUP(port->plug.bridge.brname, netdef->bridge) < 0)
-            goto cleanup;
+        port->plug.bridge.brname = g_strdup(netdef->bridge);
         port->plug.bridge.macTableManager = netdef->macTableManager;
 
         if (port->virtPortProfile) {
@@ -4686,8 +4672,7 @@ networkAllocatePort(virNetworkObjPtr obj,
              */
 
             port->plugtype = VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE;
-            if (VIR_STRDUP(port->plug.bridge.brname, netdef->bridge) < 0)
-                goto cleanup;
+            port->plug.bridge.brname = g_strdup(netdef->bridge);
             port->plug.bridge.macTableManager = netdef->macTableManager;
 
             if (port->virtPortProfile) {
@@ -4791,9 +4776,7 @@ networkAllocatePort(virNetworkObjPtr obj,
                                netdef->name);
                 goto cleanup;
             }
-            if (VIR_STRDUP(port->plug.direct.linkdev,
-                           dev->device.dev) < 0)
-                goto cleanup;
+            port->plug.direct.linkdev = g_strdup(dev->device.dev);
         }
         break;
 
diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c
index 959162b814..93dd2ca48a 100644
--- a/src/network/leaseshelper.c
+++ b/src/network/leaseshelper.c
@@ -151,16 +151,14 @@ main(int argc, char **argv)
         clientid = argv[2];
     }
 
-    if (VIR_STRDUP(server_duid, getenv("DNSMASQ_SERVER_DUID")) < 0)
-        goto cleanup;
+    server_duid = g_strdup(getenv("DNSMASQ_SERVER_DUID"));
 
     if (virAsprintf(&custom_lease_file,
                     LOCALSTATEDIR "/lib/libvirt/dnsmasq/%s.status",
                     interface) < 0)
         goto cleanup;
 
-    if (VIR_STRDUP(pid_file, RUNSTATEDIR "/leaseshelper.pid") < 0)
-        goto cleanup;
+    pid_file = g_strdup(RUNSTATEDIR "/leaseshelper.pid");
 
     /* Try to claim the pidfile, exiting if we can't */
     if ((pid_file_fd = virPidFileAcquirePath(pid_file, false, getpid())) < 0)
-- 
2.21.0




More information about the libvir-list mailing list