Using stat before open can be dangerous. Better to
From: Erik Hovland <erik@hovland.org>
do it the other way around.
---
mythplugins/mythvideo/mtd/dvdprobe.cpp | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/mythplugins/mythvideo/mtd/dvdprobe.cpp b/mythplugins/mythvideo/mtd/dvdprobe.cpp
index 2a999a4..6a06287 100644
a
|
b
|
|
19 | 19 | #include <cmath> |
20 | 20 | #include <climits> // for CDSL_CURRENT which is currently INT_MAX |
21 | 21 | |
| 22 | #include <QFile> |
| 23 | |
22 | 24 | #include "dvdprobe.h" |
23 | 25 | |
24 | 26 | #include <mythtv/mythcontext.h> |
… |
… |
bool DVDProbe::probe() |
414 | 416 | // a drive with media in it |
415 | 417 | // |
416 | 418 | |
417 | | struct stat fileinfo; |
| 419 | QFile dvdDevice((device.toAscii()).constData()); |
418 | 420 | |
419 | | QByteArray dev = device.toAscii(); |
420 | | int ret = stat(dev.constData(), &fileinfo); |
421 | | if (ret < 0) |
| 421 | if (!dvdDevice.exists() && !dvdDevice.open(QIODevice::ReadOnly)) |
422 | 422 | { |
423 | 423 | // |
424 | | // Can't even stat the device, it probably |
425 | | // doesn't exist. Silly user |
| 424 | // Device doesn't exists or can't be opened. The probe can't |
| 425 | // continue. |
426 | 426 | // |
427 | 427 | wipeClean(); |
428 | 428 | return false; |
… |
… |
bool DVDProbe::probe() |
435 | 435 | // this, but it seems to work. |
436 | 436 | // |
437 | 437 | |
438 | | int drive_handle = open(dev.constData(), O_RDONLY | O_NONBLOCK); |
| 438 | int drive_handle = dvdDevice.handle(); |
439 | 439 | |
440 | 440 | if (drive_handle == -1) |
441 | 441 | { |
… |
… |
bool DVDProbe::probe() |
461 | 461 | // 3 = not ready |
462 | 462 | // |
463 | 463 | wipeClean(); |
464 | | close(drive_handle); |
465 | 464 | return false; |
466 | 465 | |
467 | 466 | } |
468 | 467 | |
469 | 468 | status = ioctl(drive_handle, CDROM_MEDIA_CHANGED, NULL); |
470 | | close(drive_handle); |
471 | 469 | |
472 | 470 | if (!status) |
473 | 471 | { |
… |
… |
bool DVDProbe::probe() |
493 | 491 | // could be a path, file, whatever). |
494 | 492 | // |
495 | 493 | |
| 494 | dvdDevice.close(); |
496 | 495 | wipeClean(); |
497 | 496 | first_time = false; |
498 | | dvd = DVDOpen(dev.constData()); |
| 497 | dvd = DVDOpen(dvdDevice.fileName()); |
499 | 498 | if (dvd) |
500 | 499 | { |
501 | 500 | // |