[Spice-devel] [PATCH spice-server 4/5] reds: Use monotonic time for ticket expiration
Christophe Fergeau
cfergeau at redhat.com
Tue Oct 9 11:50:51 UTC 2018
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 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.
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
>
> Frediano
-------------- 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/6ecfcdc5/attachment.sig>
More information about the Spice-devel
mailing list