timedate: refuse to set time when previous request is not finished
If `timedatectl set-time` is invoked right after `timedatectl set-ntp true`, then, the NTP service may not be started yet. Fixes #11420.
This commit is contained in:
@@ -523,6 +523,10 @@ static int property_get_can_ntp(
|
|||||||
assert(reply);
|
assert(reply);
|
||||||
assert(error);
|
assert(error);
|
||||||
|
|
||||||
|
if (c->slot_job_removed)
|
||||||
|
/* When the previous request is not finished, then assume NTP is enabled. */
|
||||||
|
return sd_bus_message_append(reply, "b", true);
|
||||||
|
|
||||||
r = context_update_ntp_status(c, bus, reply);
|
r = context_update_ntp_status(c, bus, reply);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
@@ -548,6 +552,10 @@ static int property_get_ntp(
|
|||||||
assert(reply);
|
assert(reply);
|
||||||
assert(error);
|
assert(error);
|
||||||
|
|
||||||
|
if (c->slot_job_removed)
|
||||||
|
/* When the previous request is not finished, then assume NTP is active. */
|
||||||
|
return sd_bus_message_append(reply, "b", true);
|
||||||
|
|
||||||
r = context_update_ntp_status(c, bus, reply);
|
r = context_update_ntp_status(c, bus, reply);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
@@ -735,6 +743,9 @@ static int method_set_time(sd_bus_message *m, void *userdata, sd_bus_error *erro
|
|||||||
assert(m);
|
assert(m);
|
||||||
assert(c);
|
assert(c);
|
||||||
|
|
||||||
|
if (c->slot_job_removed)
|
||||||
|
return sd_bus_error_set(error, BUS_ERROR_AUTOMATIC_TIME_SYNC_ENABLED, "Previous request is not finished, refusing.");
|
||||||
|
|
||||||
r = context_update_ntp_status(c, bus, m);
|
r = context_update_ntp_status(c, bus, m);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return sd_bus_error_set_errnof(error, r, "Failed to update context: %m");
|
return sd_bus_error_set_errnof(error, r, "Failed to update context: %m");
|
||||||
|
|||||||
Reference in New Issue
Block a user