aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2021-09-20 11:59:14 +0200
committerJavier <dev.git@javispedro.com>2021-09-20 11:59:14 +0200
commit263c1c8846b1f7aed8c3a563f76a5b90191611d9 (patch)
treeea8c7db23528e464825312f84417a53b1bd5675f
parentd805dfb9f9488db5fe19483021ca2dded8727e20 (diff)
downloadscribiu-263c1c8846b1f7aed8c3a563f76a5b90191611d9.tar.gz
scribiu-263c1c8846b1f7aed8c3a563f76a5b90191611d9.zip
fix crash when hot-unplugging pen
-rw-r--r--smartpenmanager.cc23
-rw-r--r--smartpenmanager.h1
2 files changed, 18 insertions, 6 deletions
diff --git a/smartpenmanager.cc b/smartpenmanager.cc
index 1eeb685..d375fea 100644
--- a/smartpenmanager.cc
+++ b/smartpenmanager.cc
@@ -197,9 +197,8 @@ void SmartpenManager::handleTimerNextTry()
void SmartpenManager::processDeviceAdded(udev_device *dev)
{
- uint busnum = atol(udev_device_get_sysattr_value(dev, "busnum"));
- uint devnum = atol(udev_device_get_sysattr_value(dev, "devnum"));
- Smartpen::Address addr(busnum, devnum);
+ Smartpen::Address addr = getDeviceAddress(dev);
+ if (!addr.first && !addr.second) return;
QString name = parseUdevEscapedString(udev_device_get_property_value(dev, "ID_MODEL_ENC"));
@@ -223,9 +222,8 @@ void SmartpenManager::processDeviceAdded(udev_device *dev)
void SmartpenManager::processDeviceRemoved(udev_device *dev)
{
- uint busnum = atol(udev_device_get_sysattr_value(dev, "busnum"));
- uint devnum = atol(udev_device_get_sysattr_value(dev, "devnum"));
- Smartpen::Address addr(busnum, devnum);
+ Smartpen::Address addr = getDeviceAddress(dev);
+ if (!addr.first && !addr.second) return;
qDebug() << "Device removed with address:" << addr;
@@ -325,3 +323,16 @@ QString SmartpenManager::parseUdevEscapedString(const char *s)
}
return r;
}
+
+Smartpen::Address SmartpenManager::getDeviceAddress(udev_device *dev)
+{
+ const char *busnumS = udev_device_get_property_value(dev, "BUSNUM");
+ const char *devnumS = udev_device_get_property_value(dev, "DEVNUM");
+ if (!busnumS || !devnumS) {
+ qWarning() << "Cannot find busnum/devnum env var for udev device";
+ return Smartpen::Address();
+ }
+ uint busnum = atol(busnumS);
+ uint devnum = atol(devnumS);
+ return Smartpen::Address(busnum, devnum);
+}
diff --git a/smartpenmanager.h b/smartpenmanager.h
index a823709..6a5e39f 100644
--- a/smartpenmanager.h
+++ b/smartpenmanager.h
@@ -61,6 +61,7 @@ private:
void scheduleNextTry();
static QString parseUdevEscapedString(const char *s);
+ static Smartpen::Address getDeviceAddress(udev_device *dev);
private:
udev *_udev;