intel-lpmd/29.patch
Kate Hsuan c0aacb2931 Deprecate dbus-glib
Remove the dependency on dbus-glib.
2024-06-07 16:10:44 +08:00

315 lines
9.5 KiB
Diff

From 32ff889c57597fb0c1161ce4a380d333a8efc024 Mon Sep 17 00:00:00 2001
From: Kate Hsuan <hpa@redhat.com>
Date: Fri, 7 Jun 2024 10:46:31 +0800
Subject: [PATCH 1/3] lpmd_dbus_server: Drop the codes for dbus-glib
dbus-glib was deprecated so the related codes can be removed.
---
src/lpmd.h | 3 ---
src/lpmd_dbus_server.c | 54 ------------------------------------------
2 files changed, 57 deletions(-)
diff --git a/src/lpmd.h b/src/lpmd.h
index 12661f6..55aced3 100644
--- a/src/lpmd.h
+++ b/src/lpmd.h
@@ -45,9 +45,6 @@
#ifdef GLIB_SUPPORT
#include <glib.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <dbus/dbus-glib.h>
#include <glib/gi18n.h>
#include <gmodule.h>
diff --git a/src/lpmd_dbus_server.c b/src/lpmd_dbus_server.c
index 15364db..ae4fa55 100644
--- a/src/lpmd_dbus_server.c
+++ b/src/lpmd_dbus_server.c
@@ -56,7 +56,6 @@ dbus_interface_s_uv__mo_de__en_te_r(PrefObject *obj, GError **error);
static gboolean
dbus_interface_s_uv__mo_de__ex_it(PrefObject *obj, GError **error);
-#include "intel_lpmd_dbus_interface.h"
static gboolean
(*intel_lpmd_dbus_exit_callback)(void);
@@ -71,8 +70,6 @@ static void pref_object_init(PrefObject *obj)
static void pref_object_class_init(PrefObjectClass *_class)
{
g_assert (_class != NULL);
-
- dbus_g_object_type_install_info ( PREF_TYPE_OBJECT, &dbus_glib_dbus_interface_object_info);
}
static gboolean dbus_interface_terminate(PrefObject *obj, GError **error)
@@ -130,7 +127,6 @@ static gboolean dbus_interface_s_uv__mo_de__ex_it(PrefObject *obj, GError **erro
return TRUE;
}
-#ifdef GDBUS
#pragma GCC diagnostic push
static GDBusInterfaceVTable interface_vtable;
@@ -318,53 +314,3 @@ int intel_dbus_server_init(gboolean (*exit_handler)(void)) {
return LPMD_SUCCESS;
}
#pragma GCC diagnostic pop
-#else
-int intel_dbus_server_init(gboolean (*exit_handler)(void))
-{
- DBusGConnection *bus;
- DBusGProxy *bus_proxy;
- GError *error = NULL;
- guint result;
- PrefObject *value_obj;
-
- intel_lpmd_dbus_exit_callback = exit_handler;
-
- bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (error != NULL) {
- lpmd_log_error ("Couldn't connect to session bus: %s:\n", error->message);
- return LPMD_FATAL_ERROR;
- }
-
- // Get a bus proxy instance
- bus_proxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
- if (bus_proxy == NULL) {
- lpmd_log_error ("Failed to get a proxy for D-Bus:\n");
- return LPMD_FATAL_ERROR;
- }
-
- lpmd_log_debug ("Registering the well-known name (%s)\n", INTEL_LPMD_SERVICE_NAME);
- // register the well-known name
- if (!dbus_g_proxy_call (bus_proxy, "RequestName", &error, G_TYPE_STRING,
- INTEL_LPMD_SERVICE_NAME, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT,
- &result, G_TYPE_INVALID)) {
- lpmd_log_error ("D-Bus.RequestName RPC failed: %s\n", error->message);
- return LPMD_FATAL_ERROR;
- }
- lpmd_log_debug ("RequestName returned %d.\n", result);
- if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
- lpmd_log_error ("Failed to get the primary well-known name:\n");
- return LPMD_FATAL_ERROR;
- }
- value_obj = (PrefObject*) g_object_new (PREF_TYPE_OBJECT, NULL);
- if (value_obj == NULL) {
- lpmd_log_error ("Failed to create one Value instance:\n");
- return LPMD_FATAL_ERROR;
- }
-
- lpmd_log_debug ("Registering it on the D-Bus.\n");
- dbus_g_connection_register_g_object (bus, INTEL_LPMD_SERVICE_OBJECT_PATH, G_OBJECT (value_obj));
-
- return LPMD_SUCCESS;
-}
-#endif
From fcd0e2a84deb27c3efa0348a19a3d66ed0c58f64 Mon Sep 17 00:00:00 2001
From: Kate Hsuan <hpa@redhat.com>
Date: Fri, 7 Jun 2024 10:50:33 +0800
Subject: [PATCH 2/3] build: Remove dbus-glib build dependency
dbus-glib was deprecated so the build dependency can be dropped.
---
Makefile.am | 7 +------
configure.ac | 10 ----------
2 files changed, 1 insertion(+), 16 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 6d7c890..2f92a1a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -6,7 +6,7 @@ ACLOCAL_AMFLAGS =
# Global C Flags
AM_CFLAGS = \
- ${DBUS_CFLAGS} \
+ ${GLIB_CFLAGS} \
$(XML_CFLAGS) \
-DTDRUNDIR=\"$(lpmd_rundir)\" \
-DTDCONFDIR=\"$(lpmd_confdir)\" \
@@ -29,7 +29,6 @@ intel_lpmd_CPPFLAGS = \
intel_lpmd_includedir = @top_srcdir@
intel_lpmd_LDADD = \
- $(DBUS_LIBS) \
$(GLIB_LIBS) \
$(LIBNL_LIBS) \
$(LIBM) \
@@ -39,7 +38,6 @@ intel_lpmd_LDADD = \
$(SYSTEMD_LIBS)
BUILT_SOURCES = \
- intel_lpmd_dbus_interface.h \
lpmd-resource.c
intel_lpmd_SOURCES = \
@@ -58,9 +56,6 @@ intel_lpmd_SOURCES = \
man8_MANS = man/intel_lpmd.8
man5_MANS = man/intel_lpmd_config.xml.5
-intel_lpmd_dbus_interface.h: $(top_srcdir)/src/intel_lpmd_dbus_interface.xml
- $(AM_V_GEN) dbus-binding-tool --prefix=dbus_interface --mode=glib-server --output=$@ $<
-
lpmd-resource.c: $(top_srcdir)/lpmd-resource.gresource.xml
$(AM_V_GEN) glib-compile-resources --generate-source lpmd-resource.gresource.xml
diff --git a/configure.ac b/configure.ac
index 2b70a97..39fa352 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,18 +55,8 @@ GETTEXT_PACKAGE=intel_lpmd
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package])
-dnl
-dnl Checks for new dbus-glib property access function
-dnl
-AC_CHECK_LIB([dbus-glib-1], [dbus_glib_global_set_disable_legacy_property_access], ac_have_dg_prop="1", ac_have_dg_prop="0")
-AC_DEFINE_UNQUOTED(HAVE_DBUS_GLIB_DISABLE_LEGACY_PROP_ACCESS, $ac_have_dg_prop, [Define if you have a dbus-glib with dbus_glib_global_set_disable_legacy_property_access()])
-
-PKG_CHECK_MODULES(DBUS, dbus-1 >= 1.1 dbus-glib-1 >= 0.94)
-AC_SUBST(DBUS_CFLAGS)
-AC_SUBST(DBUS_LIBS)
GLIB_VERSION_DEFINES="-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_26"
-DBUS_CFLAGS="$DBUS_CFLAGS $GLIB_VERSION_DEFINES"
PKG_CHECK_MODULES(GLIB, gio-unix-2.0 >= 2.22 gmodule-2.0)
GLIB_CFLAGS="$GLIB_CFLAGS $GLIB_VERSION_DEFINES"
From 8dc503c7c98a6d28c3d8150f9fa56b6d7bc542fa Mon Sep 17 00:00:00 2001
From: Kate Hsuan <hpa@redhat.com>
Date: Fri, 7 Jun 2024 15:55:16 +0800
Subject: [PATCH 3/3] tools: intel_lpmd_control: Drop dbus-glib from cli
Deprecate the dbus-glib dependency from cli. Moreover, the cli backend
was switch to GDbus.
---
tools/Makefile | 7 +++--
tools/intel_lpmd_control.c | 63 +++++++++++++++++++++++---------------
2 files changed, 44 insertions(+), 26 deletions(-)
diff --git a/tools/Makefile b/tools/Makefile
index 670a74e..642e00d 100755
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -1,4 +1,7 @@
-CFLAGS_DBUS_GLIB = $(shell pkg-config --cflags --libs dbus-glib-1)
+CFLAGS_GLIB = $(shell pkg-config --cflags --libs glib-2.0) \
+ $(shell pkg-config --cflags --libs gio-2.0) \
+ $(shell pkg-config --cflags --libs gobject-2.0)
+
bindir ?= /usr/bin
@@ -7,7 +10,7 @@ CFLAGS ?= -g -Wall -Werror
all: intel_lpmd_control
intel_lpmd_control: intel_lpmd_control.c
- gcc $< -o $@ $(CFLAGS) $(CFLAGS_DBUS_GLIB) $(LDFLAGS)
+ gcc $< -o $@ $(CFLAGS) $(CFLAGS_GLIB) $(LDFLAGS)
clean:
rm -f intel_lpmd_control
diff --git a/tools/intel_lpmd_control.c b/tools/intel_lpmd_control.c
index 8d7f1b7..42b78b5 100644
--- a/tools/intel_lpmd_control.c
+++ b/tools/intel_lpmd_control.c
@@ -21,24 +21,31 @@
*/
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <sys/types.h>
-#include <dbus/dbus-glib.h>
+
+#include <glib.h>
+#include <glib/gprintf.h>
+
+#include <gio/gio.h>
+#include <gio/gdbusmessage.h>
#define INTEL_LPMD_SERVICE_NAME "org.freedesktop.intel_lpmd"
#define INTEL_LPMD_SERVICE_OBJECT_PATH "/org/freedesktop/intel_lpmd"
#define INTEL_LPMD_SERVICE_INTERFACE "org.freedesktop.intel_lpmd"
-int main(int argc, char **argv)
+int
+main(int argc, char **argv)
{
+ g_autoptr(GDBusConnection) connection = NULL;
+ g_autoptr (GString) command = NULL;
GError *error = NULL;
- DBusGConnection *bus;
- DBusGProxy *proxy;
- char command[20];
if (geteuid () != 0) {
- fprintf (stderr, "Must run as root\n");
- exit (0);
+ g_warning ("Must run as root");
+ exit (1);
}
if (argc < 2) {
@@ -49,28 +56,36 @@ int main(int argc, char **argv)
}
if (!strncmp (argv[1], "ON", 2))
- strcpy (command, "LPM_FORCE_ON");
+ command = g_string_new ("LPM_FORCE_ON");
else if (!strncmp (argv[1], "OFF", 3))
- strcpy (command, "LPM_FORCE_OFF");
+ command = g_string_new ("LPM_FORCE_OFF");
else if (!strncmp (argv[1], "AUTO", 4))
- strcpy (command, "LPM_AUTO");
+ command = g_string_new ("LPM_AUTO");
else {
- fprintf (stderr, "intel_lpmd_control: Invalid command\n");
- exit (0);
+ g_warning ("intel_lpmd_control: Invalid command");
+ exit (1);
}
- bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (!bus) {
- g_warning ("Unable to connect to system bus: %s", error->message);
- g_error_free (error);
- }
-
- proxy = dbus_g_proxy_new_for_name (bus, INTEL_LPMD_SERVICE_NAME,
- INTEL_LPMD_SERVICE_OBJECT_PATH,
- INTEL_LPMD_SERVICE_INTERFACE);
+ connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (connection == NULL)
+ return FALSE;
+
+ g_dbus_connection_call_sync (connection,
+ INTEL_LPMD_SERVICE_NAME,
+ INTEL_LPMD_SERVICE_OBJECT_PATH,
+ INTEL_LPMD_SERVICE_INTERFACE,
+ command->str,
+ NULL,
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
- if (!dbus_g_proxy_call (proxy, command, &error, G_TYPE_INVALID, G_TYPE_INVALID)) {
- g_warning ("Failed to send message: %s", error->message);
- g_error_free (error);
+ if (error != NULL) {
+ g_warning ("Fail on connecting lpmd: %s", error->message);
+ exit (1);
}
+
+ return 0;
}