]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: when we determine a timer cannot elapse anymore, really just warn, nothing else 12394/head
authorLennart Poettering <lennart@poettering.net>
Thu, 25 Apr 2019 11:22:55 +0000 (13:22 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 25 Apr 2019 11:40:01 +0000 (13:40 +0200)
When we determine that a calendar expression cannot elapse anymore,
print a warning but proceed regardless like we normally would.

Quite possibly a remote system has a different understanding of time
(timezone, system clock) than we have, hence we really shouldn't change
behaviour here client side, but log at best, and then leave the decision
what to do to the server side.

Follow-up for #12299

src/run/run.c

index 6a0b0d78b981a513ab41aded7a2454e189e880d9..babd9027e49fd039c9bd7cd4e5bc8f61fd6da0c6 100644 (file)
@@ -382,21 +382,22 @@ static int parse_argv(int argc, char *argv[]) {
 
                 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;
-                        }
+                                return log_error_errno(r, "Failed to parse calendar event specification: %m");
+
+                        r = calendar_spec_next_usec(cs, now(CLOCK_REALTIME), NULL);
+                        if (r == -ENOENT)
+                                /* The calendar event is in the past - let's warn about this, but install it
+                                 * anyway as it is. The service manager will trigger the service right-away
+                                 * then, but everything is discoverable as usual. Moreover, the server side
+                                 * might have a different clock or timezone than we do, hence it should
+                                 * decide when or whether to run something. */
+                                log_warning("Specified calendar expression is in the past, proceeding anyway.");
+                        else if (r < 0)
+                                return log_error_errno(r, "Failed to calculate next time calendar expression elapses: %m");
 
                         r = add_timer_property("OnCalendar", optarg);
                         if (r < 0)