src: Stop using g_get_current_time()

It isn't 2k38 safe and has therefore been deprecated. Replace it
with GDateTime or g_get_real_time() as appropriate.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/657
This commit is contained in:
Florian Müllner 2019-07-31 20:29:46 +02:00 committed by Georges Basile Stavracas Neto
parent 5d8ea4f9a3
commit 9b7f228f8e
4 changed files with 22 additions and 36 deletions

View File

@ -1102,12 +1102,10 @@ main (int argc,
static void __attribute__((format(printf, 1, 0))) static void __attribute__((format(printf, 1, 0)))
print_debug (const gchar *format, ...) print_debug (const gchar *format, ...)
{ {
gchar *s; g_autofree char *s = NULL;
g_autofree char *timestamp = NULL;
va_list ap; va_list ap;
gchar timebuf[64]; g_autoptr (GDateTime) now = NULL;
GTimeVal now;
time_t now_t;
struct tm broken_down;
static volatile gsize once_init_value = 0; static volatile gsize once_init_value = 0;
static gboolean show_debug = FALSE; static gboolean show_debug = FALSE;
static guint pid = 0; static guint pid = 0;
@ -1122,17 +1120,15 @@ print_debug (const gchar *format, ...)
if (!show_debug) if (!show_debug)
goto out; goto out;
g_get_current_time (&now); now = g_date_time_new_now_local ();
now_t = now.tv_sec; timestamp = g_date_time_format (now, "%H:%M:%S");
localtime_r (&now_t, &broken_down);
strftime (timebuf, sizeof timebuf, "%H:%M:%S", &broken_down);
va_start (ap, format); va_start (ap, format);
s = g_strdup_vprintf (format, ap); s = g_strdup_vprintf (format, ap);
va_end (ap); va_end (ap);
g_print ("gnome-shell-calendar-server[%d]: %s.%03d: %s\n", pid, timebuf, (gint) (now.tv_usec / 1000), s); g_print ("gnome-shell-calendar-server[%d]: %s.%03d: %s\n",
g_free (s); pid, timestamp, g_date_time_get_microsecond (now), s);
out: out:
; ;
} }

View File

@ -269,12 +269,10 @@ main (int argc,
static void __attribute__((format(printf, 1, 0))) static void __attribute__((format(printf, 1, 0)))
print_debug (const gchar *format, ...) print_debug (const gchar *format, ...)
{ {
gchar *s; g_autofree char *s = NULL;
g_autofree char *timestamp = NULL;
va_list ap; va_list ap;
gchar timebuf[64]; g_autoptr (GDateTime) now = NULL;
GTimeVal now;
time_t now_t;
struct tm broken_down;
static volatile gsize once_init_value = 0; static volatile gsize once_init_value = 0;
static gboolean show_debug = FALSE; static gboolean show_debug = FALSE;
static guint pid = 0; static guint pid = 0;
@ -289,17 +287,15 @@ print_debug (const gchar *format, ...)
if (!show_debug) if (!show_debug)
goto out; goto out;
g_get_current_time (&now); now = g_date_time_new_now_local ();
now_t = now.tv_sec; timestamp = g_date_time_format (now, "%H:%M:%S");
localtime_r (&now_t, &broken_down);
strftime (timebuf, sizeof timebuf, "%H:%M:%S", &broken_down);
va_start (ap, format); va_start (ap, format);
s = g_strdup_vprintf (format, ap); s = g_strdup_vprintf (format, ap);
va_end (ap); va_end (ap);
g_print ("gnome-shell-hotplug-sniffer[%d]: %s.%03d: %s\n", pid, timebuf, (gint) (now.tv_usec / 1000), s); g_print ("gnome-shell-hotplug-sniffer[%d]: %s.%03d: %s\n",
g_free (s); pid, timestamp, g_date_time_get_microsecond (now), s);
out: out:
; ;
} }

View File

@ -123,9 +123,7 @@ static void on_enable_monitoring_key_changed (GSettings *settings,
static long static long
get_time (void) get_time (void)
{ {
GTimeVal tv; return g_get_real_time () / G_TIME_SPAN_SECOND;
g_get_current_time (&tv);
return tv.tv_sec;
} }
static void static void

View File

@ -21,24 +21,20 @@
static void static void
print_debug (const gchar *format, ...) print_debug (const gchar *format, ...)
{ {
gchar *s; g_autofree char *s = NULL;
g_autofree char *timestamp = NULL;
g_autoptr (GDateTime) now = NULL;
va_list ap; va_list ap;
gchar timebuf[64];
GTimeVal now;
time_t now_t;
struct tm broken_down;
g_get_current_time (&now); now = g_date_time_new_now_local ();
now_t = now.tv_sec; timestamp = g_date_time_format (now, "%H:%M:%S");
localtime_r (&now_t, &broken_down);
strftime (timebuf, sizeof timebuf, "%H:%M:%S", &broken_down);
va_start (ap, format); va_start (ap, format);
s = g_strdup_vprintf (format, ap); s = g_strdup_vprintf (format, ap);
va_end (ap); va_end (ap);
g_print ("ShellPolkitAuthenticationAgent: %s.%03d: %s\n", timebuf, (gint) (now.tv_usec / 1000), s); g_print ("ShellPolkitAuthenticationAgent: %s.%03d: %s\n",
g_free (s); timestamp, g_date_time_get_microsecond (now), s);
} }
#else #else
static void static void