[gnome-keyring/wip/nielsdg/fix-warnings: 6/7] Don't use GTimeVal/g_get_current_time()



commit ce60975698b24f3836303c91b5bfacf3b94387a8
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Thu Jan 2 22:27:35 2020 +0100

    Don't use GTimeVal/g_get_current_time()
    
    `GTimeVal` is not safe for a post-2038 world, so it was deprecated.
    Let's get rid of it in favor of `g_get_real_time()`.

 pkcs11/gkm/gkm-object.c                  | 20 +++++++++-----------
 pkcs11/secret-store/gkm-secret-object.c  | 15 +++------------
 pkcs11/secret-store/test-secret-object.c |  6 +++---
 3 files changed, 15 insertions(+), 26 deletions(-)
---
diff --git a/pkcs11/gkm/gkm-object.c b/pkcs11/gkm/gkm-object.c
index 7ca68989..b44c19c8 100644
--- a/pkcs11/gkm/gkm-object.c
+++ b/pkcs11/gkm/gkm-object.c
@@ -105,7 +105,7 @@ timer_callback (GkmTimer *timer, gpointer user_data)
        GkmObject *self = user_data;
        glong after, idle, offset;
        GkmObjectTransient *transient;
-       GTimeVal tv;
+       gint64 now;
 
        g_return_if_fail (GKM_IS_OBJECT (self));
 
@@ -116,19 +116,19 @@ timer_callback (GkmTimer *timer, gpointer user_data)
        g_return_if_fail (timer == transient->timer);
        transient->timer = NULL;
 
-       g_get_current_time (&tv);
+       now = g_get_real_time () / G_USEC_PER_SEC;
        idle = after = G_MAXLONG;
 
        /* Are we supposed to be destroyed after a certain time? */
        if (transient->timed_after) {
                g_return_if_fail (transient->stamp_created);
-               after = (transient->stamp_created + transient->timed_after) - tv.tv_sec;
+               after = (transient->stamp_created + transient->timed_after) - now;
        }
 
        /* Are we supposed to be destroyed after an idle time? */
        if (transient->timed_idle) {
                g_return_if_fail (transient->stamp_used);
-               idle = (transient->stamp_used + transient->timed_idle) - tv.tv_sec;
+               idle = (transient->stamp_used + transient->timed_idle) - now;
        }
 
        /* Okay, time to destroy? */
@@ -148,16 +148,16 @@ start_callback (GkmTransaction *transaction, GObject *obj, gpointer user_data)
 {
        GkmObject *self = GKM_OBJECT (obj);
        GkmObjectTransient *transient;
-       GTimeVal tv;
+       gint64 now;
 
        g_return_val_if_fail (GKM_IS_OBJECT (self), FALSE);
        g_return_val_if_fail (self->pv->transient, FALSE);
        transient = self->pv->transient;
        g_return_val_if_fail (!transient->timer, FALSE);
 
-       g_get_current_time (&tv);
-       transient->stamp_created = tv.tv_sec;
-       transient->stamp_used = tv.tv_sec;
+       now = g_get_real_time () / G_USEC_PER_SEC;
+       transient->stamp_created = now;
+       transient->stamp_used = now;
 
        /* Start the timer going */
        timer_callback (NULL, self);
@@ -742,15 +742,13 @@ void
 gkm_object_mark_used (GkmObject *self)
 {
        GkmObjectTransient *transient;
-       GTimeVal tv;
 
        g_return_if_fail (GKM_IS_OBJECT (self));
        transient = self->pv->transient;
 
        if (transient) {
                if (transient->timed_idle) {
-                       g_get_current_time (&tv);
-                       transient->stamp_used = tv.tv_sec;
+                       transient->stamp_used = g_get_real_time () / G_USEC_PER_SEC;
                }
                if (transient->uses_remaining) {
                        --(transient->uses_remaining);
diff --git a/pkcs11/secret-store/gkm-secret-object.c b/pkcs11/secret-store/gkm-secret-object.c
index acc63707..53948dc3 100644
--- a/pkcs11/secret-store/gkm-secret-object.c
+++ b/pkcs11/secret-store/gkm-secret-object.c
@@ -357,13 +357,10 @@ gkm_secret_object_get_created (GkmSecretObject *self)
 void
 gkm_secret_object_set_created (GkmSecretObject *self, glong when)
 {
-       GTimeVal tv;
-
        g_return_if_fail (GKM_IS_SECRET_OBJECT (self));
 
        if (when < 0) {
-               g_get_current_time (&tv);
-               when = tv.tv_sec;
+               when = g_get_real_time () / G_USEC_PER_SEC;
        }
 
        self->pv->created = when;
@@ -373,12 +370,9 @@ gkm_secret_object_set_created (GkmSecretObject *self, glong when)
 void
 gkm_secret_object_mark_created (GkmSecretObject *self)
 {
-       GTimeVal tv;
-
        g_return_if_fail (GKM_IS_SECRET_OBJECT (self));
 
-       g_get_current_time (&tv);
-       gkm_secret_object_set_created (self, tv.tv_sec);
+       gkm_secret_object_set_created (self, g_get_real_time () / G_USEC_PER_SEC);
 }
 
 glong
@@ -420,14 +414,11 @@ void
 gkm_secret_object_begin_modified (GkmSecretObject *self,
                                   GkmTransaction *transaction)
 {
-       GTimeVal tv;
-
        g_return_if_fail (!gkm_transaction_get_failed (transaction));
        gkm_transaction_add (transaction, self, complete_set_modified,
                             g_memdup (&self->pv->modified, sizeof (gulong)));
 
-       g_get_current_time (&tv);
-       self->pv->modified = tv.tv_sec;
+       self->pv->modified = g_get_real_time () / G_USEC_PER_SEC;
 }
 
 gboolean
diff --git a/pkcs11/secret-store/test-secret-object.c b/pkcs11/secret-store/test-secret-object.c
index 9855c061..122f210d 100644
--- a/pkcs11/secret-store/test-secret-object.c
+++ b/pkcs11/secret-store/test-secret-object.c
@@ -129,15 +129,15 @@ static void
 test_was_modified (Test *test, gconstpointer unused)
 {
        GkmTransaction *transaction;
-       GTimeVal tv;
+       gint64 now;
 
-       g_get_current_time (&tv);
+       now = g_get_real_time () / G_USEC_PER_SEC;
 
        transaction = gkm_transaction_new ();
        gkm_secret_object_begin_modified (test->object, transaction);
        g_assert_cmpuint (gkm_transaction_complete_and_unref (transaction), ==, CKR_OK);
 
-       g_assert (tv.tv_sec == gkm_secret_object_get_modified (test->object));
+       g_assert (now == gkm_secret_object_get_modified (test->object));
 }
 
 static void


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