summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2019-04-12 20:57:51 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-04-25 11:27:40 +0200
commit10434dbdfd4e71ccef8b62309a4545c3b88aee29 (patch)
treea91c001f69ac58fdd385d32959ec83cf8e33451d
parentb6411f716c18e55192c442acbe8fe5595b0c14f4 (diff)
downloadsystemd-10434dbdfd4e71ccef8b62309a4545c3b88aee29.tar.gz
run: check if the specified calendar event is not in the past
Check if calendar event specification passed by --on-calendar runs in some time in the future. If not, execute the given command immediately
-rw-r--r--src/run/run.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/run/run.c b/src/run/run.c
index 56aa9aaee6..8a98177575 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -380,13 +380,31 @@ static int parse_argv(int argc, char *argv[]) {
arg_with_timer = true;
break;
- case ARG_ON_CALENDAR:
+ case ARG_ON_CALENDAR: {
+ _cleanup_(calendar_spec_freep) CalendarSpec *cs = NULL;
+ usec_t next, curr;
+
+ /* Let's make sure the given calendar event is not in the past */
+ curr = now(CLOCK_REALTIME);
+ r = calendar_spec_from_string(optarg, &cs);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse calendar event specification");
+ r = calendar_spec_next_usec(cs, curr, &next);
+ if (r < 0) {
+ /* The calendar event is in the past - in such case
+ * don't add an OnCalendar property and execute
+ * the command immediately instead */
+ log_warning("Specified calendar event is in the past, executing immediately");
+ break;
+ }
+
r = add_timer_property("OnCalendar", optarg);
if (r < 0)
return r;
arg_with_timer = true;
break;
+ }
case ARG_ON_TIMEZONE_CHANGE:
r = add_timer_property("OnTimezoneChange", "yes");