mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
udev: modernize udev-builtin-btrfs a bit
Let's in particular log an even if a device name is too long for the btrfs ioctl structure, instead of truncating it (which could theoretically reference a different device).
This commit is contained in:
@@ -14,14 +14,12 @@
|
||||
|
||||
static int builtin_btrfs(UdevEvent *event, int argc, char *argv[]) {
|
||||
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
struct btrfs_ioctl_vol_args args = {};
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
int r;
|
||||
|
||||
if (argc != 3 || !streq(argv[1], "ready"))
|
||||
return log_device_error_errno(dev, SYNTHETIC_ERRNO(EINVAL), "Invalid arguments");
|
||||
|
||||
fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC|O_NOCTTY);
|
||||
_cleanup_close_ int fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC|O_NOCTTY);
|
||||
if (fd < 0) {
|
||||
if (ERRNO_IS_DEVICE_ABSENT(errno)) {
|
||||
/* Driver not installed? Then we aren't ready. This is useful in initrds that lack
|
||||
@@ -34,7 +32,11 @@ static int builtin_btrfs(UdevEvent *event, int argc, char *argv[]) {
|
||||
return log_device_debug_errno(dev, errno, "Failed to open /dev/btrfs-control: %m");
|
||||
}
|
||||
|
||||
strscpy(args.name, sizeof(args.name), argv[2]);
|
||||
struct btrfs_ioctl_vol_args args = {};
|
||||
if (strlen(argv[2]) >= sizeof(args.name))
|
||||
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL), "Device name too long for BTRFS_IOC_DEVICES_READY call: %s", argv[2]);
|
||||
|
||||
strncpy(args.name, argv[2], sizeof(args.name));
|
||||
r = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
|
||||
if (r < 0)
|
||||
return log_device_debug_errno(dev, errno, "Failed to call BTRFS_IOC_DEVICES_READY: %m");
|
||||
|
||||
Reference in New Issue
Block a user