[Spice-devel] [PATCH spice-server 4/5] reds: Use monotonic time for ticket expiration
Frediano Ziglio
fziglio at redhat.com
Tue Oct 9 11:48:00 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(<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;
>
> 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.
Frediano
More information about the Spice-devel
mailing list