Ticket #7212: 7212-v1.patch

File 7212-v1.patch, 2.8 KB (added by danielk, 10 years ago)

Possible fix

  • mythvideo/mtd/dvdprobe.cpp

     
    4747    }
    4848}
    4949
     50#define LOC_ERR  QString("dvdprobe.cpp, Error: ")
     51#define LOC_WARN QString("dvdprobe.cpp, Warning: ")
     52#define LOC      QString("dvdprobe.cpp: ")
     53
    5054DVDSubTitle::DVDSubTitle(int subtitle_id, const QString &a_language) :
    5155    id(subtitle_id), language(a_language.toUtf8())
    5256{
     
    431435    //  Before touching libdvdread stuff
    432436    //  (below), see if there's actually
    433437    //  a drive with media in it
    434     QFile dvdDevice(device);
    435     if (!dvdDevice.exists())
    436438    {
    437         //  Device doesn't exist. Silly user
    438         Reset();
    439         return false;
     439        QFile dvdDevice(device);
     440        if (!dvdDevice.exists())
     441        {
     442            //  Device doesn't exist. Silly user
     443            Reset();
     444            return false;
     445        }
    440446    }
    441447
    442     if (!dvdDevice.open(QIODevice::ReadOnly))
     448    // On UNIX like file systems O_NONBLOCK should be used to
     449    // indicate we don't want to do reading or writing, we
     450    // just want to issue some ioctls. This will prevent the
     451    // OS from helping out and shearing the fingers off any
     452    // person's attempting to place a DVD in the drive when
     453    // we call open.
     454    int flags = O_RDONLY;
     455#ifdef O_NONBLOCK
     456    flags |= O_NONBLOCK;
     457#endif
     458
     459    // Ideally we can open with exclusive flag.
     460#ifdef O_EXCL
     461    flags |= O_EXCL;
     462#endif
     463   
     464    int drive_handle = open(device.toLocal8Bit().constData(), flags);
     465
     466#ifdef O_EXCL
     467    // If this failed with exclusive, try without.
     468    if (drive_handle < 0)
    443469    {
    444         // Can't open device.
    445         Reset();
    446         return false;
     470        flags &= ~O_EXCL;
     471        drive_handle = open(device.toLocal8Bit().constData(), flags);
    447472    }
     473#endif
    448474
    449     int drive_handle = dvdDevice.handle();
    450 
    451     if (drive_handle == -1)
     475    if (drive_handle < 0)
    452476    {
     477        VERBOSE(VB_IMPORTANT, LOC +
     478                "Failed to open file descriptor for DVD." + ENO);
    453479        Reset();
    454480        return false;
    455481    }
     
    470496    if (status < 0)
    471497    {
    472498        Reset();
     499        close(drive_handle);
    473500        return false;
    474501    }
    475502
     
    483510        //  3 = not ready
    484511        //
    485512        Reset();
     513        close(drive_handle);
    486514        return false;
    487515    }
    488516
     
    493521        //  the disc has not changed. but if this is our
    494522        //  first time running, we still need to check it
    495523        //  so return whatever we returned before
     524        close(drive_handle);
    496525        return titles.size();
    497526    }
    498527#endif
    499528
    500     dvdDevice.close();
     529    close(drive_handle);
     530    drive_handle = -1;
    501531
    502532    //
    503533    //  Try to open the disc