/* This is similar to free_and_replace_full(), but NULL is not assigned to 'b', and its reference counter is
* increased. */
-#define unref_and_replace_full(a, b, ref_func, unref_func) \
- ({ \
- typeof(a)* _a = &(a); \
- typeof(b) _b = ref_func(b); \
- unref_func(*_a); \
- *_a = _b; \
- 0; \
+#define unref_and_replace_new_ref(a, b, ref_func, unref_func) \
+ ({ \
+ typeof(a)* _a = &(a); \
+ typeof(b) _b = ref_func(b); \
+ unref_func(*_a); \
+ *_a = _b; \
+ 0; \
})
#define _DEFINE_TRIVIAL_REF_FUNC(type, name, scope) \
int dhcp_lease_set_default_subnet_mask(sd_dhcp_lease *lease);
int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const sd_dhcp_client_id *client_id);
-#define dhcp_lease_unref_and_replace(a, b) \
- unref_and_replace_full(a, b, sd_dhcp_lease_ref, sd_dhcp_lease_unref)
+#define dhcp_lease_unref_and_replace_new_ref(a, b) \
+ unref_and_replace_new_ref(a, b, sd_dhcp_lease_ref, sd_dhcp_lease_unref)
dhcp_lease_set_timestamp(lease, timestamp);
- dhcp_lease_unref_and_replace(client->lease, lease);
+ dhcp_lease_unref_and_replace_new_ref(client->lease, lease);
if (client->lease->rapid_commit) {
log_dhcp_client(client, "ACK");
else
r = SD_DHCP_CLIENT_EVENT_IP_CHANGE;
- dhcp_lease_unref_and_replace(client->lease, lease);
+ dhcp_lease_unref_and_replace_new_ref(client->lease, lease);
log_dhcp_client(client, "ACK");
return r;
int sd_dhcp_client_attach_device(sd_dhcp_client *client, sd_device *dev) {
assert_return(client, -EINVAL);
- return device_unref_and_replace(client->dev, dev);
+ return device_unref_and_replace_new_ref(client->dev, dev);
}
static sd_dhcp_client* dhcp_client_free(sd_dhcp_client *client) {
int sd_dhcp6_client_attach_device(sd_dhcp6_client *client, sd_device *dev) {
assert_return(client, -EINVAL);
- return device_unref_and_replace(client->dev, dev);
+ return device_unref_and_replace_new_ref(client->dev, dev);
}
static sd_dhcp6_client *dhcp6_client_free(sd_dhcp6_client *client) {
#include "sd-forward.h"
#include "log.h"
-#define device_unref_and_replace(a, b) \
- unref_and_replace_full(a, b, sd_device_ref, sd_device_unref)
+#define device_unref_and_replace_new_ref(a, b) \
+ unref_and_replace_new_ref(a, b, sd_device_ref, sd_device_unref)
#define FOREACH_DEVICE_PROPERTY(device, key, value) \
for (const char *value, *key = sd_device_get_property_first(device, &value); \
if (r < 0)
return log_link_error_errno(link, r, "Failed to get DHCPv6 lease: %m");
- unref_and_replace_full(link->dhcp6_lease, lease, sd_dhcp6_lease_ref, sd_dhcp6_lease_unref);
+ unref_and_replace_new_ref(link->dhcp6_lease, lease, sd_dhcp6_lease_ref, sd_dhcp6_lease_unref);
link_dirty(link);
return 0;
/* Always replace with the new sd_device object. As the sysname (and possibly other properties
* or sysattrs) may be outdated. */
- device_unref_and_replace(link->dev, device);
+ device_unref_and_replace_new_ref(link->dev, device);
r = link_managed_by_us(link);
if (r <= 0)
return 0;
}
- return device_unref_and_replace(w->dev, action == SD_DEVICE_REMOVE ? NULL : device);
+ return device_unref_and_replace_new_ref(w->dev, action == SD_DEVICE_REMOVE ? NULL : device);
}
int manager_udev_process_rfkill(Manager *m, sd_device *device, sd_device_action_t action) {
return 0;
}
- return device_unref_and_replace(w->rfkill, action == SD_DEVICE_REMOVE ? NULL : device);
+ return device_unref_and_replace_new_ref(w->rfkill, action == SD_DEVICE_REMOVE ? NULL : device);
}
r = block_device_get_originating(dev_whole_disk, &dev_origin, /* recursive= */ false);
if (r >= 0)
- device_unref_and_replace(dev, dev_origin);
+ device_unref_and_replace_new_ref(dev, dev_origin);
else if (r != -ENOENT)
return r;
}
log_device_debug(event->dev, "SEQNUM=%" PRIu64 " blocked by SEQNUM=%" PRIu64,
event->seqnum, e->seqnum);
- unref_and_replace_full(event->blocker, e, event_ref, event_unref);
+ unref_and_replace_new_ref(event->blocker, e, event_ref, event_unref);
return;
}