Merge pull request #15645 from poettering/calender-expression-doc-fix
some calendar expression fixes and documentation updates
This commit is contained in:
@@ -30,6 +30,9 @@
|
||||
* linked compenents anyway. */
|
||||
#define CALENDARSPEC_COMPONENTS_MAX 240
|
||||
|
||||
/* Let's make sure that the microsecond component is safe to be stored in an 'int' */
|
||||
assert_cc(INT_MAX >= USEC_PER_SEC);
|
||||
|
||||
static void chain_free(CalendarComponent *c) {
|
||||
CalendarComponent *n;
|
||||
|
||||
@@ -88,6 +91,16 @@ static void normalize_chain(CalendarComponent **c) {
|
||||
if (i->stop > i->start && i->repeat > 0)
|
||||
i->stop -= (i->stop - i->start) % i->repeat;
|
||||
|
||||
/* If a repeat value is specified, but it cannot even be triggered once, let's suppress
|
||||
* it.
|
||||
*
|
||||
* Similar, if the stop value is the same as the start value, then let's just make this a
|
||||
* non-repeating chain element */
|
||||
if ((i->stop > i->start && i->repeat > 0 && i->start + i->repeat > i->stop) ||
|
||||
i->start == i->stop) {
|
||||
i->repeat = 0;
|
||||
i->stop = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (n <= 1)
|
||||
@@ -162,7 +175,7 @@ int calendar_spec_normalize(CalendarSpec *c) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
_pure_ static bool chain_valid(CalendarComponent *c, int from, int to, bool end_of_month) {
|
||||
static bool chain_valid(CalendarComponent *c, int from, int to, bool end_of_month) {
|
||||
assert(to >= from);
|
||||
|
||||
if (!c)
|
||||
@@ -366,14 +379,13 @@ int calendar_spec_to_string(const CalendarSpec *c, char **p) {
|
||||
}
|
||||
|
||||
r = fflush_and_check(f);
|
||||
fclose(f);
|
||||
|
||||
if (r < 0) {
|
||||
free(buf);
|
||||
fclose(f);
|
||||
return r;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
*p = buf;
|
||||
return 0;
|
||||
}
|
||||
@@ -643,6 +655,12 @@ static int prepend_component(const char **p, bool usec, unsigned nesting, Calend
|
||||
|
||||
if (repeat == 0)
|
||||
return -ERANGE;
|
||||
} else {
|
||||
/* If no repeat value is specified for the µs component, then let's explicitly refuse ranges
|
||||
* below 1s because our default repeat granularity is beyond that. */
|
||||
|
||||
if (usec && stop >= 0 && start + repeat > stop)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!IN_SET(*e, 0, ' ', ',', '-', '~', ':'))
|
||||
|
||||
@@ -19,9 +19,9 @@ typedef struct CalendarComponent {
|
||||
|
||||
typedef struct CalendarSpec {
|
||||
int weekdays_bits;
|
||||
bool end_of_month;
|
||||
bool utc;
|
||||
int dst;
|
||||
bool end_of_month:1;
|
||||
bool utc:1;
|
||||
signed int dst:2;
|
||||
char *timezone;
|
||||
|
||||
CalendarComponent *year;
|
||||
|
||||
Reference in New Issue
Block a user