[Spice-devel] [PATCH spice-server 4/5] reds: Use monotonic time for ticket expiration
Frediano Ziglio
fziglio at redhat.com
Tue Oct 9 08:30:05 UTC 2018
Avoid time adjustment issues.
For instance ticket validity can change when daylight time changes.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
server/reds.c | 5 ++---
server/utils.h | 8 ++++++++
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/server/reds.c b/server/reds.c
index 5c2e8cb0..b11bd7df 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2099,8 +2099,7 @@ static void reds_handle_ticket(void *opaque)
goto error;
}
- //todo: use monotonic time
- time(<ime);
+ ltime = spice_get_monotonic_time_s();
expired = (reds->config->taTicket.expiration_time < ltime);
if (expired) {
@@ -3835,7 +3834,7 @@ SPICE_GNUC_VISIBLE int spice_server_set_ticket(SpiceServer *reds,
if (lifetime == 0) {
reds->config->taTicket.expiration_time = INT_MAX;
} else {
- time_t now = time(NULL);
+ time_t now = spice_get_monotonic_time_s();
reds->config->taTicket.expiration_time = now + lifetime;
}
if (passwd != NULL) {
diff --git a/server/utils.h b/server/utils.h
index 07878539..18ee6308 100644
--- a/server/utils.h
+++ b/server/utils.h
@@ -66,6 +66,14 @@ static inline red_time_t spice_get_monotonic_time_ns(void)
#define MSEC_PER_SEC 1000
+static inline time_t spice_get_monotonic_time_s(void)
+{
+ struct timespec time;
+
+ clock_gettime(CLOCK_MONOTONIC, &time);
+ return time.tv_sec;
+}
+
int rgb32_data_has_alpha(int width, int height, size_t stride,
const uint8_t *data, int *all_set_out);
--
2.17.1
More information about the Spice-devel
mailing list