[mythtv] [PATCH] fix hangs in mediamonitor
Leo Weppelman
leo at wau.mis.ah.nl
Fri Jun 11 01:18:31 EDT 2004
This patch fixes bugs in the mediamonitor introduced by the FreeBSD
patches in the ioctl() -> unlock() conversion. Much of the patch was
supplied by Stacey Son.
Leo.
-------------- next part --------------
Index: mythcdrom-freebsd.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcdrom-freebsd.cpp,v
retrieving revision 1.3
diff -u -r1.3 mythcdrom-freebsd.cpp
--- mythcdrom-freebsd.cpp 4 Jun 2004 04:27:08 -0000 1.3
+++ mythcdrom-freebsd.cpp 11 Jun 2004 05:01:24 -0000
@@ -74,10 +74,9 @@
MediaError MythCDROMFreeBSD::unlock()
{
- if (openDevice())
+ if (isDeviceOpen() || openDevice())
{
- // The call to the base unlock will close it if needed.
- VERBOSE( VB_ALL, "Unlocking CDROM door");
+ //cout << "Unlocking CDROM door" << endl;
ioctl(m_DeviceHandle, CDIOCALLOW);
}
else
Index: mythcdrom-linux.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcdrom-linux.cpp,v
retrieving revision 1.1
diff -u -r1.1 mythcdrom-linux.cpp
--- mythcdrom-linux.cpp 4 Jun 2004 02:31:22 -0000 1.1
+++ mythcdrom-linux.cpp 11 Jun 2004 05:01:25 -0000
@@ -195,10 +195,9 @@
MediaError MythCDROMLinux::unlock()
{
- if (openDevice())
+ if (isDeviceOpen() || openDevice())
{
- // The call to the base unlock will close it if needed.
- VERBOSE( VB_ALL, "Unlocking CDROM door");
+ //cout << "Unlocking CDROM door" << endl;
ioctl(m_DeviceHandle, CDROM_LOCKDOOR, 0);
}
else
Index: mythmedia.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythmedia.cpp,v
retrieving revision 1.5
diff -u -r1.5 mythmedia.cpp
--- mythmedia.cpp 24 Feb 2004 07:31:08 -0000 1.5
+++ mythmedia.cpp 11 Jun 2004 05:01:25 -0000
@@ -127,14 +127,11 @@
return MEDIAERR_FAILED;
}
-MediaError MythMediaDevice::unlock()
+MediaError MythMediaDevice::unlock()
{
m_Locked = false;
- if (closeDevice())
- return MEDIAERR_OK;
-
- return MEDIAERR_FAILED;
+ return MEDIAERR_OK;
}
bool MythMediaDevice::isMounted(bool Verify)
Index: mythmediamonitor.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythmediamonitor.cpp,v
retrieving revision 1.5
diff -u -r1.5 mythmediamonitor.cpp
--- mythmediamonitor.cpp 4 Jun 2004 21:21:05 -0000 1.5
+++ mythmediamonitor.cpp 11 Jun 2004 05:01:25 -0000
@@ -82,7 +82,7 @@
{
perror("setfsent");
cerr << "MediaMonitor::addFSTab - Failed to open "
- _PATH_FSTAB
+ _PATH_FSTAB
" for reading." << endl;
return false;
}
@@ -90,7 +90,7 @@
{
// Add all the entries
while ((mep = getfsent()) != NULL)
- addDevice(mep->fs_spec);
+ (void) addDevice(mep);
endfsent();
}
@@ -109,6 +109,94 @@
m_Devices.push_back( pDevice );
}
+// Given a fstab entry to a media device determine what type of device it is
+bool MediaMonitor::addDevice(struct fstab * mep)
+{
+ QString devicePath( mep->fs_spec );
+ //cout << "addDevice - " << devicePath << endl;
+
+ MythMediaDevice* pDevice = NULL;
+ struct stat sbuf;
+
+ bool is_supermount = false;
+ bool is_cdrom = false;
+
+ if (mep == NULL)
+ return false;
+
+ if (stat(mep->fs_spec, &sbuf) < 0)
+ return false;
+
+ // Can it be mounted?
+ if ( ! ( ((strstr(mep->fs_mntops, "owner") &&
+ (sbuf.st_mode & S_IRUSR)) || strstr(mep->fs_mntops, "user")) &&
+ (strstr(mep->fs_vfstype, MNTTYPE_ISO9660) ||
+ strstr(mep->fs_vfstype, MNTTYPE_UDF) ||
+ strstr(mep->fs_vfstype, MNTTYPE_AUTO)) ) )
+ {
+ if ( strstr(mep->fs_mntops, MNTTYPE_ISO9660) &&
+ strstr(mep->fs_vfstype, MNTTYPE_SUPERMOUNT) )
+ {
+ is_supermount = true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ if (strstr(mep->fs_mntops, MNTTYPE_ISO9660) ||
+ strstr(mep->fs_vfstype, MNTTYPE_ISO9660))
+ {
+ is_cdrom = true;
+ //cout << "Device is a CDROM" << endl;
+ }
+
+ if (!is_supermount)
+ {
+ if (is_cdrom)
+ pDevice = MythCDROM::get(this, QString(mep->fs_spec),
+ is_supermount, m_AllowEject);
+ }
+ else
+ {
+ char *dev;
+ int len = 0;
+ dev = strstr(mep->fs_mntops, SUPER_OPT_DEV);
+ dev += sizeof(SUPER_OPT_DEV)-1;
+ while (dev[len] != ',' && dev[len] != ' ' && dev[len] != 0)
+ len++;
+
+ if (dev[len] != 0)
+ {
+ char devstr[256];
+ strncpy(devstr, dev, len);
+ devstr[len] = 0;
+ if (is_cdrom)
+ MythCDROM::get(this, QString(devstr),
+ is_supermount, m_AllowEject);
+ }
+ else
+ return false;
+ }
+
+ if (pDevice)
+ {
+ pDevice->setMountPath(mep->fs_file);
+ VERBOSE(VB_ALL, QString("Mediamonitor: Adding %1")
+ .arg(pDevice->getDevicePath()));
+ if (pDevice->testMedia() == MEDIAERR_OK)
+ {
+ addDevice(pDevice);
+ return true;
+ }
+ else
+ delete pDevice;
+ }
+
+ return false;
+}
+
// Given a path to a media device determine what type of device it is and
// add it to our collection.
bool MediaMonitor::addDevice(const char* devPath )
@@ -116,13 +204,8 @@
QString devicePath( devPath );
//cout << "addDevice - " << devicePath << endl;
- MythMediaDevice* pDevice = NULL;
-
struct fstab * mep = NULL;
char lpath[PATH_MAX];
- struct stat sbuf;
- bool is_supermount = false;
- bool is_cdrom = false;
// Resolve the simlink for the device.
int len = readlink(devicePath, lpath, PATH_MAX);
@@ -134,7 +217,7 @@
{
perror("setfsent");
cerr << "MediaMonitor::addDevice - Failed to open "
- _PATH_FSTAB
+ _PATH_FSTAB
" for reading." << endl;
return false;
}
@@ -157,79 +240,13 @@
(len && (strcmp(lpath, mep->fs_spec) != 0)))
continue;
- stat(mep->fs_spec, &sbuf);
-
- if (((strstr(mep->fs_mntops, "owner") &&
- (sbuf.st_mode & S_IRUSR)) || strstr(mep->fs_mntops, "user")) &&
- (strstr(mep->fs_vfstype, MNTTYPE_ISO9660) ||
- strstr(mep->fs_vfstype, MNTTYPE_UDF) ||
- strstr(mep->fs_vfstype, MNTTYPE_AUTO)))
- {
- break;
- }
-
- if (strstr(mep->fs_mntops, MNTTYPE_ISO9660) &&
- strstr(mep->fs_vfstype, MNTTYPE_SUPERMOUNT))
- {
- is_supermount = true;
- break;
- }
}
endfsent();
}
if (mep)
- {
- if (strstr(mep->fs_mntops, MNTTYPE_ISO9660) ||
- strstr(mep->fs_vfstype, MNTTYPE_ISO9660))
- {
- is_cdrom = true;
- //cout << "Device is a CDROM" << endl;
- }
-
- if (!is_supermount)
- {
- if (is_cdrom)
- pDevice = MythCDROM::get(this, QString(mep->fs_spec),
- is_supermount, m_AllowEject);
- }
- else
- {
- char *dev;
- int len = 0;
- dev = strstr(mep->fs_mntops, SUPER_OPT_DEV);
- dev += sizeof(SUPER_OPT_DEV)-1;
- while (dev[len] != ',' && dev[len] != ' ' && dev[len] != 0)
- len++;
-
- if (dev[len] != 0)
- {
- char devstr[256];
- strncpy(devstr, dev, len);
- devstr[len] = 0;
- if (is_cdrom)
- MythCDROM::get(this, QString(devstr),
- is_supermount, m_AllowEject);
- }
- else
- return false;
- }
-
- if (pDevice)
- {
- pDevice->setMountPath(mep->fs_file);
- VERBOSE(VB_ALL, QString("Mediamonitor: Adding %1")
- .arg(pDevice->getDevicePath()));
- if (pDevice->testMedia() == MEDIAERR_OK)
- {
- addDevice(pDevice);
- return true;
- }
- else
- delete pDevice;
- }
- }
+ return addDevice(mep);
return false;
}
Index: mythmediamonitor.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythmediamonitor.h,v
retrieving revision 1.2
diff -u -r1.2 mythmediamonitor.h
--- mythmediamonitor.h 4 Jun 2004 02:31:22 -0000 1.2
+++ mythmediamonitor.h 11 Jun 2004 05:01:25 -0000
@@ -5,6 +5,7 @@
#include <qvaluelist.h>
#include <qguardedptr.h>
#include <qthread.h>
+#include <fstab.h>
const int kMediaEventType = 30042;
@@ -48,6 +49,7 @@
bool addFSTab(void);
void addDevice(MythMediaDevice* pDevice);
bool addDevice(const char* dev);
+ bool addDevice(struct fstab* mep);
bool isActive(void) const { return m_Active; }
void checkDevices(void);
More information about the mythtv-dev
mailing list