Ticket #5704: mythvideo-file-race.patch

File mythvideo-file-race.patch, 2.0 KB (added by Erik Hovland <erik@…>, 16 years ago)

changes DVDProbe::probe to use QFile instead of stat and open.

  • mythplugins/mythvideo/mtd/dvdprobe.cpp

    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  
    1919#include <cmath>
    2020#include <climits> // for CDSL_CURRENT which is currently INT_MAX
    2121
     22#include <QFile>
     23
    2224#include "dvdprobe.h"
    2325
    2426#include <mythtv/mythcontext.h>
    bool DVDProbe::probe() 
    414416    //  a drive with media in it
    415417    //
    416418
    417     struct stat fileinfo;
     419    QFile dvdDevice((device.toAscii()).constData());
    418420
    419     QByteArray dev = device.toAscii();
    420     int ret = stat(dev.constData(), &fileinfo);
    421     if (ret < 0)
     421    if (!dvdDevice.exists() && !dvdDevice.open(QIODevice::ReadOnly))
    422422    {
    423423        //
    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.
    426426        //
    427427        wipeClean();
    428428        return false;
    bool DVDProbe::probe() 
    435435    //  this, but it seems to work.
    436436    //
    437437
    438     int drive_handle = open(dev.constData(), O_RDONLY | O_NONBLOCK);
     438    int drive_handle = dvdDevice.handle();
    439439
    440440    if (drive_handle == -1)
    441441    {
    bool DVDProbe::probe() 
    461461        //  3 = not ready
    462462        //
    463463        wipeClean();
    464         close(drive_handle);
    465464        return false;
    466465
    467466    }
    468467
    469468    status = ioctl(drive_handle, CDROM_MEDIA_CHANGED, NULL);
    470     close(drive_handle);
    471469
    472470    if (!status)
    473471    {
    bool DVDProbe::probe() 
    493491    //  could be a path, file, whatever).
    494492    //
    495493
     494    dvdDevice.close();
    496495    wipeClean();
    497496    first_time = false;
    498     dvd = DVDOpen(dev.constData());
     497    dvd = DVDOpen(dvdDevice.fileName());
    499498    if (dvd)
    500499    {
    501500        //