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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On Tue, Oct 09, 2018 at 07:48:00AM -0400, Frediano Ziglio wrote:
> > > 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@xxxxxxxxxx>
> > > > ---
> > > >  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
> > > 
> > 
> > So, instead of calling a function A: call a function B that calls function
> > A,
> > does some computation, return the computation, then revert the computation
> > done by function B to get the result from function A. Does not seem really
> > clever to me.
> > 
> > Beside would be g_get_monotonic_time() / USEC_PER_SEC.
> 
> We have one part of the code calling g_get_monotonic_time(), another
> helper calling CLOCK_MONOTONIC because we want nanosecond resolution,
> and now you suggest adding a 3rd one. I'd rather we have a single way of
> getting monotonic time rather than trying to be clever.
> 
> Christophe
>

Then it has to be CLOCK_MONOTONIC as g_get_monotonic_time does not provide
enough precision for nanoseconds.

Frediano
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]