[systemd-commits] 2 commits - CODING_STYLE man/systemd.time.xml src/shared src/test
Lennart Poettering
lennart at kemper.freedesktop.org
Mon Oct 27 10:12:50 PDT 2014
CODING_STYLE | 6 +++-
man/systemd.time.xml | 13 +++++----
src/shared/calendarspec.c | 59 ++++++++++++++++++++++++++++++++++++++++---
src/test/test-calendarspec.c | 4 ++
4 files changed, 73 insertions(+), 9 deletions(-)
New commits:
commit 7f8bf08f9036de419ad14c55b61eda74c6659d3a
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Oct 27 18:09:07 2014 +0100
CODING_STYLE: don't clobber arguments on failure
diff --git a/CODING_STYLE b/CODING_STYLE
index 598d241..4439ee6 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -182,7 +182,11 @@
is_main_thread() to detect whether the calling thread is the main
thread.
-- Option parsing:
+- Command line option parsing:
- Do not print full help() on error, be specific about the error.
- Do not print messages to stdout on error.
- Do not POSIX_ME_HARDER unless necessary, i.e. avoid "+" in option string.
+
+- Do not write functions that clobber call-by-reference variables on
+ failure. Use temporary variables for these cases and change the
+ passed in variables only on success.
commit dbfd41e2df44113d1d2d07fb751db11b443f186b
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Oct 27 18:08:46 2014 +0100
calendarspec: parse 'quarterly' and 'semi-annually' as shortcuts
diff --git a/man/systemd.time.xml b/man/systemd.time.xml
index 6e7dbc5..f35ccd7 100644
--- a/man/systemd.time.xml
+++ b/man/systemd.time.xml
@@ -245,15 +245,18 @@
<literal>minutely</literal>,
<literal>hourly</literal>, <literal>daily</literal>,
<literal>monthly</literal>, <literal>weekly</literal>,
- and <literal>yearly</literal> or
- <literal>annually</literal> may be used as calendar
- events which refer to
+ <literal>yearly</literal>,
+ <literal>quarterly</literal>,
+ <literal>semiannually</literal> may be used as
+ calendar events which refer to
<literal>*-*-* *:*:00</literal>,
<literal>*-*-* *:00:00</literal>,
<literal>*-*-* 00:00:00</literal>,
<literal>*-*-01 00:00:00</literal>,
- <literal>Mon *-*-* 00:00:00</literal>, and
- <literal>*-01-01 00:00:00</literal> respectively.
+ <literal>Mon *-*-* 00:00:00</literal>,
+ <literal>*-01-01 00:00:00</literal>,
+ <literal>*-01,04,07,10-01 00:00:0</literal> and
+ <literal>*-01,07-01 00:00:00</literal> respectively.
</para>
<para>Examples for valid timestamps and their
diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c
index da920b6..7efcf7b 100644
--- a/src/shared/calendarspec.c
+++ b/src/shared/calendarspec.c
@@ -474,7 +474,7 @@ static int const_chain(int value, CalendarComponent **c) {
cc->value = value;
cc->repeat = 0;
- cc->next = NULL;
+ cc->next = *c;
*c = cc;
@@ -693,8 +693,10 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
if (r < 0)
goto fail;
- } else if (strcaseeq(p, "annually") || strcaseeq(p, "yearly")
- || strcaseeq(p, "anually") /* backwards compatibility */ ) {
+ } else if (strcaseeq(p, "annually") ||
+ strcaseeq(p, "yearly") ||
+ strcaseeq(p, "anually") /* backwards compatibility */ ) {
+
r = const_chain(1, &c->month);
if (r < 0)
goto fail;
@@ -725,6 +727,57 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
if (r < 0)
goto fail;
+ } else if (strcaseeq(p, "quarterly")) {
+
+ r = const_chain(1, &c->month);
+ if (r < 0)
+ goto fail;
+ r = const_chain(4, &c->month);
+ if (r < 0)
+ goto fail;
+ r = const_chain(7, &c->month);
+ if (r < 0)
+ goto fail;
+ r = const_chain(10, &c->month);
+ if (r < 0)
+ goto fail;
+ r = const_chain(1, &c->day);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->hour);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->minute);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->second);
+ if (r < 0)
+ goto fail;
+
+ } else if (strcaseeq(p, "biannually") ||
+ strcaseeq(p, "bi-annually") ||
+ strcaseeq(p, "semiannually") ||
+ strcaseeq(p, "semi-annually")) {
+
+ r = const_chain(1, &c->month);
+ if (r < 0)
+ goto fail;
+ r = const_chain(7, &c->month);
+ if (r < 0)
+ goto fail;
+ r = const_chain(1, &c->day);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->hour);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->minute);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->second);
+ if (r < 0)
+ goto fail;
+
} else {
r = parse_weekdays(&p, c);
if (r < 0)
diff --git a/src/test/test-calendarspec.c b/src/test/test-calendarspec.c
index 21b0024..87e1da1 100644
--- a/src/test/test-calendarspec.c
+++ b/src/test/test-calendarspec.c
@@ -77,6 +77,10 @@ int main(int argc, char* argv[]) {
test_one("daily", "*-*-* 00:00:00");
test_one("monthly", "*-*-01 00:00:00");
test_one("weekly", "Mon *-*-* 00:00:00");
+ test_one("minutely", "*-*-* *:*:00");
+ test_one("quarterly", "*-01,04,07,10-01 00:00:00");
+ test_one("semi-annually", "*-01,07-01 00:00:00");
+ test_one("annually", "*-01-01 00:00:00");
test_one("*:2/3", "*-*-* *:02/3:00");
assert_se(calendar_spec_from_string("test", &c) < 0);
More information about the systemd-commits
mailing list