[gnome-applets] cpufreq: require polkit-gobject



commit 27b2b973fd2707b7a517c27b56e06c08f70632ec
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Dec 13 18:10:50 2016 +0200

    cpufreq: require polkit-gobject

 configure.ac                             |   55 ++++------------------------
 cpufreq/src/cpufreq-selector.c           |   59 +-----------------------------
 cpufreq/src/cpufreq-selector/Makefile.am |   44 +++++-----------------
 cpufreq/src/cpufreq-selector/main.c      |   35 +-----------------
 cpufreq/src/cpufreq-utils.c              |   34 -----------------
 5 files changed, 20 insertions(+), 207 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8642ef1..db4b912 100644
--- a/configure.ac
+++ b/configure.ac
@@ -170,40 +170,13 @@ fi
 AC_SUBST(LIBNOTIFY_CFLAGS)
 AC_SUBST(LIBNOTIFY_LIBS)
 
-dnl -- check for glib/gobject (required) --------------------------------------
-PKG_CHECK_MODULES(CPUFREQ_SELECTOR, glib-2.0 >= $GLIB_REQUIRED gobject-2.0 >= $GLIB_REQUIRED)
-AC_SUBST(CPUFREQ_SELECTOR_CFLAGS)
-AC_SUBST(CPUFREQ_SELECTOR_LIBS)
-
-dnl -- check for dbus (required for cpufreq-selector)
-PKG_CHECK_MODULES(DBUS, dbus-1 >= $DBUS_REQUIRED dbus-glib-1 >= $DBUS_GLIB_REQUIRED, HAVE_DBUS=yes, 
HAVE_DBUS=no)
-
-AC_SUBST(DBUS_CFLAGS)
-AC_SUBST(DBUS_LIBS)
-
-dnl -- check for PolicyKit and PolicyKit-gnome (optional) -----------------------------------------
-POLKIT_CFLAGS=
-POLKIT_LIBS=
-AC_ARG_ENABLE([polkit],
-    AC_HELP_STRING([--enable-polkit], [Enable PolicyKit support @<:@default auto@:>@]),
-    enable_polkit=$enableval,
-    enable_polkit=auto)
-if test "x$enable_polkit" != "xno"; then
-    PKG_CHECK_MODULES(POLKIT, polkit-gobject-1 >= $POLKIT_REQUIRED dbus-glib-1 >= $DBUS_GLIB_REQUIRED, 
HAVE_POLKIT=yes, HAVE_POLKIT=no)
-    if test "x$enable_polkit" = "xyes" -a "x$HAVE_POLKIT" = "xno"; then
-        AC_MSG_ERROR([PolicyKit support explicitly requested but dependencies not found])
-    fi
-fi
-dnl - This is only so the printout at the end of configure is correct -
-if test "x$enable_polkit" = "xno"; then
-   HAVE_POLKIT=no
-fi
-if test "x$HAVE_POLKIT" = "xyes"; then
-    AC_DEFINE(HAVE_POLKIT, [1], [PolicyKit available])
-fi
-AM_CONDITIONAL(HAVE_POLKIT, test "x$HAVE_POLKIT" = "xyes")
-AC_SUBST(POLKIT_CFLAGS)
-AC_SUBST(POLKIT_LIBS)
+PKG_CHECK_MODULES([CPUFREQ_SELECTOR], [
+  dbus-1 >= $DBUS_REQUIRED
+  dbus-glib-1 >= $DBUS_GLIB_REQUIRED
+  glib-2.0 >= $GLIB_REQUIRED
+  gobject-2.0 >= $GLIB_REQUIRED
+  polkit-gobject-1 >= $POLKIT_REQUIRED
+])
 
 dnl -- check for libupower-glib (optional) --------------------------------------------
 UPOWER_CFLAGS=
@@ -459,16 +432,6 @@ AC_ARG_ENABLE(frequency-selector,
                          build frequency selector [@<:@default: yes@:>@]], enable_selector=$enableval,
              enable_selector=yes)
 
-dnl --enable-suid=(yes/no)
-AC_ARG_ENABLE(suid,
-       [  --enable-suid[@<:@=yes/no@:>@]  suid root the frequency selector executable
-                   [@<:@default: yes@:>@]], ,
-       suid=yes)
-
-if test "x$HAVE_POLKIT" = "xyes"; then
-   suid=no
-fi
-
 AC_ARG_WITH([cpufreq-lib],
        AS_HELP_STRING([--with-cpufreq-lib=lib], [library to use for cpufreq applet @<:@default=cpufreq@:>@]),
        [with_cpufreq_lib=$withval], [with_cpufreq_lib="cpufreq"])
@@ -501,7 +464,6 @@ fi
 
 AM_CONDITIONAL(BUILD_CPUFREQ_APPLET, test x$build_cpufreq_applet = xyes)
 AM_CONDITIONAL(BUILD_CPUFREQ_SELECTOR, test x$enable_selector = xyes)
-AM_CONDITIONAL(CPUFREQ_SELECTOR_SUID, test x$suid = xyes)
 
 dnl ***************************************************************************
 dnl *** tracker-search-bar applet check                                     ***
@@ -796,10 +758,7 @@ echo "    gucharmap support .............: $have_gucharmap"
 echo ""
 echo "  cpufreq"
 echo "    building selector .............: $enable_selector"
-echo "    using PolicyKit ...............: $HAVE_POLKIT"
-echo "    enabling suid bit .............: $suid"
 echo ""
-echo "  Using DBUS ......................: $HAVE_DBUS"
 echo "  Using UPOWER ....................: $HAVE_UPOWER"
 echo "  Enabling IPv6 ...................: $have_ipv6"
 echo ""
diff --git a/cpufreq/src/cpufreq-selector.c b/cpufreq/src/cpufreq-selector.c
index 5e79370..82919e0 100644
--- a/cpufreq/src/cpufreq-selector.c
+++ b/cpufreq/src/cpufreq-selector.c
@@ -23,12 +23,10 @@
 #include "cpufreq-selector.h"
 
 struct _CPUFreqSelector {
-       GObject parent;
+       GObject          parent;
 
-#ifdef HAVE_POLKIT
        GDBusConnection *system_bus;
        GDBusProxy      *proxy;
-#endif /* HAVE_POLKIT */
 };
 
 struct _CPUFreqSelectorClass {
@@ -42,10 +40,8 @@ cpufreq_selector_finalize (GObject *object)
 {
        CPUFreqSelector *selector = CPUFREQ_SELECTOR (object);
 
-#ifdef HAVE_POLKIT
        g_clear_object (&selector->proxy);
        g_clear_object (&selector->system_bus);
-#endif /* HAVE_POLKIT */
 
        G_OBJECT_CLASS (cpufreq_selector_parent_class)->finalize (object);
 }
@@ -74,7 +70,6 @@ cpufreq_selector_get_default (void)
        return selector;
 }
 
-#ifdef HAVE_POLKIT
 typedef enum {
        FREQUENCY,
        GOVERNOR
@@ -278,55 +273,3 @@ cpufreq_selector_set_governor_async (CPUFreqSelector *selector,
 
        selector_set_governor_async (data);
 }
-#else /* !HAVE_POLKIT */
-static void
-cpufreq_selector_run_command (CPUFreqSelector *selector,
-                             const gchar     *args)
-{
-       gchar  *command;
-       gchar  *path;
-       GError *error = NULL;
-
-       path = g_find_program_in_path ("cpufreq-selector");
-
-       if (!path)
-               return;
-
-       command = g_strdup_printf ("%s %s", path, args);
-       g_free (path);
-
-       g_spawn_command_line_async (command, &error);
-       g_free (command);
-
-       if (error) {
-               g_warning ("%s", error->message);
-               g_error_free (error);
-       }
-}
-
-void
-cpufreq_selector_set_frequency_async (CPUFreqSelector *selector,
-                                     guint            cpu,
-                                     guint            frequency,
-                                     guint32          parent)
-{
-       gchar *args;
-
-       args = g_strdup_printf ("-c %u -f %u", cpu, frequency);
-       cpufreq_selector_run_command (selector, args);
-       g_free (args);
-}
-
-void
-cpufreq_selector_set_governor_async (CPUFreqSelector *selector,
-                                    guint            cpu,
-                                    const gchar     *governor,
-                                    guint32          parent)
-{
-       gchar *args;
-
-       args = g_strdup_printf ("-c %u -g %s", cpu, governor);
-       cpufreq_selector_run_command (selector, args);
-       g_free (args);
-}
-#endif /* HAVE_POLKIT */
diff --git a/cpufreq/src/cpufreq-selector/Makefile.am b/cpufreq/src/cpufreq-selector/Makefile.am
index bcec21a..369c392 100644
--- a/cpufreq/src/cpufreq-selector/Makefile.am
+++ b/cpufreq/src/cpufreq-selector/Makefile.am
@@ -8,38 +8,21 @@ cpufreq_selector_CFLAGS = \
        $(AM_CFLAGS) \
        $(NULL)
 
-if HAVE_POLKIT
-cpufreq_selector_CFLAGS += \
-       $(DBUS_CFLAGS)          \
-       $(POLKIT_CFLAGS)
-endif
-
 bin_PROGRAMS = cpufreq-selector
 
-install-exec-hook:
-if CPUFREQ_SELECTOR_SUID
-       chmod 4755 $(DESTDIR)$(bindir)/cpufreq-selector
-endif
-
-if HAVE_POLKIT
-service_files=cpufreq-selector-service.c       cpufreq-selector-service.h
-endif
-
 cpufreq_selector_SOURCES = \
-       cpufreq-selector.c               cpufreq-selector.h             \
-       $(service_files)                                                \
-       $(BUILT_SOURCES)                                                \
-       main.c
+       cpufreq-selector.c \
+       cpufreq-selector.h \
+       cpufreq-selector-service.c \
+       cpufreq-selector-service.h \
+       main.c \
+       $(BUILT_SOURCES) \
+       $(NULL)
 
 cpufreq_selector_LDADD = \
-       $(CPUFREQ_SELECTOR_LIBS)        \
-       $(LIBCPUFREQ_LIBS)
-
-if HAVE_POLKIT
-cpufreq_selector_LDADD += \
-       $(DBUS_LIBS)            \
-       $(POLKIT_LIBS)
-endif
+       $(CPUFREQ_SELECTOR_LIBS) \
+       $(LIBCPUFREQ_LIBS) \
+       $(NULL)
 
 cpufreq_selector_LDFLAGS = \
        -Wl,-z,now \
@@ -54,7 +37,6 @@ dbus_servicesdir = $(datadir)/dbus-1/system-services
 dbus_confdir = $(sysconfdir)/dbus-1/system.d
 polkitdir = $(datadir)/polkit-1/actions
 
-if HAVE_POLKIT
 BUILT_SOURCES = cpufreq-selector-service-glue.h
 
 cpufreq-selector-service-glue.h: $(srcdir)/cpufreq-selector-service.xml
@@ -70,12 +52,6 @@ dbus_conf_DATA = org.gnome.CPUFreqSelector.conf
 @INTLTOOL_POLICY_RULE@
 polkit_DATA = $(polkit_in_files:.policy.in=.policy)
 
-else
-dbus_services_DATA=
-dbus_conf_DATA=
-polkit_DATA=
-endif
-
 EXTRA_DIST = \
        cpufreq-selector-service.xml    \
        $(dbus_services_in_files)       \
diff --git a/cpufreq/src/cpufreq-selector/main.c b/cpufreq/src/cpufreq-selector/main.c
index 5e47b16..e469a79 100644
--- a/cpufreq/src/cpufreq-selector/main.c
+++ b/cpufreq/src/cpufreq-selector/main.c
@@ -18,16 +18,12 @@
  * Authors : Carlos García Campos <carlosgc gnome org>
  */
 
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
 #include <glib.h>
 #include <glib-object.h>
 
-#ifdef HAVE_POLKIT
 #include "cpufreq-selector-service.h"
-#endif
 #include "cpufreq-selector.h"
 
 static gint    cpu = 0;
@@ -41,7 +37,6 @@ static const GOptionEntry options[] = {
        { NULL }
 };
 
-#ifdef HAVE_POLKIT
 static void
 do_exit (GMainLoop *loop,
         GObject   *object)
@@ -119,7 +114,6 @@ cpufreq_selector_set_values_dbus (void)
 
        g_object_unref (proxy);
 }
-#endif /* HAVE_POLKIT */
 
 static void
 cpufreq_selector_set_values (void)
@@ -160,31 +154,10 @@ cpufreq_selector_set_values (void)
 gint
 main (gint argc, gchar **argv)
 {
-#ifdef HAVE_POLKIT
        GMainLoop      *loop;
-#endif
-        GOptionContext *context;
+       GOptionContext *context;
        GError         *error = NULL;
 
-#ifndef HAVE_POLKIT
-       if (geteuid () != 0) {
-               g_printerr ("You must be root\n");
-
-               return 1;
-       }
-       
-       if (argc < 2) {
-               g_printerr ("Missing operand after `cpufreq-selector'\n");
-               g_printerr ("Try `cpufreq-selector --help' for more information.\n");
-
-               return 1;
-       }
-#endif
-       
-       #if !defined(GLIB_VERSION_2_36)
-               g_type_init ();
-       #endif
-
        context = g_option_context_new ("- CPUFreq Selector");
        g_option_context_add_main_entries (context, options, NULL);
        
@@ -200,8 +173,7 @@ main (gint argc, gchar **argv)
        }
        
        g_option_context_free (context);
-       
-#ifdef HAVE_POLKIT
+
        if (!cpufreq_selector_service_register (SELECTOR_SERVICE, &error)) {
                if (governor || frequency != 0) {
                        cpufreq_selector_set_values_dbus ();
@@ -225,9 +197,6 @@ main (gint argc, gchar **argv)
        g_main_loop_run (loop);
 
        g_main_loop_unref (loop);
-#else /* !HAVE_POLKIT */
-       cpufreq_selector_set_values ();
-#endif /* HAVE_POLKIT */
 
         return 0;
 }
diff --git a/cpufreq/src/cpufreq-utils.c b/cpufreq/src/cpufreq-utils.c
index 7fc7386..eda024b 100644
--- a/cpufreq/src/cpufreq-utils.c
+++ b/cpufreq/src/cpufreq-utils.c
@@ -100,7 +100,6 @@ cpufreq_utils_display_error (const gchar *message,
        gtk_widget_show (dialog);
 }
 
-#ifdef HAVE_POLKIT
 #define CACHE_VALIDITY_SEC 2
 
 static gboolean
@@ -171,39 +170,6 @@ cpufreq_utils_selector_is_available (void)
 
        return cache;
 }
-#else /* !HAVE_POLKIT */
-gboolean
-cpufreq_utils_selector_is_available (void)
-{
-       struct stat *info;
-       gchar       *path = NULL;
-
-       path = g_find_program_in_path ("cpufreq-selector");
-       if (!path)
-               return FALSE;
-
-       if (geteuid () == 0) {
-               g_free (path);
-               return TRUE;
-       }
-
-       info = (struct stat *) g_malloc (sizeof (struct stat));
-
-       if ((lstat (path, info)) != -1) {
-               if ((info->st_mode & S_ISUID) && (info->st_uid == 0)) {
-                       g_free (info);
-                       g_free (path);
-
-                       return TRUE;
-               }
-       }
-
-       g_free (info);
-       g_free (path);
-
-       return FALSE;
-}
-#endif /* HAVE_POLKIT_GNOME */
 
 gchar *
 cpufreq_utils_get_frequency_label (guint freq)


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