No functional change, preparation for later commits.
static int run(int argc, char *argv[]) {
_cleanup_(udev_rules_freep) UdevRules *rules = NULL;
- _cleanup_(udev_event_freep) UdevEvent *event = NULL;
+ _cleanup_(udev_event_unrefp) UdevEvent *event = NULL;
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
const char *devpath, *devname, *action;
int r;
static void test_event_spawn_core(bool with_pidfd, const char *cmd, char *result_buf, size_t buf_size) {
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
- _cleanup_(udev_event_freep) UdevEvent *event = NULL;
+ _cleanup_(udev_event_unrefp) UdevEvent *event = NULL;
ASSERT_OK_ERRNO(setenv("SYSTEMD_PIDFD", yes_no(with_pidfd), 1));
return NULL;
*event = (UdevEvent) {
+ .n_ref = 1,
.worker = worker,
.rtnl = worker ? sd_netlink_ref(worker->rtnl) : NULL,
.dev = sd_device_ref(dev),
return event;
}
-UdevEvent* udev_event_free(UdevEvent *event) {
+static UdevEvent* udev_event_free(UdevEvent *event) {
if (!event)
return NULL;
return mfree(event);
}
+DEFINE_TRIVIAL_REF_UNREF_FUNC(UdevEvent, udev_event, udev_event_free);
+
static int device_rename(sd_device *device, const char *name) {
_cleanup_free_ char *new_syspath = NULL;
const char *s;
typedef struct UdevWorker UdevWorker;
typedef struct UdevEvent {
+ unsigned n_ref;
+
UdevWorker *worker;
sd_netlink *rtnl;
-
sd_device *dev;
sd_device *dev_parent;
sd_device *dev_db_clone;
} UdevEvent;
UdevEvent* udev_event_new(sd_device *dev, UdevWorker *worker, EventMode mode);
-UdevEvent* udev_event_free(UdevEvent *event);
-DEFINE_TRIVIAL_CLEANUP_FUNC(UdevEvent*, udev_event_free);
+UdevEvent* udev_event_ref(UdevEvent *event);
+UdevEvent* udev_event_unref(UdevEvent *event);
+DEFINE_TRIVIAL_CLEANUP_FUNC(UdevEvent*, udev_event_unref);
int udev_event_execute_rules(UdevEvent *event, UdevRules *rules);
}
static int worker_process_device(UdevWorker *worker, sd_device *dev) {
- _cleanup_(udev_event_freep) UdevEvent *udev_event = NULL;
+ _cleanup_(udev_event_unrefp) UdevEvent *udev_event = NULL;
_cleanup_close_ int fd_lock = -EBADF;
int r;
}
int builtin_main(int argc, char *argv[], void *userdata) {
- _cleanup_(udev_event_freep) UdevEvent *event = NULL;
+ _cleanup_(udev_event_unrefp) UdevEvent *event = NULL;
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
UdevBuiltinCommand cmd;
int r;
int test_main(int argc, char *argv[], void *userdata) {
_cleanup_(udev_rules_freep) UdevRules *rules = NULL;
- _cleanup_(udev_event_freep) UdevEvent *event = NULL;
+ _cleanup_(udev_event_unrefp) UdevEvent *event = NULL;
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
sigset_t mask, sigmask_orig;
int r;