Ticket #5679: libs_libmyth-check-return.patch
File libs_libmyth-check-return.patch, 15.2 KB (added by , 16 years ago) |
---|
-
mythplugins/mythgallery/mythgallery/iconview.cpp
Some return values are not checked in libmyth From: Erik Hovland <erik@hovland.org> --- mythplugins/mythgallery/mythgallery/iconview.cpp | 4 mythtv/libs/libmyth/mediamonitor-unix.cpp | 3 mythtv/libs/libmyth/mythcdrom-freebsd.cpp | 2 mythtv/libs/libmyth/mythcdrom-linux.cpp | 12 + mythtv/libs/libmyth/mythhdd.cpp | 4 mythtv/libs/libmyth/mythmedia.cpp | 184 +++++++++++----------- mythtv/libs/libmyth/mythmedia.h | 3 mythtv/libs/libmyth/mythmediamonitor.cpp | 6 - 8 files changed, 113 insertions(+), 105 deletions(-) diff --git a/mythplugins/mythgallery/mythgallery/iconview.cpp b/mythplugins/mythgallery/mythgallery/iconview.cpp index 533263b..c1d9ba9 100644
a b void IconView::SetupMediaMonitor(void) 317 317 MediaMonitor *mon = MediaMonitor::GetMediaMonitor(); 318 318 if (m_currDevice && mon && mon->ValidateAndLock(m_currDevice)) 319 319 { 320 bool mounted = m_currDevice->isMounted( true);320 bool mounted = m_currDevice->isMounted(); 321 321 if (!mounted) 322 322 mounted = m_currDevice->mount(); 323 323 … … bool IconView::HandleMediaDeviceSelect(ThumbItem *item) 460 460 { 461 461 m_currDevice = item->GetMediaDevice(); 462 462 463 if (!m_currDevice->isMounted( ))463 if (!m_currDevice->isMounted(false)) 464 464 m_currDevice->mount(); 465 465 466 466 item->SetPath(m_currDevice->getMountPath(), true); -
mythtv/libs/libmyth/mediamonitor-unix.cpp
diff --git a/mythtv/libs/libmyth/mediamonitor-unix.cpp b/mythtv/libs/libmyth/mediamonitor-unix.cpp index 3b739ce..47b5ad6 100644
a b bool MediaMonitorUnix::CheckMountable(void) 161 161 sysfs.cd(*it); 162 162 163 163 QFile removable(sysfs.absFilePath("removable")); 164 if (removable.exists() )164 if (removable.exists() && removable.open(QIODevice::ReadOnly)) 165 165 { 166 removable.open(QIODevice::ReadOnly);167 166 int c = removable.getch(); 168 167 removable.close(); 169 168 -
mythtv/libs/libmyth/mythcdrom-freebsd.cpp
diff --git a/mythtv/libs/libmyth/mythcdrom-freebsd.cpp b/mythtv/libs/libmyth/mythcdrom-freebsd.cpp index 0570a14..2c4b14d 100644
a b MediaError MythCDROMFreeBSD::testMedia() 54 54 if (errno == EBUSY) 55 55 { 56 56 //cout << "errno == EBUSY" << endl; 57 return isMounted( true) ? MEDIAERR_OK : MEDIAERR_FAILED;57 return isMounted() ? MEDIAERR_OK : MEDIAERR_FAILED; 58 58 } 59 59 else 60 60 { -
mythtv/libs/libmyth/mythcdrom-linux.cpp
diff --git a/mythtv/libs/libmyth/mythcdrom-linux.cpp b/mythtv/libs/libmyth/mythcdrom-linux.cpp index 598a325..965d83b 100644
a b MediaError MythCDROMLinux::testMedia() 327 327 VERBOSE(VB_MEDIA+VB_EXTRA, LOC + ":testMedia - failed to open " 328 328 + getDevicePath() + ENO); 329 329 if (errno == EBUSY) 330 return isMounted( true) ? MEDIAERR_OK : MEDIAERR_FAILED;330 return isMounted() ? MEDIAERR_OK : MEDIAERR_FAILED; 331 331 else 332 332 return MEDIAERR_FAILED; 333 333 } … … MediaStatus MythCDROMLinux::checkMedia() 387 387 return m_Status; 388 388 // If the disc is ok and we already know it's mediatype 389 389 // returns MOUNTED. 390 if (isMounted( true))390 if (isMounted()) 391 391 return setStatus(MEDIASTAT_MOUNTED, OpenedHere); 392 392 break; 393 393 case CDS_TRAY_OPEN: … … MediaStatus MythCDROMLinux::checkMedia() 448 448 449 449 // the base class's onDeviceMounted will do fine 450 450 // grained detection of the type of data on this disc 451 if (isMounted( true))451 if (isMounted()) 452 452 onDeviceMounted(); 453 453 else 454 454 if (mount()) … … MediaStatus MythCDROMLinux::checkMedia() 456 456 else 457 457 return setStatus(MEDIASTAT_ERROR, OpenedHere); 458 458 459 if (isMounted( true))459 if (isMounted()) 460 460 { 461 461 // pretend we're NOTMOUNTED so setStatus emits 462 462 // a signal … … MediaStatus MythCDROMLinux::checkMedia() 488 488 return setStatus(MEDIASTAT_USEABLE, OpenedHere); 489 489 #else 490 490 mount(); 491 if (isMounted( true))491 if (isMounted()) 492 492 { 493 493 // pretend we're NOTMOUNTED so setStatus 494 494 // emits a signal … … MediaStatus MythCDROMLinux::checkMedia() 528 528 VERBOSE(VB_MEDIA, QString("Current status == ") + 529 529 MythMediaDevice::MediaStatusStrings[m_Status]); 530 530 VERBOSE(VB_MEDIA, "Setting status to not mounted?"); 531 if (isMounted( true))531 if (isMounted()) 532 532 setStatus(MEDIASTAT_MOUNTED, OpenedHere); 533 533 else 534 534 setStatus(MEDIASTAT_NOTMOUNTED, OpenedHere); -
mythtv/libs/libmyth/mythhdd.cpp
diff --git a/mythtv/libs/libmyth/mythhdd.cpp b/mythtv/libs/libmyth/mythhdd.cpp index 33cbbe6..86f2018 100644
a b MythHDD::MythHDD(QObject *par, const char *DevicePath, 31 31 */ 32 32 MediaStatus MythHDD::checkMedia(void) 33 33 { 34 if (isMounted( true))34 if (isMounted()) 35 35 { 36 36 // A lazy way to present volume name for the user to eject. 37 37 // Hotplug devices are usually something like /media/VOLUME … … MediaStatus MythHDD::checkMedia(void) 46 46 { 47 47 // a removable device was just plugged in try to mount it. 48 48 mount(); 49 if (isMounted( true))49 if (isMounted()) 50 50 { 51 51 m_Status = MEDIASTAT_NOTMOUNTED; 52 52 return setStatus(MEDIASTAT_MOUNTED); -
mythtv/libs/libmyth/mythmedia.cpp
diff --git a/mythtv/libs/libmyth/mythmedia.cpp b/mythtv/libs/libmyth/mythmedia.cpp index 9def5d0..58e1e1e 100644
a b bool MythMediaDevice::isDeviceOpen() const 99 99 return (m_DeviceHandle >= 0) ? true : false; 100 100 } 101 101 102 /// \brief Looks through the mounts file to file in the m_MountPath 103 /// from the m_DevicePath value. 104 bool MythMediaDevice::findMountPath() 105 { 106 if (m_DevicePath.isEmpty()) 107 { 108 VERBOSE(VB_MEDIA, LOC + ":findMountPath() - logic error, no device path"); 109 return false; 110 } 111 112 QFile mountFile(PATHTO_MOUNTS); 113 114 // Try to open the mounts file so we can search it for our device. 115 if (!mountFile.open(QIODevice::ReadOnly)) 116 return false; 117 118 QString debug; 119 QTextStream stream(&mountFile); 120 121 for (;;) 122 { 123 QString mountPoint; 124 QString deviceName; 125 126 // Extract the mount point and device name. 127 stream >> deviceName >> mountPoint; 128 stream.readLine(); // skip the rest of the line 129 130 if (deviceName.isNull()) 131 break; 132 133 if (deviceName.isEmpty()) 134 continue; 135 136 if (!deviceName.startsWith("/dev/")) 137 continue; 138 139 QStringList deviceNames(deviceName); 140 141 142 // Get some basic info on the device name, if it looks like a path 143 QFileInfo fi(deviceName); 144 QString link = QString::null; 145 146 // If the device name in the mounts file is a symlink, follow it.. 147 if (fi.isSymLink() && !(link = fi.readLink()).isEmpty()) 148 { 149 if (link[0] == '/') // absolute link 150 deviceNames.push_back(link); 151 else // relative link.. 152 deviceNames.push_back(fi.dir(true).absPath() + "/" + link); 153 } 154 155 // Deal with escaped spaces 156 if (mountPoint.contains("\\040")) 157 mountPoint.replace("\\040", " "); 158 159 if (deviceNames.contains(m_DevicePath) || 160 deviceNames.contains(m_RealDevice)) 161 { 162 m_MountPath = mountPoint; 163 mountFile.close(); 164 return true; 165 } 166 167 if (print_verbose_messages & VB_MEDIA) 168 debug += QString(" %1 | %2\n") 169 .arg(deviceName, 16).arg(mountPoint); 170 } 171 172 mountFile.close(); 173 174 if (print_verbose_messages & VB_MEDIA) 175 { 176 debug = LOC + ":findMountPath() - mount of '" 177 + m_DevicePath + "' not found.\n" 178 + " Device name/type | Current mountpoint\n" 179 + " -----------------+-------------------\n" 180 + debug 181 + " =================+==================="; 182 VERBOSE(VB_MEDIA, debug); 183 } 184 185 return false; 186 } 187 102 188 bool MythMediaDevice::performMountCmd(bool DoMount) 103 189 { 104 if (DoMount && isMounted( true))190 if (DoMount && isMounted()) 105 191 { 106 192 VERBOSE(VB_MEDIA, "MythMediaDevice::performMountCmd(true)" 107 193 " - Logic Error? Device already mounted."); … … bool MythMediaDevice::performMountCmd(bool DoMount) 133 219 { 134 220 // we cannot tell beforehand what the pmount mount point is 135 221 // so verify the mount status of the device 136 isMounted(true); 222 if (!findMountPath()) 223 { 224 VERBOSE(VB_MEDIA, "No mount path to media found"); 225 return false; 226 } 137 227 m_Status = MEDIASTAT_MOUNTED; 138 228 onDeviceMounted(); 139 229 VERBOSE(VB_GENERAL, … … bool MythMediaDevice::performMountCmd(bool DoMount) 141 231 } 142 232 else 143 233 onDeviceUnmounted(); 234 144 235 return true; 145 236 } 146 237 else 147 {148 238 VERBOSE(VB_GENERAL, QString("Failed to mount %1.") 149 239 .arg(m_DevicePath)); 150 }151 240 } 152 241 else 153 242 { … … bool MythMediaDevice::performMountCmd(bool DoMount) 163 252 } 164 253 else 165 254 onDeviceUnmounted(); 255 166 256 return true; 167 257 } 168 258 return false; … … bool MythMediaDevice::isMounted(bool Verify) 325 415 if (!Verify) 326 416 return (m_Status == MEDIASTAT_MOUNTED); 327 417 328 if (m_DevicePath.isEmpty()) 329 { 330 VERBOSE(VB_MEDIA, LOC + ":isMounted() - logic error, no device path"); 331 return false; 332 } 333 334 QFile mountFile(PATHTO_MOUNTS); 335 336 // Try to open the mounts file so we can search it for our device. 337 if (!mountFile.open(QIODevice::ReadOnly)) 338 return false; 339 340 QString debug; 341 QTextStream stream(&mountFile); 342 343 for (;;) 344 { 345 QString mountPoint; 346 QString deviceName; 347 348 349 // Extract the mount point and device name. 350 stream >> deviceName >> mountPoint; 351 stream.readLine(); // skip the rest of the line 352 353 if (deviceName.isNull()) 354 break; 355 356 if (deviceName.isEmpty()) 357 continue; 358 359 if (!deviceName.startsWith("/dev/")) 360 continue; 361 362 QStringList deviceNames(deviceName); 363 364 365 // Get some basic info on the device name, if it looks like a path 366 QFileInfo fi(deviceName); 367 QString link = QString::null; 368 369 // If the device name in the mounts file is a symlink, follow it.. 370 if (fi.isSymLink() && !(link = fi.readLink()).isEmpty()) 371 { 372 if (link[0] == '/') // absolute link 373 deviceNames.push_back(link); 374 else // relative link.. 375 deviceNames.push_back(fi.dir(true).absPath() + "/" + link); 376 } 377 378 379 // Deal with escaped spaces 380 if (mountPoint.contains("\\040")) 381 mountPoint.replace("\\040", " "); 382 383 384 if (deviceNames.contains(m_DevicePath) || 385 deviceNames.contains(m_RealDevice) ) 386 { 387 m_MountPath = mountPoint; 388 mountFile.close(); 389 return true; 390 } 391 392 if (print_verbose_messages & VB_MEDIA) 393 debug += QString(" %1 | %2\n") 394 .arg(deviceName, 16).arg(mountPoint); 395 } 396 397 mountFile.close(); 398 399 if (print_verbose_messages & VB_MEDIA) 400 { 401 debug = LOC + ":isMounted() - mount of '" 402 + m_DevicePath + "' not found.\n" 403 + " Device name/type | Current mountpoint\n" 404 + " -----------------+-------------------\n" 405 + debug 406 + " =================+==================="; 407 VERBOSE(VB_MEDIA, debug); 408 } 409 410 return false; 418 return findMountPath(); 411 419 } 412 420 413 421 MediaStatus MythMediaDevice::setStatus( MediaStatus NewStatus, bool CloseIt ) … … MediaStatus MythMediaDevice::setStatus( MediaStatus NewStatus, bool CloseIt ) 427 435 case MEDIASTAT_OPEN: 428 436 case MEDIASTAT_NODISK: 429 437 case MEDIASTAT_NOTMOUNTED: 430 if (isMounted( true))438 if (isMounted()) 431 439 unmount(); 432 440 break; 433 441 case MEDIASTAT_UNKNOWN: -
mythtv/libs/libmyth/mythmedia.h
diff --git a/mythtv/libs/libmyth/mythmedia.h b/mythtv/libs/libmyth/mythmedia.h index e34fa40..6d82b21 100644
a b class MPUBLIC MythMediaDevice : public QObject 98 98 virtual MediaError lock(); 99 99 virtual MediaError unlock(); 100 100 virtual bool performMountCmd( bool DoMount ); 101 virtual bool findMountPath(); 101 102 102 103 bool mount() { return performMountCmd(true); } 103 104 bool unmount() { return performMountCmd(false); } 104 bool isMounted(bool bVerify = false);105 bool isMounted(bool bVerify = true); 105 106 106 107 void RegisterMediaExtensions(uint mediatype, 107 108 const QString& extensions); -
mythtv/libs/libmyth/mythmediamonitor.cpp
diff --git a/mythtv/libs/libmyth/mythmediamonitor.cpp b/mythtv/libs/libmyth/mythmediamonitor.cpp index 43cf725..c64b619 100644
a b QList<MythMediaDevice*> MediaMonitor::GetRemovable(bool showMounted) 125 125 // Caller can also request mounted drives to be listed (e.g. USB flash) 126 126 127 127 if (QString(typeid(**it).name()).contains("MythCDROM") || 128 (showMounted && (*it)->isMounted( )))128 (showMounted && (*it)->isMounted(false))) 129 129 drives.append(*it); 130 130 } 131 131 … … void MediaMonitor::AttemptEject(MythMediaDevice *device) 228 228 return; 229 229 } 230 230 231 if (device->isMounted( true))231 if (device->isMounted()) 232 232 { 233 233 VERBOSE(VB_MEDIA, QString("Disk %1 is mounted? Unmounting").arg(dev)); 234 234 device->unmount(); 235 235 236 if (device->isMounted( true))236 if (device->isMounted()) 237 237 { 238 238 ShowOkPopup(tr("Failed to unmount %1").arg(dev)); 239 239 return;