cronie-crond / cronie

Cronie cron daemon project
Other
453 stars 77 forks source link

Step size out of bound handling #154

Closed alexxcons closed 9 months ago

alexxcons commented 10 months ago

When using stepwise notation, there is no cron-error when a step-size is picked which is bigger than the max. value of the field. E.g. the following entry is valid:*/500 */400 */31 */12 */300 MyCommand And, as far as I can tell, will be interpreted as: * * * Jan *

A step size, which is bigger than the specified range actually does not make much sense, and it would be nice to see a warning, when used. In this PR I did a fallback to the default stepsize in that case ... hope that would be fine ?

Even though step-sizes bigger than (max-min)/2 do not make much sense, it is possible to use them in some way (see e.g. see here ). So I kept support for them, and used "max-min" to restrict step-size.

For testing, I used the attached cron files and did the following:

$ sudo ./src/crontab ../example-crontab-invalid
Step size of '500' will be ignored, since it exceeds the maximum possible step size of '59' for the specified entry'
Step size of '400' will be ignored, since it exceeds the maximum possible step size of '23' for the specified entry'
Step size of '31' will be ignored, since it exceeds the maximum possible step size of '30' for the specified entry'
Step size of '12' will be ignored, since it exceeds the maximum possible step size of '11' for the specified entry'
Step size of '300' will be ignored, since it exceeds the maximum possible step size of '7' for the specified entry'
$ sudo ./src/crontab ../example-crontab-invalid2
Step size of '11' will be ignored for this entry, since it exceeds the maximum possible step size of '10' for the specifed range of '10-20'
Step size of '20' will be ignored for this entry, since it exceeds the maximum possible step size of '10' for the specifed range of '10-20'
Step size of '2' will be ignored for this entry, since it exceeds the maximum possible step size of '1' for the specifed range of '4-4'
Step size of '3' will be ignored for this entry, since it exceeds the maximum possible step size of '1' for the specifed range of '1-2'

testfiles.zip

t8m commented 10 months ago

I'd prefer not changing the meaning. I.e., printing out a warning is a good idea but I would not set the value to 1.

Also I believe the current interpretation is a little bit different:

*/500 */400 */31 */12 */300 MyCommand

is interpreted as

0 0 1 1 0 MyCommand

alexxcons commented 9 months ago

I'd prefer not changing the meaning. I.e., printing out a warning is a good idea but I would not set the value to 1.

Thanks for review! Alright, changed accordingly.

t8m commented 9 months ago

Merged, thank you for your contribution!