Revert latest changes to cron, until better version is worked out (I hope).

Requested by:   few
This commit is contained in:
Maxim Sobolev 2012-10-17 20:45:48 +00:00
parent 983731268c
commit 07e9aac098
4 changed files with 10 additions and 45 deletions

View File

@ -98,7 +98,6 @@ main(argc, argv)
char *argv[]; char *argv[];
{ {
cron_db database; cron_db database;
int runnum;
ProgramName = argv[0]; ProgramName = argv[0];
@ -150,24 +149,21 @@ main(argc, argv)
load_database(&database); load_database(&database);
run_reboot_jobs(&database); run_reboot_jobs(&database);
cron_sync(); cron_sync();
runnum = 0;
while (TRUE) { while (TRUE) {
# if DEBUGGING # if DEBUGGING
/* if (!(DebugFlags & DTEST)) */ /* if (!(DebugFlags & DTEST)) */
# endif /*DEBUGGING*/ # endif /*DEBUGGING*/
cron_sleep(&database); cron_sleep(&database);
if (runnum % 60 == 0)
load_database(&database); load_database(&database);
/* do this iteration /* do this iteration
*/ */
cron_tick(&database); cron_tick(&database);
/* sleep 1 second /* sleep 1 minute
*/ */
TargetTime += 1; TargetTime += 60;
runnum += 1;
} }
} }
@ -198,23 +194,22 @@ cron_tick(db)
static time_t diff = 0, /* time difference in seconds from the last offset change */ static time_t diff = 0, /* time difference in seconds from the last offset change */
difflimit = 0; /* end point for the time zone correction */ difflimit = 0; /* end point for the time zone correction */
struct tm otztm; /* time in the old time zone */ struct tm otztm; /* time in the old time zone */
int otzsecond, otzminute, otzhour, otzdom, otzmonth, otzdow; int otzminute, otzhour, otzdom, otzmonth, otzdow;
register struct tm *tm = localtime(&TargetTime); register struct tm *tm = localtime(&TargetTime);
register int second, minute, hour, dom, month, dow; register int minute, hour, dom, month, dow;
register user *u; register user *u;
register entry *e; register entry *e;
/* make 0-based values out of these so we can use them as indicies /* make 0-based values out of these so we can use them as indicies
*/ */
second = tm->tm_sec -FIRST_SECOND;
minute = tm->tm_min -FIRST_MINUTE; minute = tm->tm_min -FIRST_MINUTE;
hour = tm->tm_hour -FIRST_HOUR; hour = tm->tm_hour -FIRST_HOUR;
dom = tm->tm_mday -FIRST_DOM; dom = tm->tm_mday -FIRST_DOM;
month = tm->tm_mon +1 /* 0..11 -> 1..12 */ -FIRST_MONTH; month = tm->tm_mon +1 /* 0..11 -> 1..12 */ -FIRST_MONTH;
dow = tm->tm_wday -FIRST_DOW; dow = tm->tm_wday -FIRST_DOW;
Debug(DSCH, ("[%d] tick(%d,%d,%d,%d,%d,%d)\n", Debug(DSCH, ("[%d] tick(%d,%d,%d,%d,%d)\n",
getpid(), second, minute, hour, dom, month, dow)) getpid(), minute, hour, dom, month, dow))
if (dst_enabled && last_time != 0 if (dst_enabled && last_time != 0
&& TargetTime > last_time /* exclude stepping back */ && TargetTime > last_time /* exclude stepping back */
@ -267,7 +262,6 @@ cron_tick(db)
/* make 0-based values out of these so we can use them as indicies /* make 0-based values out of these so we can use them as indicies
*/ */
otzsecond = otztm.tm_sec -FIRST_SECOND;
otzminute = otztm.tm_min -FIRST_MINUTE; otzminute = otztm.tm_min -FIRST_MINUTE;
otzhour = otztm.tm_hour -FIRST_HOUR; otzhour = otztm.tm_hour -FIRST_HOUR;
otzdom = otztm.tm_mday -FIRST_DOM; otzdom = otztm.tm_mday -FIRST_DOM;
@ -289,8 +283,7 @@ cron_tick(db)
e->uid, e->gid, e->cmd)) e->uid, e->gid, e->cmd))
if ( diff != 0 && (e->flags & (RUN_AT|NOT_UNTIL)) ) { if ( diff != 0 && (e->flags & (RUN_AT|NOT_UNTIL)) ) {
if (bit_test(e->second, otzsecond) if (bit_test(e->minute, otzminute)
&& bit_test(e->minute, otzminute)
&& bit_test(e->hour, otzhour) && bit_test(e->hour, otzhour)
&& bit_test(e->month, otzmonth) && bit_test(e->month, otzmonth)
&& ( ((e->flags & DOM_STAR) || (e->flags & DOW_STAR)) && ( ((e->flags & DOM_STAR) || (e->flags & DOW_STAR))
@ -309,8 +302,7 @@ cron_tick(db)
continue; continue;
} }
if (bit_test(e->second, second) if (bit_test(e->minute, minute)
&& bit_test(e->minute, minute)
&& bit_test(e->hour, hour) && bit_test(e->hour, hour)
&& bit_test(e->month, month) && bit_test(e->month, month)
&& ( ((e->flags & DOM_STAR) || (e->flags & DOW_STAR)) && ( ((e->flags & DOM_STAR) || (e->flags & DOW_STAR))

View File

@ -124,10 +124,6 @@
LineNumber = ln; \ LineNumber = ln; \
} }
#define FIRST_SECOND 0
#define LAST_SECOND 59
#define SECOND_COUNT (LAST_SECOND - FIRST_SECOND + 1)
#define FIRST_MINUTE 0 #define FIRST_MINUTE 0
#define LAST_MINUTE 59 #define LAST_MINUTE 59
#define MINUTE_COUNT (LAST_MINUTE - FIRST_MINUTE + 1) #define MINUTE_COUNT (LAST_MINUTE - FIRST_MINUTE + 1)
@ -169,7 +165,6 @@ typedef struct _entry {
#endif #endif
char **envp; char **envp;
char *cmd; char *cmd;
bitstr_t bit_decl(second, SECOND_COUNT);
bitstr_t bit_decl(minute, MINUTE_COUNT); bitstr_t bit_decl(minute, MINUTE_COUNT);
bitstr_t bit_decl(hour, HOUR_COUNT); bitstr_t bit_decl(hour, HOUR_COUNT);
bitstr_t bit_decl(dom, DOM_COUNT); bitstr_t bit_decl(dom, DOM_COUNT);
@ -181,6 +176,7 @@ typedef struct _entry {
#define WHEN_REBOOT 0x04 #define WHEN_REBOOT 0x04
#define RUN_AT 0x08 #define RUN_AT 0x08
#define NOT_UNTIL 0x10 #define NOT_UNTIL 0x10
#define SECONDS_COUNT 0x20
time_t lastrun; time_t lastrun;
} entry; } entry;

View File

@ -232,8 +232,6 @@ string meaning
@daily Run once a day, "0 0 * * *". @daily Run once a day, "0 0 * * *".
@midnight (same as @daily) @midnight (same as @daily)
@hourly Run once an hour, "0 * * * *". @hourly Run once an hour, "0 * * * *".
@every_minute Run once a minute, "*/1 * * * *".
@every_second Run once a second.
.Ed .Ed
.Sh EXAMPLE CRON FILE .Sh EXAMPLE CRON FILE
.Bd -literal .Bd -literal

View File

@ -151,7 +151,6 @@ load_entry(file, error_func, pw, envp)
e->flags |= WHEN_REBOOT; e->flags |= WHEN_REBOOT;
} else if (!strcmp("yearly", cmd) || !strcmp("annually", cmd)){ } else if (!strcmp("yearly", cmd) || !strcmp("annually", cmd)){
Debug(DPARS, ("load_entry()...yearly shortcut\n")) Debug(DPARS, ("load_entry()...yearly shortcut\n"))
bit_set(e->second, 0);
bit_set(e->minute, 0); bit_set(e->minute, 0);
bit_set(e->hour, 0); bit_set(e->hour, 0);
bit_set(e->dom, 0); bit_set(e->dom, 0);
@ -160,7 +159,6 @@ load_entry(file, error_func, pw, envp)
e->flags |= DOW_STAR; e->flags |= DOW_STAR;
} else if (!strcmp("monthly", cmd)) { } else if (!strcmp("monthly", cmd)) {
Debug(DPARS, ("load_entry()...monthly shortcut\n")) Debug(DPARS, ("load_entry()...monthly shortcut\n"))
bit_set(e->second, 0);
bit_set(e->minute, 0); bit_set(e->minute, 0);
bit_set(e->hour, 0); bit_set(e->hour, 0);
bit_set(e->dom, 0); bit_set(e->dom, 0);
@ -169,7 +167,6 @@ load_entry(file, error_func, pw, envp)
e->flags |= DOW_STAR; e->flags |= DOW_STAR;
} else if (!strcmp("weekly", cmd)) { } else if (!strcmp("weekly", cmd)) {
Debug(DPARS, ("load_entry()...weekly shortcut\n")) Debug(DPARS, ("load_entry()...weekly shortcut\n"))
bit_set(e->second, 0);
bit_set(e->minute, 0); bit_set(e->minute, 0);
bit_set(e->hour, 0); bit_set(e->hour, 0);
bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1)); bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1));
@ -178,7 +175,6 @@ load_entry(file, error_func, pw, envp)
bit_set(e->dow, 0); bit_set(e->dow, 0);
} else if (!strcmp("daily", cmd) || !strcmp("midnight", cmd)) { } else if (!strcmp("daily", cmd) || !strcmp("midnight", cmd)) {
Debug(DPARS, ("load_entry()...daily shortcut\n")) Debug(DPARS, ("load_entry()...daily shortcut\n"))
bit_set(e->second, 0);
bit_set(e->minute, 0); bit_set(e->minute, 0);
bit_set(e->hour, 0); bit_set(e->hour, 0);
bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1)); bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1));
@ -186,27 +182,11 @@ load_entry(file, error_func, pw, envp)
bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1)); bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1));
} else if (!strcmp("hourly", cmd)) { } else if (!strcmp("hourly", cmd)) {
Debug(DPARS, ("load_entry()...hourly shortcut\n")) Debug(DPARS, ("load_entry()...hourly shortcut\n"))
bit_set(e->second, 0);
bit_set(e->minute, 0); bit_set(e->minute, 0);
bit_nset(e->hour, 0, (LAST_HOUR-FIRST_HOUR+1)); bit_nset(e->hour, 0, (LAST_HOUR-FIRST_HOUR+1));
bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1)); bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1));
bit_nset(e->month, 0, (LAST_MONTH-FIRST_MONTH+1)); bit_nset(e->month, 0, (LAST_MONTH-FIRST_MONTH+1));
bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1)); bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1));
} else if (!strcmp("every_minute", cmd)) {
Debug(DPARS, ("load_entry()...every_minute shortcut\n"))
bit_set(e->second, 0);
bit_nset(e->minute, 0, (LAST_MINUTE-FIRST_MINUTE+1));
bit_nset(e->hour, 0, (LAST_HOUR-FIRST_HOUR+1));
bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1));
bit_nset(e->month, 0, (LAST_MONTH-FIRST_MONTH+1));
bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1));
} else if (!strcmp("every_second", cmd)) {
Debug(DPARS, ("load_entry()...every_second shortcut\n"))
bit_nset(e->second, 0, (LAST_SECOND-FIRST_SECOND+1));
bit_nset(e->minute, 0, (LAST_MINUTE-FIRST_MINUTE+1));
bit_nset(e->hour, 0, (LAST_HOUR-FIRST_HOUR+1));
bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1));
bit_nset(e->month, 0, (LAST_MONTH-FIRST_MONTH+1));
bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1)); bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1));
} else { } else {
ecode = e_timespec; ecode = e_timespec;
@ -222,7 +202,6 @@ load_entry(file, error_func, pw, envp)
} }
} else { } else {
Debug(DPARS, ("load_entry()...about to parse numerics\n")) Debug(DPARS, ("load_entry()...about to parse numerics\n"))
bit_set(e->second, 0);
ch = get_list(e->minute, FIRST_MINUTE, LAST_MINUTE, ch = get_list(e->minute, FIRST_MINUTE, LAST_MINUTE,
PPC_NULL, ch, file); PPC_NULL, ch, file);