/* The main driving routine */ int main(int argc, char *argv[]) { time_t t; /* Current time */ time_t target; /* Next wake up time */ struct tm *now; /* Pointer to current expanded time */ int delay; /* How long to sleep for */ if (strcmp(argv[0], "cron-parent") == 0) { return cron_parent_main(argc, argv); } openlog("cron", LOG_PID, LOG_CRON); signal(SIGCHLD, SIG_IGN); for (;;) { t = time(NULL); /* Work out what time it is now */ now = localtime(&t); target = t + 60 - now->tm_sec; /* Next awakening */ load_file(CRONFILE); /* Load the crontab if necessary */ check_runs(now); /* Run anything that needs to be run */ /* Now go to sleep for a time. * This loop will fail if it takes longer than sixty second to * execute each iteration :-) */ for (;;) { delay = target - time(NULL); if (delay > 0) break; target += 60; } while (delay > 0) delay = sleep(delay); } }
/* The main driving routine */ int main(int argc, char *argv[]) { time_t t; /* Current time */ time_t target; /* Next wake up time */ struct tm *now; /* Pointer to current expanded time */ int delay; /* How long to sleep for */ int ret,dsv; time_t t1,stm; SYS_TIME timeinfo; TIME_FMT timefmt; if (strcmp(argv[0], "cron-parent") == 0) { return cron_parent_main(argc, argv); } create_file(CRONFILE); /* Create the crontab on /mnt/ramfs */ /* Set daylight saving flag */ t = time(NULL); TIME_FMT_ReadSystemData(&timefmt); if(timefmt.d_sav) { tzone=timefmt.t_index; dsv=daylight_saving(t); PRO_SetInt(SEC_MAN,MAN_SUMMER_CHANGED ,dsv); } for (;;) { t = time(NULL); /* Work out what time it is now */ ret=PRO_GetInt(SEC_MAN,MAN_SUMMER_CHANGED ,&dsv); if(ret != 0) dsv=0; TIME_FMT_ReadSystemData(&timefmt); // Read daylight saving flag if(timefmt.d_sav) { tzone=timefmt.t_index; if((ret=daylight_saving(t)) != dsv) { if(dsv) { AddLog(DST_SEC,SYSLOG_WARNING,DST_CHG_LEAVE,-1); time(&t1); now=localtime(&t1); stm = mktime(now); stm -= 3600; stime(&stm); set_rtc(); ret = PRO_SetInt(SEC_MAN, MAN_SUMMER_CHANGED, 0); // fl_write_conf(CONF_FILE); // summer_chg = 0 } else { AddLog(DST_SEC,SYSLOG_WARNING,DST_CHG_ENTER,1); time(&t1); now=localtime(&t1); stm = mktime(now); stm += 3600; stime(&stm); set_rtc(); ret = PRO_SetInt(SEC_MAN, MAN_SUMMER_CHANGED, 1); // fl_write_conf(CONF_FILE); // summer_chg = 1 } } } now = localtime(&t); target = t + 60 - now->tm_sec; /* Next awakening */ clean_children(); /* Clean up any child processes */ load_file(CRONFILE); /* Load the crontab if necessary */ check_runs(now); /* Run anything that needs to be run */ /* Now go to sleep for a time. * This loop will fail if it takes longer than sixty second to * execute each iteration :-) */ for (;;) { delay = target - (time(NULL)); if (delay > 0) break; target += 60; } while (delay > 0) delay = sleep(delay); } }