#include "hashmap.h"
#include "set.h"
#include "signal-util.h"
+#include "static-destruct.h"
#include "string-util.h"
+#include "time-util.h"
#include "udevadm.h"
#include "virt.h"
-#include "time-util.h"
static bool arg_show_property = false;
static bool arg_print_kernel = false;
static Set *arg_tag_filter = NULL;
static Hashmap *arg_subsystem_filter = NULL;
+STATIC_DESTRUCTOR_REGISTER(arg_tag_filter, set_freep);
+STATIC_DESTRUCTOR_REGISTER(arg_subsystem_filter, hashmap_freep);
+
static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device, void *userdata) {
sd_device_action_t action = _SD_DEVICE_ACTION_INVALID;
const char *devpath = NULL, *subsystem = NULL;
if (slash) {
devtype = strdup(slash + 1);
if (!devtype)
- return -ENOMEM;
+ return log_oom();
subsystem = strndup(optarg, slash - optarg);
} else
subsystem = strdup(optarg);
if (!subsystem)
- return -ENOMEM;
+ return log_oom();
- r = hashmap_ensure_put(&arg_subsystem_filter, NULL, subsystem, devtype);
+ r = hashmap_ensure_put(&arg_subsystem_filter, &trivial_hash_ops_free_free, subsystem, devtype);
if (r < 0)
- return r;
+ return log_oom();
TAKE_PTR(subsystem);
TAKE_PTR(devtype);
break;
}
case 't':
- /* optarg is stored in argv[], so we don't need to copy it */
- r = set_ensure_put(&arg_tag_filter, &string_hash_ops, optarg);
+ r = set_put_strdup(&arg_tag_filter, optarg);
if (r < 0)
- return r;
+ return log_oom();
break;
case 'V':
r = parse_argv(argc, argv);
if (r <= 0)
- goto finalize;
+ return r;
if (running_in_chroot() > 0) {
log_info("Running in chroot, ignoring request.");
setlinebuf(stdout);
r = sd_event_default(&event);
- if (r < 0) {
- log_error_errno(r, "Failed to initialize event: %m");
- goto finalize;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to initialize event: %m");
r = sd_event_set_signal_exit(event, true);
- if (r < 0) {
- log_error_errno(r, "Failed to install SIGINT/SIGTERM handling: %m");
- goto finalize;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to install SIGINT/SIGTERM handling: %m");
printf("monitor will print the received events for:\n");
if (arg_print_udev) {
r = setup_monitor(MONITOR_GROUP_UDEV, event, &udev_monitor);
if (r < 0)
- goto finalize;
+ return r;
printf("UDEV - the event which udev sends out after rule processing\n");
}
if (arg_print_kernel) {
r = setup_monitor(MONITOR_GROUP_KERNEL, event, &kernel_monitor);
if (r < 0)
- goto finalize;
+ return r;
printf("KERNEL - the kernel uevent\n");
}
printf("\n");
r = sd_event_loop(event);
- if (r < 0) {
- log_error_errno(r, "Failed to run event loop: %m");
- goto finalize;
- }
-
- r = 0;
-
-finalize:
- hashmap_free_free_free(arg_subsystem_filter);
- set_free(arg_tag_filter);
+ if (r < 0)
+ return log_error_errno(r, "Failed to run event loop: %m");
- return r;
+ return 0;
}