signed long int SysGetRtcSeconds() { RtcTimeStruct time; if(SysGetDate(&time) != ESUCCESS) return -EIO; return maketime(time.Year, time.Month, time.DayMonth, time.Hour, time.Minute, time.Second); }
/* Parse a free-format date in *SOURCE, yielding a Unix format time. Update *SOURCE to point to the first character after the date. If *SOURCE is missing some information, take defaults from DEFAULT_TIME and DEFAULT_ZONE. *SOURCE may even be the empty string or an immediately invalid string, in which case the default time and zone is used. Return (time_t) -1 if the time is invalid or cannot be represented. */ time_t str2time (char const **source, time_t default_time, long default_zone) { struct partime pt; *source = partime (*source, &pt); if (pt.zone == TM_UNDEFINED_ZONE) pt.zone = default_zone; return maketime (&pt, default_time); }
static void find_jobs(time_t vtime, cron_db *db, int doWild, int doNonWild) { time_t virtualSecond = vtime * SECONDS_PER_MINUTE; struct tm *tm; int minute, hour, dom, month, dow; user *u; entry *e; #ifndef CRON_LOCALTIME char *orig_tz, *job_tz; #define maketime(tz1, tz2) do { \ char *t = tz1; \ if (t != NULL && *t != '\0') \ setenv("TZ", t, 1); \ else if ((tz2) != NULL) \ setenv("TZ", (tz2), 1); \ else \ unsetenv("TZ"); \ tzset(); \ tm = localtime(&virtualSecond); \ minute = tm->tm_min -FIRST_MINUTE; \ hour = tm->tm_hour -FIRST_HOUR; \ dom = tm->tm_mday -FIRST_DOM; \ month = tm->tm_mon + 1 /* 0..11 -> 1..12 */ -FIRST_MONTH; \ dow = tm->tm_wday -FIRST_DOW; \ } while (/*CONSTCOND*/0) orig_tz = getenv("TZ"); maketime(NULL, orig_tz); #else tm = gmtime(&virtualSecond); #endif Debug(DSCH, ("[%ld] tick(%d,%d,%d,%d,%d) %s %s\n", (long)getpid(), minute, hour, dom, month, dow, doWild?" ":"No wildcard",doNonWild?" ":"Wildcard only")); /* the dom/dow situation is odd. '* * 1,15 * Sun' will run on the * first and fifteenth AND every Sunday; '* * * * Sun' will run *only* * on Sundays; '* * 1,15 * *' will run *only* the 1st and 15th. this * is why we keep 'e->dow_star' and 'e->dom_star'. yes, it's bizarre. * like many bizarre things, it's the standard. */ for (u = db->head; u != NULL; u = u->next) { for (e = u->crontab; e != NULL; e = e->next) { #ifndef CRON_LOCALTIME job_tz = env_get("CRON_TZ", e->envp); maketime(job_tz, orig_tz); #else #define job_tz "N/A" #define orig_tz "N/A" #endif Debug(DSCH|DEXT, ("user [%s:%ld:%ld:...] " "[jobtz=%s, origtz=%s] " "tick(%s), cmd=\"%s\"\n", e->pwd->pw_name, (long)e->pwd->pw_uid, (long)e->pwd->pw_gid, job_tz, orig_tz, tick(e), e->cmd)); if (bit_test(e->minute, minute) && bit_test(e->hour, hour) && bit_test(e->month, month) && ( ((e->flags & DOM_STAR) || (e->flags & DOW_STAR)) ? (bit_test(e->dow,dow) && bit_test(e->dom,dom)) : (bit_test(e->dow,dow) || bit_test(e->dom,dom)) ) ) { if ((doNonWild && !(e->flags & (MIN_STAR|HR_STAR))) || (doWild && (e->flags & (MIN_STAR|HR_STAR)))) job_add(e, u, StartTime); } } } #ifndef CRON_LOCALTIME if (orig_tz != NULL) setenv("TZ", orig_tz, 1); else unsetenv("TZ"); #endif }