From 1c9dc18c3512499cee97c9e2f5c60fb8cba540a4 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Sun, 20 Oct 2019 03:34:46 -0500 Subject: hscript: DiskId: use devnum instead of syspath (thx @sroracle) --- hscript/disk.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/hscript/disk.cc b/hscript/disk.cc index 890ff34..137d3cf 100644 --- a/hscript/disk.cc +++ b/hscript/disk.cc @@ -15,6 +15,7 @@ #include #include #ifdef HAS_INSTALL_ENV +# include /* assert */ # include /* blkid_get_tag_value */ # include /* udev_* */ # include /* mount */ @@ -76,8 +77,15 @@ bool DiskId::execute(ScriptOptions options) const { struct udev *udev; struct udev_device *device; const char *serial; - /* XXX this is *horrible* */ - const char *syspath = ("/sys/block/" + _block.substr(5)).c_str(); + struct stat blk_stat; + const char *block_c = _block.c_str(); + if(stat(block_c, &blk_stat) != 0) { + output_error("installfile:" + std::to_string(line), + "diskid: error opening device " + _block, + strerror(errno)); + return false; + } + assert(S_ISBLK(blk_stat.st_mode)); udev = udev_new(); if(!udev) { @@ -86,7 +94,7 @@ bool DiskId::execute(ScriptOptions options) const { "cannot read disk information"); return false; } - device = udev_device_new_from_syspath(udev, syspath); + device = udev_device_new_from_devnum(udev, 'b', blk_stat.st_rdev); if(!device) { udev_unref(udev); output_error("installfile:" + std::to_string(line), -- cgit v1.2.3-60-g2f50