Commit 75050f6a authored by Àlex Fiestas's avatar Àlex Fiestas
Browse files

Always return an object if the device was of interest when added

Finally this nasty gets fixed, problem is easy:
-Udev calls deviceAdded
-We emit deviceAdded
-Device becomes invalid (in udev)
-UdevManager::createDevice is called, returns 0
-deviceRemoved is emit
-Q_ASSERT explodes because we returned 0.

This patch basically ensures that if the device was of interest when
deviceAdded was called a UdevDevice object is always returned even if
the device is dummy. That's the best we can do.

BUG: 302243
FIXED-IN: 4.11
parent efef7c9b
......@@ -38,11 +38,14 @@ public:
Private();
~Private();
bool isOfInterest(const UdevQt::Device &device);
bool isOfInterest(const QString &udi, const UdevQt::Device &device);
bool checkOfInterest(const UdevQt::Device &device);
bool isPowerBubtton(const UdevQt::Device &device);
bool isLidBubtton(const UdevQt::Device &device);
UdevQt::Client *m_client;
QStringList m_devicesOfInterest;
QSet<Solid::DeviceInterface::Type> m_supportedInterfaces;
};
......@@ -65,7 +68,21 @@ UDevManager::Private::~Private()
delete m_client;
}
bool UDevManager::Private::isOfInterest(const UdevQt::Device &device)
bool UDevManager::Private::isOfInterest(const QString &udi, const UdevQt::Device &device)
{
if (m_devicesOfInterest.contains(udi)) {
return true;
}
bool isOfInterest = checkOfInterest(device);
if (isOfInterest) {
m_devicesOfInterest.append(udi);
}
return isOfInterest;
}
bool UDevManager::Private::checkOfInterest(const UdevQt::Device &device)
{
#ifdef UDEV_DETAILED_OUTPUT
qDebug() << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";
......@@ -183,7 +200,7 @@ QStringList UDevManager::allDevices()
QStringList res;
const UdevQt::DeviceList deviceList = d->m_client->allDevices();
foreach (const UdevQt::Device &device, deviceList) {
if (d->isOfInterest(device)) {
if (d->isOfInterest(udiPrefix() + device.sysfsPath(), device)) {
res << udiPrefix() + device.sysfsPath();
}
}
......@@ -228,24 +245,28 @@ QObject *UDevManager::createDevice(const QString &udi_)
device->setIcon("computer");
return device;
}
const QString udi = udi_.right(udi_.size() - udiPrefix().size());
UdevQt::Device device = d->m_client->deviceBySysfsPath(udi);
if (d->isOfInterest(device) || QFile::exists(udi)) {
if (d->isOfInterest(udi_, device) || QFile::exists(udi)) {
return new UDevDevice(device);
}
return 0;
}
void UDevManager::slotDeviceAdded(const UdevQt::Device &device)
{
if (d->isOfInterest(device)) {
if (d->isOfInterest(udiPrefix() + device.sysfsPath(), device)) {
emit deviceAdded(udiPrefix() + device.sysfsPath());
}
}
void UDevManager::slotDeviceRemoved(const UdevQt::Device &device)
{
if (d->isOfInterest(device)) {
if (d->isOfInterest(udiPrefix() + device.sysfsPath(), device)) {
emit deviceRemoved(udiPrefix() + device.sysfsPath());
d->m_devicesOfInterest.removeAll(udiPrefix() + device.sysfsPath());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment