typedef struct Context {
char *zone;
bool local_rtc;
- int can_ntp;
- int use_ntp;
+ unsigned can_ntp;
+ unsigned use_ntp;
Hashmap *polkit_registry;
} Context;
static void context_free(Context *c, sd_bus *bus) {
assert(c);
- free(c->zone);
+ context_reset(c);
bus_verify_polkit_async_registry_free(bus, c->polkit_registry);
}
"/run/systemd/ntp-units.d",
"/usr/local/lib/systemd/ntp-units.d",
"/usr/lib/systemd/ntp-units.d",
+#ifdef HAVE_SPLIT_USR
+ "/lib/systemd/ntp-units.d",
+#endif
NULL);
if (k < 0)
return NULL;
zero(tm);
r = hwclock_get_time(&tm);
- if (r < 0) {
+ if (r == -EBUSY) {
+ log_warning("/dev/rtc is busy, is somebody keeping it open continously? That's not a good idea... Returning a bogus RTC timestamp.");
+ t = 0;
+ } else if (r < 0) {
sd_bus_error_set_errnof(error, -r, "Failed to read RTC: %s", strerror(-r));
return r;
- }
-
- t = (usec_t) mktime(&tm) * USEC_PER_SEC;
+ } else
+ t = (usec_t) mktime(&tm) * USEC_PER_SEC;
r = sd_bus_message_append(reply, "t", t);
if (r < 0)
return 1;
}
+static int property_get_time(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ sd_bus_error *error,
+ void *userdata) {
+
+ int r;
+
+ r = sd_bus_message_append(reply, "t", now(CLOCK_REALTIME));
+ if (r < 0)
+ return r;
+
+ return 1;
+}
+
+static int property_get_ntp_sync(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ sd_bus_error *error,
+ void *userdata) {
+
+ int r;
+
+ r = sd_bus_message_append(reply, "b", ntp_synced());
+ if (r < 0)
+ return r;
+
+ return 1;
+}
+
static int method_set_timezone(sd_bus *bus, sd_bus_message *m, void *userdata) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
Context *c = userdata;
const char *z;
- bool interactive;
+ unsigned interactive;
char *t;
int r;
+ assert(bus);
+ assert(m);
+ assert(c);
+
r = sd_bus_message_read(m, "sb", &z, &interactive);
if (r < 0)
return sd_bus_reply_method_errno(bus, m, r, NULL);
static int method_set_local_rtc(sd_bus *bus, sd_bus_message *m, void *userdata) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
- bool lrtc, fix_system, interactive;
+ unsigned lrtc, fix_system, interactive;
Context *c = userdata;
struct timespec ts;
int r;
static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
- bool relative, interactive;
+ unsigned relative, interactive;
Context *c = userdata;
int64_t utc;
struct timespec ts;
static int method_set_ntp(sd_bus *bus, sd_bus_message *m, void *userdata) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
- bool ntp, interactive;
+ unsigned ntp, interactive;
Context *c = userdata;
int r;
SD_BUS_PROPERTY("LocalRTC", "b", NULL, offsetof(Context, local_rtc), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("CanNTP", "b", bus_property_get_tristate, offsetof(Context, can_ntp), 0),
SD_BUS_PROPERTY("NTP", "b", bus_property_get_tristate, offsetof(Context, use_ntp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+ SD_BUS_PROPERTY("NTPSynchronized", "b", property_get_ntp_sync, 0, 0),
+ SD_BUS_PROPERTY("TimeUSec", "t", property_get_time, 0, 0),
SD_BUS_PROPERTY("RTCTimeUSec", "t", property_get_rtc_time, 0, 0),
SD_BUS_METHOD("SetTime", "xbb", NULL, method_set_time, 0),
SD_BUS_METHOD("SetTimezone", "sb", NULL, method_set_timezone, 0),
int r;
log_set_target(LOG_TARGET_AUTO);
- log_set_max_level(LOG_DEBUG);
log_parse_environment();
log_open();
goto finish;
}
- sd_bus_flush(bus);
r = 0;
finish: