- tod = (bit_is_set(mday, run->mday) || bit_is_set(wday, run->wday)) &&
- bit_is_set(month, run->month) && bit_is_set(wpos, run->wpos);
-
- tom = (bit_is_set(tmday, run->mday) || bit_is_set(twday, run->wday)) &&
- bit_is_set(tmonth, run->month) && bit_is_set(wpos, run->wpos);
-
- Dmsg2(200, "tod=%d tom=%d\n", tod, tom);
- if (tod) { /* Jobs scheduled today (next 24 hours) */
- /* find time (time_t) job is to be run */
- localtime_r(&now, &tm);
- hour = 0;
- for (i=tm.tm_hour; i < 24; i++) {
- if (bit_is_set(i, run->hour)) {
- tm.tm_hour = i;
- tm.tm_min = run->minute;
- tm.tm_sec = 0;
- runtime = mktime(&tm);
- if (runtime > now) {
- return run; /* found it, return run resource */
- }
- }
- }
- }
-
-// Dmsg2(200, "runtime=%d now=%d\n", runtime, now);
- if (tom) { /* look at jobs scheduled tomorrow */
- localtime_r(&tomorrow, &tm);
- hour = 0;
- for (i=0; i < 24; i++) {
- if (bit_is_set(i, run->hour)) {
- hour = i;
- break;
- }
- }
- tm.tm_hour = hour;
- tm.tm_min = run->minute;
- tm.tm_sec = 0;
- runtime = mktime(&tm);
- Dmsg2(200, "truntime=%d now=%d\n", runtime, now);
- if (runtime < tomorrow) {
- return run; /* found it, return run resource */
- }
+ for (day = 0; day <= ndays; day++) {
+ future = now + (day * 60 * 60 * 24);
+
+ /* Break down the time into components */
+ (void)localtime_r(&future, &tm);
+ mday = tm.tm_mday - 1;
+ wday = tm.tm_wday;
+ month = tm.tm_mon;
+ wom = mday / 7;
+ woy = tm_woy(future);
+
+ is_scheduled = bit_is_set(mday, run->mday) && bit_is_set(wday, run->wday) &&
+ bit_is_set(month, run->month) && bit_is_set(wom, run->wom) &&
+ bit_is_set(woy, run->woy);
+
+#ifdef xxx
+ Dmsg2(000, "day=%d is_scheduled=%d\n", day, is_scheduled);
+ Dmsg1(000, "bit_set_mday=%d\n", bit_is_set(mday, run->mday));
+ Dmsg1(000, "bit_set_wday=%d\n", bit_is_set(wday, run->wday));
+ Dmsg1(000, "bit_set_month=%d\n", bit_is_set(month, run->month));
+ Dmsg1(000, "bit_set_wom=%d\n", bit_is_set(wom, run->wom));
+ Dmsg1(000, "bit_set_woy=%d\n", bit_is_set(woy, run->woy));
+#endif
+
+ if (is_scheduled) { /* Jobs scheduled on that day */
+#ifdef xxx
+ char buf[300], num[10];
+ bsnprintf(buf, sizeof(buf), "tm.hour=%d hour=", tm.tm_hour);
+ for (i=0; i<24; i++) {
+ if (bit_is_set(i, run->hour)) {
+ bsnprintf(num, sizeof(num), "%d ", i);
+ bstrncat(buf, num, sizeof(buf));
+ }
+ }
+ bstrncat(buf, "\n", sizeof(buf));
+ Dmsg1(000, "%s", buf);
+#endif
+ /* find time (time_t) job is to be run */
+ (void)localtime_r(&future, &runtm);
+ for (i= 0; i < 24; i++) {
+ if (bit_is_set(i, run->hour)) {
+ runtm.tm_hour = i;
+ runtm.tm_min = run->minute;
+ runtm.tm_sec = 0;
+ runtime = mktime(&runtm);
+ Dmsg2(200, "now=%d runtime=%d\n", now, runtime);
+ if ((runtime > now) && (runtime < endtime)) {
+ Dmsg2(200, "Found it level=%d %c\n", run->level, run->level);
+ return run; /* found it, return run resource */
+ }
+ }
+ }
+ }