[syslog-ng] [PATCH] Don't use deprecated glib symbols on newer glibs

Gergely Nagy algernon at balabit.hu
Fri May 4 19:50:29 CEST 2012


A couple of symbols have been deprecated by glib in versions newer
than the minimum version syslog-ng supports, and with 2.30 which
deprecated g_atomic_int_exchange_and_add(), these warnings are way
over the normal threshold, and turn build logs into not much more than
noise.

This patch solves this issue by checking the glib version at compile
time, and deciding then which functions to use. This makes it possible
to remain compatible with ancient glib, yet, still compile without
deprecation warnings on systems with recent glibs.

No functionality is lost or changed, just different interfaces used to
accomplish the same thing.

Signed-off-by: Gergely Nagy <algernon at balabit.hu>
---
 lib/atomic.h              |    4 ++++
 lib/timeutils.c           |    8 ++++++++
 syslog-ng/syslog-ng-ctl.c |   12 ++++++++----
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/lib/atomic.h b/lib/atomic.h
index 05cfb88..32d421e 100644
--- a/lib/atomic.h
+++ b/lib/atomic.h
@@ -52,7 +52,11 @@ g_atomic_counter_get(GAtomicCounter *c)
 static inline gint
 g_atomic_counter_exchange_and_add(GAtomicCounter *c, gint val)
 {
+#if GLIB_CHECK_VERSION(2, 30, 0)
+  return g_atomic_int_add(&c->counter, val);
+#else
   return g_atomic_int_exchange_and_add(&c->counter, val);
+#endif
 }
 
 static inline gint
diff --git a/lib/timeutils.c b/lib/timeutils.c
index 9e7822b..313d61c 100644
--- a/lib/timeutils.c
+++ b/lib/timeutils.c
@@ -844,7 +844,11 @@ zone_info_read(const gchar *zonename, ZoneInfo **zone, ZoneInfo **zone64)
   if (byte_read == -1)
     {
       msg_error("Failed to read the time zone file", evt_tag_str("filename", filename), NULL);
+#if GLIB_CHECK_VERSION(2, 22, 0)
+      g_mapped_file_unref(file_map);
+#else
       g_mapped_file_free(file_map);
+#endif
       g_free(filename);
       return FALSE;
     }
@@ -857,7 +861,11 @@ zone_info_read(const gchar *zonename, ZoneInfo **zone, ZoneInfo **zone64)
       *zone64 = zone_info_parser(&buff, TRUE, &version);
     }
 
+#if GLIB_CHECK_VERSION(2, 22, 0)
+  g_mapped_file_unref(file_map);
+#else
   g_mapped_file_free(file_map);
+#endif
     g_free(filename);
   return TRUE;
 }
diff --git a/syslog-ng/syslog-ng-ctl.c b/syslog-ng/syslog-ng-ctl.c
index 25948b0..16348f1 100644
--- a/syslog-ng/syslog-ng-ctl.c
+++ b/syslog-ng/syslog-ng-ctl.c
@@ -131,7 +131,7 @@ slng_verbose(int argc, char *argv[], const gchar *mode)
 {
   gint ret = 0;
   GString *rsp = NULL;
-  gchar buff[256];
+  gchar buff[256], *ubuff;
 
   if (!verbose_set)
     snprintf(buff, 255, "LOG %s\n", mode);
@@ -139,10 +139,14 @@ slng_verbose(int argc, char *argv[], const gchar *mode)
     snprintf(buff, 255, "LOG %s %s\n", mode,
         strncasecmp(verbose_set, "on", 2) == 0 || verbose_set[0] == '1' ? "ON" : "OFF");
 
-  g_strup(buff);
+  ubuff = g_ascii_strup(buff, -1);
 
-  if (!(slng_send_cmd(buff) && ((rsp = slng_read_response()) != NULL)))
-    return 1;
+  if (!(slng_send_cmd(ubuff) && ((rsp = slng_read_response()) != NULL)))
+    {
+      g_free(ubuff);
+      return 1;
+    }
+  g_free(ubuff);
 
   if (!verbose_set)
     printf("%s\n", rsp->str);
-- 
1.7.10




More information about the syslog-ng mailing list