Skip to content

Commit

Permalink
crond: Fix timing
Browse files Browse the repository at this point in the history
It seems the original author of crond slightly messed up the logic for
checking whether the current time matches the time that was specified.
This patch fixes it.

For some reason there was an OR where there should have been an AND,
which meant if the time and day of month OR the month and day of week
match the current time, the job would run. So you'd get jobs running
every minute if the day of week and month match. And if they didn't
match, you'd still get the job running if the time and day of month
match.

Also, in the tm struct, the day of the month (tm_mday) starts at 1,
not the month (tm_mon).
  • Loading branch information
Kana Steimle authored and landley committed Jan 12, 2025
1 parent 006dfd8 commit bade4db
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions toys/pending/crond.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ static void schedule_jobs(time_t ctime, time_t ptime)
if (FLAG(d)) loginfo(5, " line %s", job->cmd);

if (job->min[lt->tm_min] && job->hour[lt->tm_hour]
&& (job->dom[lt->tm_mday] || job->dow[lt->tm_wday])
&& job->mon[lt->tm_mon-1]) {
&& (job->dom[lt->tm_mday-1] && job->dow[lt->tm_wday])
&& job->mon[lt->tm_mon]) {
if (FLAG(d))
loginfo(5, " job: %d %s\n", (int)job->pid, job->cmd);
if (job->pid > 0) {
Expand Down

0 comments on commit bade4db

Please sign in to comment.