#include <errno.h>
#include <getopt.h>
-#include <signal.h>
#include "sd-device.h"
#include "sd-event.h"
#include "alloc-util.h"
#include "device-monitor-private.h"
+#include "device-private.h"
#include "device-util.h"
#include "fd-util.h"
#include "format-util.h"
#include "signal-util.h"
#include "string-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 Hashmap *arg_subsystem_filter = NULL;
static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device, void *userdata) {
- const char *action = NULL, *devpath = NULL, *subsystem = NULL;
+ DeviceAction action = _DEVICE_ACTION_INVALID;
+ const char *devpath = NULL, *subsystem = NULL;
MonitorNetlinkGroup group = PTR_TO_INT(userdata);
struct timespec ts;
assert(device);
assert(IN_SET(group, MONITOR_GROUP_UDEV, MONITOR_GROUP_KERNEL));
- (void) sd_device_get_property_value(device, "ACTION", &action);
+ (void) device_get_action(device, &action);
(void) sd_device_get_devpath(device, &devpath);
(void) sd_device_get_subsystem(device, &subsystem);
printf("%-6s[%"PRI_TIME".%06"PRI_NSEC"] %-8s %s (%s)\n",
group == MONITOR_GROUP_UDEV ? "UDEV" : "KERNEL",
ts.tv_sec, (nsec_t)ts.tv_nsec/1000,
- action, devpath, subsystem);
+ strna(device_action_to_string(action)),
+ devpath, subsystem);
if (arg_show_property) {
const char *key, *value;
slash = strchr(optarg, '/');
if (slash) {
- devtype = strdup(devtype + 1);
+ devtype = strdup(slash + 1);
if (!devtype)
return -ENOMEM;
- subsystem = strndup(optarg, devtype - optarg);
+ subsystem = strndup(optarg, slash - optarg);
} else
subsystem = strdup(optarg);
subsystem = devtype = NULL;
break;
}
- case 't': {
- _cleanup_free_ char *tag = NULL;
-
- r = set_ensure_allocated(&arg_tag_filter, &string_hash_ops);
- if (r < 0)
- return r;
-
- tag = strdup(optarg);
- if (!tag)
- return -ENOMEM;
-
- r = set_put(arg_tag_filter, tag);
+ 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);
if (r < 0)
return r;
-
- tag = NULL;
break;
- }
+
case 'V':
return print_version();
case 'h':
if (r <= 0)
goto finalize;
+ if (running_in_chroot() > 0) {
+ log_info("Running in chroot, ignoring request.");
+ return 0;
+ }
+
/* Callers are expecting to see events as they happen: Line buffering */
setlinebuf(stdout);
finalize:
hashmap_free_free_free(arg_subsystem_filter);
- set_free_free(arg_tag_filter);
+ set_free(arg_tag_filter);
return r;
}