booth/0003-Feature-alternative-range2random-provider-glib.patch
Jan Pokorný 0c140f2bb9
1.0-3.570876d.git - update per the changesets recently accepted
...by the upstream (memory/resource leaks fixes, patches previously
attached separately that make unit test pass, internal cleanups, etc.)

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2016-05-25 10:14:11 +02:00

180 lines
6.0 KiB
Diff

From cd8c7245e4f50269ec62b36cb56ef21e659c7578 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= <jpokorny@redhat.com>
Date: Wed, 24 Feb 2016 02:12:34 +0100
Subject: [PATCH 3/6] Feature: alternative range2random provider: glib
Also check if cl_rand_from_interval is actually defined in
<clplumbing/cl_random.h> (not the case with older glue/plumb lib).
---
booth.spec | 2 ++
configure.ac | 24 ++++++++++++++++++++++++
src/Makefile.am | 8 ++++++++
src/alt/range2random_glib.c | 33 +++++++++++++++++++++++++++++++++
src/alt/range2random_glib.h | 22 ++++++++++++++++++++++
src/ticket.c | 6 +++++-
6 files changed, 94 insertions(+), 1 deletion(-)
create mode 100644 src/alt/range2random_glib.c
create mode 100644 src/alt/range2random_glib.h
diff --git a/booth.spec b/booth.spec
index cc73af2..b88ff4c 100644
--- a/booth.spec
+++ b/booth.spec
@@ -69,6 +69,8 @@ BuildRequires: libglue-devel
%else
# logging provider
BuildRequires: pkgconfig(libqb)
+# random2range provider
+BuildRequires: pkgconfig(glib-2.0)
%endif
BuildRequires: libxml2-devel
BuildRequires: zlib-devel
diff --git a/configure.ac b/configure.ac
index 32a7dd1..10e131d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -245,6 +245,29 @@ libqb)
esac
AM_CONDITIONAL([LOGGING_LIBQB], [test "x$logging_provider" = "xlibqb"])
+# figure out range2random provider
+range2random_provider=""
+if test "x$range2random_provider" = "x" && test "x$with_glue" = "xyes"; then
+ AC_CHECK_LIB([plumb], [get_next_random], [range2random_provider="libplumb"])
+ AC_CHECK_DECL([cl_rand_from_interval], [], [range2random_provider=""],
+ [#include <clplumbing/cl_random.h>])
+fi
+if test "x$range2random_provider" = "x" && test "x$with_glue" = "xno"; then
+ AC_CHECK_LIB([glib-2.0], [g_random_int_range], [range2random_provider="glib"])
+fi
+case "$range2random_provider" in
+libplumb)
+ ;;
+glib)
+ PKG_CHECK_MODULES([GLIB], [glib-2.0])
+ AC_DEFINE([RANGE2RANDOM_GLIB], [], [use glib as a range2random provider])
+ ;;
+*)
+ AC_MSG_ERROR([range2random provider required (libplumb, or glib when --without-glue)])
+ ;;
+esac
+AM_CONDITIONAL([RANGE2RANDOM_GLIB], [test "x$range2random_provider" = "xglib"])
+
# OS detection
# THIS SECTION MUST DIE!
CP=cp
@@ -474,6 +497,7 @@ AC_MSG_RESULT([ booth config dir = ${BOOTHSYSCONFDIR}])
AC_MSG_RESULT([ SOCKETDIR = ${SOCKETDIR}])
AC_MSG_RESULT([ Features = ${PACKAGE_FEATURES}])
AC_MSG_RESULT([ Logging provider = ${logging_provider}])
+AC_MSG_RESULT([ Range2random provider = ${range2random_provider}])
AC_MSG_RESULT([])
AC_MSG_RESULT([$PACKAGE build info:])
AC_MSG_RESULT([ Library SONAME = ${SONAME}])
diff --git a/src/Makefile.am b/src/Makefile.am
index 49c3ac4..317710e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,5 +33,13 @@ boothd_SOURCES += alt/logging_libqb.c
noinst_HEADERS += alt/logging_libqb.h
endif
+if !RANGE2RANDOM_GLIB
+boothd_LDADD += -lplumb
+else
+boothd_LDADD += $(GLIB_LIBS)
+boothd_SOURCES += alt/range2random_glib.c
+noinst_HEADERS += alt/range2random_glib.h
+endif
+
lint:
-splint $(INCLUDES) $(LINT_FLAGS) $(CFLAGS) *.c
diff --git a/src/alt/range2random_glib.c b/src/alt/range2random_glib.c
new file mode 100644
index 0000000..8363559
--- /dev/null
+++ b/src/alt/range2random_glib.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2016 Jan Pokorny <jpokorny@redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include <glib.h>
+
+#include "range2random_glib.h"
+#include "ticket.h"
+
+int
+alt_glib_rand_from_interval(int from, int to)
+{
+ assert(from >= 0 && from < to);
+ assert(sizeof(to) <= sizeof(gint32) || (to < 0x7fffffff));
+ return (int) g_random_int_range(from, to);
+}
diff --git a/src/alt/range2random_glib.h b/src/alt/range2random_glib.h
new file mode 100644
index 0000000..4b87c46
--- /dev/null
+++ b/src/alt/range2random_glib.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2016 Jan Pokorny <jpokorny@redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+int alt_glib_rand_from_interval(int from, int to);
+
+#define cl_rand_from_interval(from, to) \
+ alt_glib_rand_from_interval(from, to)
diff --git a/src/ticket.c b/src/ticket.c
index 09743f7..8d4cc12 100644
--- a/src/ticket.c
+++ b/src/ticket.c
@@ -25,8 +25,12 @@
#include <stdio.h>
#include <assert.h>
#include <time.h>
-#include <clplumbing/cl_random.h>
#include "b_config.h"
+#ifndef RANGE2RANDOM_GLIB
+#include <clplumbing/cl_random.h>
+#else
+#include "alt/range2random_glib.h"
+#endif
#include "ticket.h"
#include "config.h"
#include "pacemaker.h"
--
2.4.11