#944110 anacron: Incorrect behavoiur when using @monthly period_name

Package:
anacron
Source:
anacron
Description:
cron-like program that doesn't go by time
Submitter:
Santiago Castillo Oli
Date:
2019-11-04 13:33:04 UTC
Severity:
normal
#944110#5
Date:
2019-11-04 13:30:27 UTC
From:
To:
Dear Maintainer,

I see that @monthly is not a feature of anacron upstream, but it belongs
to a debian patch.

I have found that @monthly period_name doesnt work well sometimes.

Let's see an example: I have an job that was last executed by anacron on
the first of october.
The expected behaviour would be that the next execution will happen on
the first of november.
But the truth is that the next execution happens on the 31st of october.

Looking at lock.c code I see:

  if (jr->named_period)
         {
             int period = 0, bypass = 0;
             switch (jr->named_period)
             {
                 case 1:
                     period = days_last_month ();
                     bypass = days_this_month ();
                     break;
                 case 2:
                     period = days_last_year ();
                     bypass = days_this_year ();
                     break;
                 default:
                     die ("Unknown named period for %s (%d)", jr->ident,
jr->named_period);
             }
             if (day_delta < period && day_delta != bypass)
             {
                 /* Job is still too young */
                 xclose (jr->timestamp_fd);
                 return 0;
             }
         }



Last execution (with YYYYMMDD notation): 20191001

Current day: 20191031

day_delta=30

period=30 (Number of days in september)

bypass=31 (Number of days in octuber)

(day_delta < period && day_delta != bypass) = (30 < 30 && 30 !=31) =
(FALSE && TRUE) = FALSE, so the job is executed today


In this case the job is run on the 1st and on the 31st day of october.
Two times in a month. The next one will be at the end of november.
I think this is wrong. If first run is on 1st day it should be again the
first day of following months, assuming that the machine is turned up
everyday.


Not sure about (day_delta < period && day_delta != bypass). It doesn't
work in this case, but it doesnt work with another dates: (i.e.: last
execution on january 31st, won't run on february, but on the first of
march))



Can this be fixed, please?


Thank you and regards.