summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2022-03-22 17:05:55 +0100
committerBenjamin Berg <bberg@redhat.com>2022-03-23 15:39:20 +0100
commit96aeac57d6f76f672cbf9d3f20211a5cefe1885d (patch)
tree742b5aec9cc516ede3018649e793e3ceb601d979
parent5671b3c3b5e00d45f6462b657f6dc83bdcb01763 (diff)
downloadgnome-settings-daemon-benzea/brightness.tar.gz
power: Remove backlight helperbenzea/brightness
Lets just assume that everyone has systemd-logind or elogind these days.
-rw-r--r--plugins/power/gsd-backlight-helper.c149
-rw-r--r--plugins/power/gsd-backlight.c164
-rw-r--r--plugins/power/meson.build35
-rw-r--r--plugins/power/org.gnome.settings-daemon.plugins.power.policy.in.in32
4 files changed, 3 insertions, 377 deletions
diff --git a/plugins/power/gsd-backlight-helper.c b/plugins/power/gsd-backlight-helper.c
deleted file mode 100644
index f0fbbb59..00000000
--- a/plugins/power/gsd-backlight-helper.c
+++ /dev/null
@@ -1,149 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2018 Benjamin Berg <bberg@redhat.com>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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 of the License, or
- * (at your option) any later version.
- *
- * This program 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 program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <dirent.h>
-#include <errno.h>
-#include <string.h>
-#include <libgen.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#define GSD_BACKLIGHT_HELPER_EXIT_CODE_SUCCESS 0
-#define GSD_BACKLIGHT_HELPER_EXIT_CODE_FAILED 1
-#define GSD_BACKLIGHT_HELPER_EXIT_CODE_ARGUMENTS_INVALID 3
-#define GSD_BACKLIGHT_HELPER_EXIT_CODE_INVALID_USER 4
-
-#ifndef __linux__
-#error "gsd-backlight-helper does not work on non-Linux"
-#endif
-
-static void
-usage(int argc, char *argv[])
-{
- fprintf (stderr, "Usage: %s device brightness\n", argv[0]);
- fprintf (stderr, " device: The backlight directory starting with \"/sys/class/backlight/\"\n");
- fprintf (stderr, " brightness: The new brightness to write\n");
-}
-
-int
-main (int argc, char *argv[])
-{
- char tmp[512];
- char *device = NULL;
- int fd, len, res;
- int uid, euid;
- int brightness;
- int result = GSD_BACKLIGHT_HELPER_EXIT_CODE_FAILED;
- DIR *dp = NULL;
- struct dirent *ep;
-
- /* check calling UID */
- uid = getuid ();
- euid = geteuid ();
- if (uid != 0 || euid != 0) {
- fprintf (stderr, "This program can only be used by the root user\n");
- result = GSD_BACKLIGHT_HELPER_EXIT_CODE_INVALID_USER;
- goto done;
- }
-
- if (argc != 3) {
- fprintf (stderr, "Error: Need to be called with exactly two arguments\n");
- usage (argc, argv);
- result = GSD_BACKLIGHT_HELPER_EXIT_CODE_ARGUMENTS_INVALID;
- goto done;
- }
-
- errno = 0;
- brightness = strtol (argv[2], NULL, 0);
- if (errno) {
- fprintf (stderr, "Error: Invalid brightness argument (%d: %s)\n", errno, strerror (errno));
- usage (argc, argv);
- goto done;
- }
-
- dp = opendir ("/sys/class/backlight");
- if (dp == NULL) {
- fprintf (stderr, "Error: Could not open /sys/class/backlight (%d: %s)\n", errno, strerror (errno));
- result = GSD_BACKLIGHT_HELPER_EXIT_CODE_FAILED;
- goto done;
- }
-
- /* May be NULL if the path cannot be resolved */
- device = realpath (argv[1], NULL);
-
- while ((ep = readdir (dp))) {
- char *path;
-
- if (ep->d_name[0] == '.')
- continue;
-
- /* Leave room for "/brightness" */
- snprintf (tmp, sizeof(tmp) - 11, "/sys/class/backlight/%s", ep->d_name);
- path = realpath (tmp, NULL);
- if (path && device && strcmp (path, device) == 0) {
- free (path);
- strcat (tmp, "/brightness");
-
- fd = open (tmp, O_WRONLY);
- if (fd < 0) {
- fprintf (stderr, "Error: Could not open brightness sysfs file (%d: %s)\n", errno, strerror(errno));
- result = GSD_BACKLIGHT_HELPER_EXIT_CODE_FAILED;
- goto done;
- }
-
- len = snprintf (tmp, sizeof(tmp), "%d", brightness);
- if ((res = write (fd, tmp, len)) != len) {
- if (res == -1)
- fprintf (stderr, "Error: Writing to file (%d: %s)\n", errno, strerror(errno));
- else
- fprintf (stderr, "Error: Wrote the wrong length (%d of %d bytes)!\n", res, len);
-
- close (fd);
- result = GSD_BACKLIGHT_HELPER_EXIT_CODE_FAILED;
- goto done;
- }
- close (fd);
-
- result = GSD_BACKLIGHT_HELPER_EXIT_CODE_SUCCESS;
- goto done;
- } else {
- free (path);
- }
- }
-
- result = GSD_BACKLIGHT_HELPER_EXIT_CODE_FAILED;
- fprintf (stderr, "Error: Could not find the specified backlight \"%s\"\n", argv[1]);
-
-done:
- if (device)
- free (device);
- if (dp)
- closedir (dp);
-
- return result;
-}
-
diff --git a/plugins/power/gsd-backlight.c b/plugins/power/gsd-backlight.c
index dbf538a6..1cc8b00e 100644
--- a/plugins/power/gsd-backlight.c
+++ b/plugins/power/gsd-backlight.c
@@ -45,9 +45,6 @@ struct _GsdBacklight
GUdevClient *udev;
GUdevDevice *udev_device;
- GTask *active_task;
- GQueue tasks;
-
gint idle_update;
#endif /* __linux__ */
@@ -160,10 +157,6 @@ gsd_backlight_udev_idle_update_cb (GsdBacklight *backlight)
g_autofree gchar *contents = NULL;
backlight->idle_update = 0;
- /* If we are active again now, just stop. */
- if (backlight->active_task)
- return FALSE;
-
path = g_build_filename (g_udev_device_get_sysfs_path (backlight->udev_device), "brightness", NULL);
if (!g_file_get_contents (path, &contents, NULL, &error)) {
g_warning ("Could not get brightness from sysfs: %s", error->message);
@@ -203,10 +196,6 @@ gsd_backlight_udev_uevent (GUdevClient *client, const gchar *action, GUdevDevice
if (g_strcmp0 (action, "change") != 0)
return;
- /* We are going to update our state after processing the tasks anyway. */
- if (!g_queue_is_empty (&backlight->tasks))
- return;
-
if (g_strcmp0 (g_udev_device_get_sysfs_path (device),
g_udev_device_get_sysfs_path (backlight->udev_device)) != 0)
return;
@@ -259,139 +248,6 @@ gsd_backlight_udev_init (GsdBacklight *backlight)
return TRUE;
}
-
-
-typedef struct {
- int value;
- char *value_str;
-} BacklightHelperData;
-
-static void gsd_backlight_process_taskqueue (GsdBacklight *backlight);
-
-static void
-backlight_task_data_destroy (gpointer data)
-{
- BacklightHelperData *task_data = (BacklightHelperData*) data;
-
- g_free (task_data->value_str);
- g_free (task_data);
-}
-
-static void
-gsd_backlight_set_helper_return (GsdBacklight *backlight, GTask *task, gint result, const GError *error)
-{
- GTask *finished_task;
- gint percent = ABS_TO_PERCENTAGE (backlight->brightness_min, backlight->brightness_max, result);
-
- if (error)
- g_warning ("Error executing backlight helper: %s", error->message);
-
- /* If the queue will be empty then update the current value. */
- if (task == g_queue_peek_tail (&backlight->tasks)) {
- if (error == NULL) {
- g_assert (backlight->brightness_target == result);
-
- backlight->brightness_val = backlight->brightness_target;
- g_debug ("New brightness value is in effect %i (%i..%i)",
- backlight->brightness_val, backlight->brightness_min, backlight->brightness_max);
- g_object_notify_by_pspec (G_OBJECT (backlight), props[PROP_BRIGHTNESS]);
- }
-
- /* The udev handler won't read while a write is pending, so queue an
- * update in case we have missed some events. */
- gsd_backlight_udev_idle_update (backlight);
- }
-
- /* Return all the pending tasks up and including the one we actually
- * processed. */
- do {
- finished_task = g_queue_pop_head (&backlight->tasks);
-
- if (error)
- g_task_return_error (finished_task, g_error_copy (error));
- else
- g_task_return_int (finished_task, percent);
-
- g_object_unref (finished_task);
- } while (finished_task != task);
-}
-
-static void
-gsd_backlight_set_helper_finish (GObject *obj, GAsyncResult *res, gpointer user_data)
-{
- g_autoptr(GSubprocess) proc = G_SUBPROCESS (obj);
- GTask *task = G_TASK (user_data);
- BacklightHelperData *data = g_task_get_task_data (task);
- GsdBacklight *backlight = g_task_get_source_object (task);
- g_autoptr(GError) error = NULL;
-
- g_assert (task == backlight->active_task);
- backlight->active_task = NULL;
-
- g_subprocess_wait_finish (proc, res, &error);
-
- if (error)
- goto done;
-
- g_spawn_check_exit_status (g_subprocess_get_exit_status (proc), &error);
- if (error)
- goto done;
-
-done:
- gsd_backlight_set_helper_return (backlight, task, data->value, error);
- /* Start processing any tasks that were added in the meantime. */
- gsd_backlight_process_taskqueue (backlight);
-}
-
-static void
-gsd_backlight_run_set_helper (GsdBacklight *backlight, GTask *task)
-{
- GSubprocess *proc = NULL;
- BacklightHelperData *data = g_task_get_task_data (task);
- GError *error = NULL;
-
- g_assert (backlight->active_task == NULL);
- backlight->active_task = task;
-
- if (data->value_str == NULL)
- data->value_str = g_strdup_printf ("%d", data->value);
-
- /* This is solely for use by the test environment. If given, execute
- * this helper instead of the internal helper using pkexec */
- proc = g_subprocess_new (G_SUBPROCESS_FLAGS_STDOUT_SILENCE,
- &error,
- "pkexec",
- LIBEXECDIR "/gsd-backlight-helper",
- g_udev_device_get_sysfs_path (backlight->udev_device),
- data->value_str, NULL);
-
- if (proc == NULL) {
- gsd_backlight_set_helper_return (backlight, task, -1, error);
- return;
- }
-
- g_subprocess_wait_async (proc, g_task_get_cancellable (task),
- gsd_backlight_set_helper_finish,
- task);
-}
-
-static void
-gsd_backlight_process_taskqueue (GsdBacklight *backlight)
-{
- GTask *to_run;
-
- /* There is already a task active, nothing to do. */
- if (backlight->active_task)
- return;
-
- /* Get the last added task, thereby compressing the updates into one. */
- to_run = G_TASK (g_queue_peek_tail (&backlight->tasks));
- if (to_run == NULL)
- return;
-
- /* And run it! */
- gsd_backlight_run_set_helper (backlight, to_run);
-}
#endif /* __linux__ */
static GnomeRROutput*
@@ -494,8 +350,6 @@ gsd_backlight_set_brightness_val_async (GsdBacklight *backlight,
#ifdef __linux__
if (backlight->udev_device != NULL) {
- BacklightHelperData *task_data;
-
if (backlight->logind_proxy) {
g_dbus_proxy_call (backlight->logind_proxy,
"SetBrightness",
@@ -512,15 +366,10 @@ gsd_backlight_set_brightness_val_async (GsdBacklight *backlight,
backlight->brightness_target);
g_task_return_int (task, percent);
} else {
- task_data = g_new0 (BacklightHelperData, 1);
- task_data->value = backlight->brightness_target;
- g_task_set_task_data (task, task_data, backlight_task_data_destroy);
-
- /* Task is set up now. Queue it and ensure we are working something. */
- g_queue_push_tail (&backlight->tasks, task);
- gsd_backlight_process_taskqueue (backlight);
+ g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "logind unavailable");
}
+ g_object_unref (task);
return;
}
#endif /* __linux__ */
@@ -890,7 +739,7 @@ gsd_backlight_initable_init (GInitable *initable,
}
if (logind_error) {
- g_warning ("No logind found: %s", logind_error->message);
+ g_warning ("No logind found, backlight will not work: %s", logind_error->message);
g_error_free (logind_error);
}
@@ -933,8 +782,6 @@ gsd_backlight_finalize (GObject *object)
GsdBacklight *backlight = GSD_BACKLIGHT (object);
#ifdef __linux__
- g_assert (backlight->active_task == NULL);
- g_assert (g_queue_is_empty (&backlight->tasks));
g_clear_object (&backlight->logind_proxy);
g_clear_object (&backlight->udev);
g_clear_object (&backlight->udev_device);
@@ -984,11 +831,6 @@ gsd_backlight_init (GsdBacklight *backlight)
backlight->brightness_max = -1;
backlight->brightness_val = -1;
backlight->brightness_step = 1;
-
-#ifdef __linux__
- backlight->active_task = NULL;
- g_queue_init (&backlight->tasks);
-#endif /* __linux__ */
}
GsdBacklight *
diff --git a/plugins/power/meson.build b/plugins/power/meson.build
index 014bb6da..146137ab 100644
--- a/plugins/power/meson.build
+++ b/plugins/power/meson.build
@@ -66,41 +66,6 @@ gsd_power_enums_update = executable(
native: true
)
-if host_is_linux
- policy = 'org.gnome.settings-daemon.plugins.power.policy'
-
- policy_in = configure_file(
- input: policy + '.in.in',
- output: policy + '.in',
- configuration: plugins_conf
- )
-
- i18n.merge_file(
- input: policy_in,
- output: policy,
- po_dir: po_dir,
- install: true,
- install_dir: join_paths(gsd_datadir, 'polkit-1', 'actions')
- )
-
- sources = files(
- 'gsd-backlight-helper.c',
- )
-
- deps = [
- ]
-
- executable(
- 'gsd-backlight-helper',
- sources,
- include_directories: top_inc,
- dependencies: deps,
- install: true,
- install_rpath: gsd_pkglibdir,
- install_dir: gsd_libexecdir
- )
-endif
-
output = 'gsdpowerconstants.py'
gsdpowerconstants_py = custom_target(
diff --git a/plugins/power/org.gnome.settings-daemon.plugins.power.policy.in.in b/plugins/power/org.gnome.settings-daemon.plugins.power.policy.in.in
deleted file mode 100644
index f16300f8..00000000
--- a/plugins/power/org.gnome.settings-daemon.plugins.power.policy.in.in
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE policyconfig PUBLIC
- "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
-<policyconfig>
-
- <!--
- Policy definitions for gnome-settings-daemon system-wide actions.
- Copyright (c) 2010-2011 Richard Hughes <richard@hughsie.com>
- -->
-
- <vendor>GNOME Settings Daemon</vendor>
- <vendor_url>http://git.gnome.org/browse/gnome-settings-daemon</vendor_url>
- <icon_name>battery</icon_name>
-
- <action id="org.gnome.settings-daemon.plugins.power.backlight-helper">
- <!-- SECURITY:
- - A normal active user on the local machine does not need permission
- to change the backlight brightness.
- -->
- <description>Modify the laptop brightness</description>
- <message>Authentication is required to modify the laptop brightness</message>
- <defaults>
- <allow_any>no</allow_any>
- <allow_inactive>no</allow_inactive>
- <allow_active>yes</allow_active>
- </defaults>
- <annotate key="org.freedesktop.policykit.exec.path">@libexecdir@/gsd-backlight-helper</annotate>
- </action>
-
-</policyconfig>
-