--- ../vdr-1.4.5-orig/dvbdevice.c	2006-08-14 11:38:32.000000000 +0200
+++ dvbdevice.c	2007-02-01 21:38:44.000000000 +0100
@@ -176,6 +176,13 @@ static unsigned int FrequencyToHz(unsign
   return f;
 }
 
+#include <sys/time.h>
+static double now() { timeval t; gettimeofday(&t, 0); return t.tv_sec + t.tv_usec / 1e6; }
+static int check(int c, int r, char *a, double t) { fprintf(stderr, "t: %.3lf, c: %d, r: %d, a: %s\n", t, c, r, a); return r; } 
+#define CHECK4(s) ::check(cardIndex, 0, s, ::now())
+#define CHECK3(s) ::check(cardIndex, s, #s, ::now())
+#define CHECK2(s) CHECK(::check(cardIndex, s, #s, ::now()))
+
 bool cDvbTuner::SetFrontend(void)
 {
   dvb_frontend_parameters Frontend;
@@ -195,12 +202,12 @@ bool cDvbTuner::SetFrontend(void)
                   for (char *CurrentAction = NULL; (da = diseqc->Execute(&CurrentAction)) != cDiseqc::daNone; ) {
                       switch (da) {
                         case cDiseqc::daNone:      break;
-                        case cDiseqc::daToneOff:   CHECK(ioctl(fd_frontend, FE_SET_TONE, SEC_TONE_OFF)); break;
-                        case cDiseqc::daToneOn:    CHECK(ioctl(fd_frontend, FE_SET_TONE, SEC_TONE_ON)); break;
-                        case cDiseqc::daVoltage13: CHECK(ioctl(fd_frontend, FE_SET_VOLTAGE, SEC_VOLTAGE_13)); break;
-                        case cDiseqc::daVoltage18: CHECK(ioctl(fd_frontend, FE_SET_VOLTAGE, SEC_VOLTAGE_18)); break;
-                        case cDiseqc::daMiniA:     CHECK(ioctl(fd_frontend, FE_DISEQC_SEND_BURST, SEC_MINI_A)); break;
-                        case cDiseqc::daMiniB:     CHECK(ioctl(fd_frontend, FE_DISEQC_SEND_BURST, SEC_MINI_B)); break;
+                        case cDiseqc::daToneOff:   CHECK2(ioctl(fd_frontend, FE_SET_TONE, SEC_TONE_OFF)); break;
+                        case cDiseqc::daToneOn:    CHECK2(ioctl(fd_frontend, FE_SET_TONE, SEC_TONE_ON)); break;
+                        case cDiseqc::daVoltage13: CHECK2(ioctl(fd_frontend, FE_SET_VOLTAGE, SEC_VOLTAGE_13)); break;
+                        case cDiseqc::daVoltage18: CHECK2(ioctl(fd_frontend, FE_SET_VOLTAGE, SEC_VOLTAGE_18)); break;
+                        case cDiseqc::daMiniA:     CHECK2(ioctl(fd_frontend, FE_DISEQC_SEND_BURST, SEC_MINI_A)); break;
+                        case cDiseqc::daMiniB:     CHECK2(ioctl(fd_frontend, FE_DISEQC_SEND_BURST, SEC_MINI_B)); break;
                         case cDiseqc::daCodes: {
                              int n = 0;
                              uchar *codes = diseqc->Codes(n);
@@ -208,7 +215,7 @@ bool cDvbTuner::SetFrontend(void)
                                 struct dvb_diseqc_master_cmd cmd;
                                 memcpy(cmd.msg, codes, min(n, int(sizeof(cmd.msg))));
                                 cmd.msg_len = n;
-                                CHECK(ioctl(fd_frontend, FE_DISEQC_SEND_MASTER_CMD, &cmd));
+                                CHECK2(ioctl(fd_frontend, FE_DISEQC_SEND_MASTER_CMD, &cmd));
                                 }
                              }
                              break;
@@ -285,7 +292,7 @@ bool cDvbTuner::SetFrontend(void)
          esyslog("ERROR: attempt to set channel with unknown DVB frontend type");
          return false;
     }
-  if (ioctl(fd_frontend, FE_SET_FRONTEND, &Frontend) < 0) {
+  if (CHECK3(ioctl(fd_frontend, FE_SET_FRONTEND, &Frontend)) < 0) {
      esyslog("ERROR: frontend %d: %m", cardIndex);
      return false;
      }
@@ -306,11 +313,13 @@ void cDvbTuner::Action(void)
           case tsIdle:
                break;
           case tsSet:
+CHECK4("----------------------------------------------");
                tunerStatus = SetFrontend() ? tsTuned : tsIdle;
                Timer.Set(tuneTimeout);
                continue;
           case tsTuned:
                if (Timer.TimedOut()) {
+CHECK4("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                   tunerStatus = tsSet;
                   diseqcCommands = NULL;
                   if (time(NULL) - lastTimeoutReport > 60) { // let's not get too many of these
@@ -328,6 +337,7 @@ void cDvbTuner::Action(void)
                   continue;
                   }
                else if (Status & FE_HAS_LOCK) {
+if (tunerStatus != tsLocked) CHECK4("==============================================");
                   if (LostLock) {
                      isyslog("frontend %d regained lock on channel %d, tp %d", cardIndex, channel.Number(), channel.Transponder());

