]> xenbits.xensource.com Git - libvirt.git/commitdiff
network: use g_strdup instead of VIR_STRDUP
authorJán Tomko <jtomko@redhat.com>
Sun, 20 Oct 2019 11:49:46 +0000 (13:49 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 21 Oct 2019 10:51:57 +0000 (12:51 +0200)
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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/network/bridge_driver.c
src/network/leaseshelper.c

index 9dce161937b0384484474c27471bf5d7740d22dd..fcaa6a48ae1c2becc62790adb0db5113aaaab077 100644 (file)
@@ -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;
 
index 959162b81448519b65cc9cecc57631c47707bb89..93dd2ca48a9523b1a5625215a863bfa42c1d348a 100644 (file)
@@ -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)