das ist zwar eigentlich sowas wie "wir müssen draußen bleiben" aber ich mach mal einen frickelvorschlag ... vlt kann es mws ja überarbeiten...mws hat geschrieben:mit implementieren meine ich aber nicht reinfrickeln
in der sectionsd.cpp
//#define TIME_NIT_BACKOFF 20
int TIME_NIT_BACKOFF=20;
//static long secondsToCache = 21*24*60*60L; // 21 Tage - Prozessorlast <3% (rasc)
//static long oldEventsAre =3* 60*60L; // 3h
long secondsToCache = 21*24*60*60L; // 21 Tage
long oldEventsAre = 3*60*60L; // 3h
timethread:
Code: Alles auswählen
static void *timeThread(void *)
{
UTC_t UTC;
time_t tim;
unsigned int seconds;
bool first_time = true; /* we don't sleep the first time (we try to get a TOT header) */
struct timespec restartWait;
struct timeval now;
try
{
dprintf("[%sThread] pid %d start\n", "time", getpid());
// -- check if time is already on box (e.g. using rdate/ntpd) (2005-05-02 rasc)
// -- if so skip first_time, etc. flags for better/quick EPG startup
{
time_t actTime;
struct tm *tmTime;
actTime=time(NULL);
tmTime = localtime(&actTime);
// -- do we already have a valid(???) date/time?
if ((tmTime->tm_year + 1900) >= 2005) {
first_time = false;
pthread_mutex_lock(&timeIsSetMutex);
timeset = true;
pthread_cond_broadcast(&timeIsSetCond);
pthread_mutex_unlock(&timeIsSetMutex );
dprintf("we already have a time set\n");
}
}
while(1)
{
if ( (ntp_mode == 0) || (system(ntp_system_line) != 0) )
{
if (scanning && (getUTC(&UTC, true))) // always use TDT, a lot of transponders don't provide a TOT
{
tim = changeUTCtoCtime((const unsigned char *) &UTC);
if (tim) {
if ((!messaging_neutrino_sets_time) && (geteuid() == 0)) {
struct timeval tv;
tv.tv_sec = tim;
tv.tv_usec = 0;
if (settimeofday(&tv, NULL) < 0) {
perror("[sectionsd] settimeofday");
pthread_exit(NULL);
}
}
time_t actTime;
struct tm *tmTime;
actTime=time(NULL);
tmTime = localtime(&actTime);
printf("[%sThread] time(): %02d.%02d.%04d %02d:%02d:%02d, tim: %s", "time", tmTime->tm_mday, tmTime->tm_mon+1, tmTime->tm_year+1900, tmTime->tm_hour, tmTime->tm_min, tmTime->tm_sec, ctime(&tim));
pthread_mutex_lock(&timeIsSetMutex);
timeset = true;
pthread_cond_broadcast(&timeIsSetCond);
pthread_mutex_unlock(&timeIsSetMutex );
eventServer->sendEvent(CSectionsdClient::EVT_TIMESET, CEventServer::INITID_SECTIONSD, &tim, sizeof(tim));
}
}
if (timeset && first_time)
{
first_time = false;
/*
* automatically restart scanning of events, because
* current events were most likely ignored as they seem
* to be too far in the future (cf. secondsToCache)
*/
// -- do not trash read events, cleanup will be done hopefully
// -- by housekeeping anyway (rasc (2005-05-02)
// dmxEIT.change(0);
// dmxSDT.change(0);
}
else
{
if (timeset) {
seconds = 60 * 30;
dprintf("[%sThread] - dmxTOT: going to sleep for %d seconds.\n", "time", seconds);
}
else if (!scanning){
seconds = 60;
}
else {
seconds = 1;
}
gettimeofday(&now, NULL);
TIMEVAL_TO_TIMESPEC(&now, &restartWait);
restartWait.tv_sec += seconds;
pthread_mutex_lock( &timeThreadSleepMutex );
int ret = pthread_cond_timedwait( &timeThreadSleepCond, &timeThreadSleepMutex, &restartWait );
if (ret == ETIMEDOUT)
{
dprintf("TDT-Thread sleeping is over - no signal received\n");
}
else if (ret == EINTR)
{
dprintf("TDT-Thread sleeping interrupted\n");
}
// else if (ret == 0) //everything is fine :) e.g. timeThreadSleepCond maybe signalled @zap time to get a valid time
pthread_mutex_unlock( &timeThreadSleepMutex );
}
}
else
{
printf("[%sThread rdate] time set by ntp\n", "time");
time_t actTime;
// struct tm *tmTime;
actTime=time(NULL);
timeset = true;
pthread_cond_broadcast(&timeIsSetCond);
pthread_mutex_unlock(&timeIsSetMutex );
eventServer->sendEvent(CSectionsdClient::EVT_TIMESET, CEventServer::INITID_SECTIONSD, &actTime, sizeof(actTime) );
gettimeofday(&now, NULL);
TIMEVAL_TO_TIMESPEC(&now, &restartWait);
//restartWait.tv_sec += seconds;
restartWait.tv_sec += ntp_update_intervall;;
pthread_mutex_lock( &timeThreadSleepMutex );
int ret = pthread_cond_timedwait( &timeThreadSleepCond, &timeThreadSleepMutex, &restartWait );
if (ret == ETIMEDOUT)
{
dprintf("TDT-Thread sleeping is over - no signal received\n");
}
else if (ret == EINTR)
{
dprintf("TDT-Thread sleeping interrupted\n");
}
// else if (ret == 0) //everything is fine :) e.g. timeThreadSleepCond maybe signalled @zap time to get a valid time
pthread_mutex_unlock( &timeThreadSleepMutex );
}
}
}
catch (std::exception& e)
{
fprintf(stderr, "Caught std-exception in time-thread %s!\n", e.what());
}
catch (...)
{
fprintf(stderr, "Caught exception in time-thread!\n");
}
dprintf("time-thread ended\n");
pthread_exit(NULL);
}
Code: Alles auswählen
int main(int argc, char **argv)
{
pthread_t threadTOT, threadEIT, threadSDT, threadHouseKeeping, threadPPT, threadNIT;
int rc;
printf("$Id: sectionsd.cpp,v 1.210 2005/12/01 20:19:00 mws Exp $\n");Exp $\n");
FILE *secd = fopen("/var/tuxbox/config/sectionsd.conf", "rt");
if (secd)
{
char line[256];
char ntp_server[240] = "";
while(fgets(line,250,secd)!=NULL)
{
sscanf(line,"ntpmode=%d", &ntp_mode);
sscanf(line,"ntptime=%d", &ntp_update_intervall);
sscanf(line,"ntpserver=%s", (char *) &ntp_server);
sscanf(line,"EventsToCache=%d", &secondsToCache);
sscanf(line,"OldEventsAre=%d", &oldEventsAre);
sscanf(line,"TimeNitBackoff=%d", &TIME_NIT_BACKOFF);
}
fclose(secd);
if(ntp_mode == 1)
{
if (strlen(ntp_server) > 2)
{
sprintf(ntp_system_line,"/sbin/rdate -s %s > /dev/null", ntp_server);
if (ntp_update_intervall<60)
ntp_update_intervall = 60 * 30;
}
else
{
sprintf(ntp_system_line,"/sbin/rdate -s de.pool.ntp.org > /dev/null");
ntp_update_intervall = 60 * 30;
}
if(TIME_NIT_BACKOFF<=0)
TIME_NIT_BACKOFF=20;
printf("[sectionsd] NTP Server: %s\n", ntp_server);
printf("[sectionsd] Aktualsisierung: %d Sekunden\n", ntp_update_intervall);
}
}
else
{
// cvs defaults
ntp_mode = 0;
secondsToCache = 21*24*60*60L; // 21 Tage
oldEventsAre = 3*60*60L; // 3h
TIME_NIT_BACKOFF=20;
}
printf("[sectionsd] NIT Backoff %d Sekunden\n", TIME_NIT_BACKOFF);
printf("[sectionsd] SecondsToCache %d Sekunden\n", secondsToCache);
printf("[sectionsd] OldEventsAre %d Sekunden\n", oldEventsAre);
try {
if (argc != 1 && argc != 2) {
.....
Code: Alles auswählen
ntpmode=1
ntpserver=de.pool.ntp.org
ntptime=1800
EventsToCache=345600
OldEventsAre=3600
TimeNitBackoff=20
Innu