summaryrefslogtreecommitdiff
path: root/dvbdevice.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2004-11-27 10:28:51 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2004-11-27 10:28:51 +0100
commit69ecb6a4d8d7eb73bd81f690d8e153a7cc6b882e (patch)
treefe56a71b801b607c638ecbc79612bc2136ce3c9d /dvbdevice.c
parenta05ed0363139694d1b4eece5ea54346de64265e1 (diff)
downloadvdr-69ecb6a4d8d7eb73bd81f690d8e153a7cc6b882e.tar.gz
vdr-69ecb6a4d8d7eb73bd81f690d8e153a7cc6b882e.tar.bz2
Fixed a possible race condition in generating the DVB device names
Diffstat (limited to 'dvbdevice.c')
-rw-r--r--dvbdevice.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/dvbdevice.c b/dvbdevice.c
index 8780ac53..0c370c4f 100644
--- a/dvbdevice.c
+++ b/dvbdevice.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: dvbdevice.c 1.105 2004/11/20 11:41:37 kls Exp $
+ * $Id: dvbdevice.c 1.106 2004/11/27 10:24:47 kls Exp $
*/
#include "dvbdevice.h"
@@ -46,16 +46,19 @@ extern "C" {
#define DEV_DVB_AUDIO "audio"
#define DEV_DVB_CA "ca"
-static const char *DvbName(const char *Name, int n)
-{
- static char buffer[PATH_MAX];
- snprintf(buffer, sizeof(buffer), "%s%d/%s%d", DEV_DVB_ADAPTER, n, Name, 0);
- return buffer;
-}
+class cDvbName {
+private:
+ char buffer[PATH_MAX];
+public:
+ cDvbName(const char *Name, int n) {
+ snprintf(buffer, sizeof(buffer), "%s%d/%s%d", DEV_DVB_ADAPTER, n, Name, 0);
+ }
+ const char *operator*() { return buffer; }
+ };
static int DvbOpen(const char *Name, int n, int Mode, bool ReportError = false)
{
- const char *FileName = DvbName(Name, n);
+ const char *FileName = *cDvbName(Name, n);
int fd = open(FileName, Mode);
if (fd < 0 && ReportError)
LOG_ERROR_STR(FileName);
@@ -406,7 +409,7 @@ cDvbDevice::cDvbDevice(int n)
dvb_frontend_info feinfo;
if (ioctl(fd_frontend, FE_GET_INFO, &feinfo) >= 0) {
frontendType = feinfo.type;
- ciHandler = cCiHandler::CreateCiHandler(DvbName(DEV_DVB_CA, n));
+ ciHandler = cCiHandler::CreateCiHandler(*cDvbName(DEV_DVB_CA, n));
dvbTuner = new cDvbTuner(fd_frontend, CardIndex(), frontendType, ciHandler);
}
else
@@ -449,7 +452,7 @@ bool cDvbDevice::Initialize(void)
int i;
for (i = 0; i < MAXDVBDEVICES; i++) {
if (UseDevice(NextCardIndex())) {
- if (Probe(DvbName(DEV_DVB_FRONTEND, i))) {
+ if (Probe(*cDvbName(DEV_DVB_FRONTEND, i))) {
new cDvbDevice(i);
found++;
}
@@ -659,7 +662,7 @@ bool cDvbDevice::SetPid(cPidHandle *Handle, int Type, bool On)
int cDvbDevice::OpenFilter(u_short Pid, u_char Tid, u_char Mask)
{
- const char *FileName = DvbName(DEV_DVB_DEMUX, CardIndex());
+ const char *FileName = *cDvbName(DEV_DVB_DEMUX, CardIndex());
int f = open(FileName, O_RDWR | O_NONBLOCK);
if (f >= 0) {
dmx_sct_filter_params sctFilterParams;