[Spice-devel] [PATCH spice-server 4/5] reds: Use monotonic time for ticket expiration

Christophe Fergeau cfergeau at redhat.com
Tue Oct 9 11:40:53 UTC 2018


On Tue, Oct 09, 2018 at 09:30:05AM +0100, Frediano Ziglio wrote:
> 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(&ltime);
> +        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;

return g_get_monotonic_time() / MSEC_PER_SEC ?

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20181009/ff3e3b46/attachment.sig>


More information about the Spice-devel mailing list