Skip to contentSkip to conversation

xf86-video-intel: Fix fd_set_nonblock

PATCH In review Hans de Goede 2 participants 10 messages Feb 14, 2014 – Feb 15, 2014 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 xf86-video-intel: Fix fd_set_nonblock

O_NONBLOCK is a status flag not a descriptor flag, so F_GETFL / F_SETFL should be used to modify it.

---
 src/intel_device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/intel_device.c +2 -2
index effda24..07b7d2e 100644
@@ -167,10 +167,10 @@ static int fd_set_nonblock(int fd)
 	if (fd == -1)
 		return fd;
 
-	flags = fcntl(fd, F_GETFD);
+	flags = fcntl(fd, F_GETFL);
 	if (flags != -1) {
 		flags |= O_NONBLOCK;
-		fcntl(fd, F_SETFD, flags);
+		fcntl(fd, F_SETFL, flags);
 	}
 
 	return fd;
Signature · 1 line
1.8.5.3
#1 lore raw

PATCH 2/3 xf86-video-intel: export fd_set_cloexec / fd_set_nonblock

Allow fd_set_cloexec / fd_set_nonblock to be used outside of intel_device.c.

---
 src/intel_device.c | 8 ++++----
 src/intel_driver.h | 2 ++
 2 files changed, 6 insertions(+), 4 deletions(-)
src/intel_device.c +4 -4
index 07b7d2e..fd0b735 100644
@@ -142,7 +142,7 @@ static int __intel_check_device(int fd)
 	return ret;
 }
 
-static int fd_set_cloexec(int fd)
+int intel_fd_set_cloexec(int fd)
 {
 	int flags;
 
@@ -160,7 +160,7 @@ static int fd_set_cloexec(int fd)
 	return fd;
 }
 
-static int fd_set_nonblock(int fd)
+int intel_fd_set_nonblock(int fd)
 {
 	int flags;
 
@@ -209,7 +209,7 @@ static int __intel_open_device(const struct pci_device *pci, char **path)
 				fd = -1;
 			}
 		}
-		fd = fd_set_nonblock(fd);
+		fd = intel_fd_set_nonblock(fd);
 	} else {
 #ifdef O_CLOEXEC
 		fd = open(*path, O_RDWR | O_NONBLOCK | O_CLOEXEC);
@@ -217,7 +217,7 @@ static int __intel_open_device(const struct pci_device *pci, char **path)
 		fd = -1;
 #endif
 		if (fd == -1)
-			fd = fd_set_cloexec(open(*path, O_RDWR | O_NONBLOCK));
+			fd = intel_fd_set_cloexec(open(*path, O_RDWR | O_NONBLOCK));
 	}
 
 	return fd;
src/intel_driver.h +2 -0
index b2cb1b9..52c2768 100644
@@ -126,6 +126,8 @@ int intel_open_device(int entity_num,
 		      const struct pci_device *pci,
 		      struct xf86_platform_device *dev);
 int intel_get_device(ScrnInfoPtr scrn);
+int intel_fd_set_cloexec(int fd);
+int intel_fd_set_nonblock(int fd);
 const char *intel_get_client_name(ScrnInfoPtr scrn);
 int intel_get_device_id(ScrnInfoPtr scrn);
 int intel_get_master(ScrnInfoPtr scrn);
Signature · 1 line
1.8.5.3
#2 lore raw

PATCH 3/3 xf86-video-intel: Add a helper for setting backlight without root rights

In reply to Hans de Goede

Once the xserver stops running as root on kms capabable systems, we will need some other way to access the backlight.

The approach taken in this patch leaves most of the heavy lifting (wrt doing everything suid root safe) to pkexec, as is done in ie gnome-settings-daemon, which controls the backlight directly on ati and nouveau cards.

This commit adds src/backlight.h and src/backlight.c as a place to share common backlight code, in the future most of the duplicate backlight code inside src/sna/sna_display.c and src/uxa/intel_display.c should be moved there.

---
 Makefile.am                                        |   4 +
 backlight_helper/Makefile.am                       |  37 ++++++
 backlight_helper/backlight_helper.c                |  37 ++++++
 ...g.x.xf86-video-intel.backlight-helper.policy.in |  19 +++
 configure.ac                                       |  11 ++
 src/Makefile.am                                    |   2 +
 src/backlight.c                                    | 142 +++++++++++++++++++++
 src/backlight.h                                    |  22 ++++
 src/sna/sna_display.c                              |  17 +--
 src/uxa/intel_display.c                            |  17 +--
 10 files changed, 292 insertions(+), 16 deletions(-)
 create mode 100644 backlight_helper/Makefile.am
 create mode 100644 backlight_helper/backlight_helper.c
 create mode 100644 backlight_helper/org.x.xf86-video-intel.backlight-helper.policy.in
 create mode 100644 src/backlight.c
 create mode 100644 src/backlight.h
Makefile.am +4 -0
index 71c7698..d6b97b6 100644
@@ -26,6 +26,10 @@ if BUILD_TOOLS
 SUBDIRS += tools
 endif
 
+if BUILD_BACKLIGHT_HELPER
+SUBDIRS += backlight_helper
+endif
+
 MAINTAINERCLEANFILES = ChangeLog INSTALL
 
 if HAVE_X11
backlight_helper/Makefile.am new file +37 -0
new file mode 100644
index 0000000..a4a5050
@@ -0,0 +1,37 @@
+#  Copyright 2005 Adam Jackson.
+#
+#  Permission is hereby granted, free of charge, to any person obtaining a
+#  copy of this software and associated documentation files (the "Software"),
+#  to deal in the Software without restriction, including without limitation
+#  on the rights to use, copy, modify, merge, publish, distribute, sub
+#  license, and/or sell copies of the Software, and to permit persons to whom
+#  the Software is furnished to do so, subject to the following conditions:
+#
+#  The above copyright notice and this permission notice (including the next
+#  paragraph) shall be included in all copies or substantial portions of the
+#  Software.
+#
+#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+#  FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
+#  ADAM JACKSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+#  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+#  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+AM_CFLAGS = \
+	@CWARNFLAGS@ \
+	@NOWARNFLAGS@ \
+	$(NULL)
+
+backlight_helperdir = $(prefix)/libexec
+policydir = $(datarootdir)/polkit-1/actions
+
+backlight_helper_PROGRAMS = xf86-video-intel-backlight-helper
+nodist_policy_DATA = org.x.xf86-video-intel.backlight-helper.policy
+
+xf86_video_intel_backlight_helper_SOURCES = \
+	backlight_helper.c \
+	$(NULL)
+
+EXTRA_DIST = org.x.xf86-video-intel.backlight-helper.policy.in
+DISTCLEANFILES = $(nodist_policy_DATA)
backlight_helper/backlight_helper.c new file +37 -0
new file mode 100644
index 0000000..c681aae
@@ -0,0 +1,37 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define BUF_SIZE 1024
+
+int main(int argc, char *argv[])
+{
+	char buf[BUF_SIZE];
+	FILE *f;
+	int r;
+
+	if (argc != 3) {
+		fprintf(stderr, "Error %s expects exactly 2 parameters\n",
+			argv[0]);
+		fprintf(stderr, "Usage: %s <iface> <level>\n", argv[0]);
+		return 1;
+	}
+
+	snprintf(buf, BUF_SIZE, "/sys/class/backlight/%s/brightness", argv[1]);
+	f = fopen(buf, "r+");
+	if (!f) {
+		fprintf(stderr, "Error opening %s: %s\n", buf, strerror(errno));
+		return 1;
+	}
+	
+	r = fprintf(f, "%s\n", argv[2]);	
+	if (r < 0) {
+		fprintf(stderr, "Error writing %s: %s\n", buf, strerror(errno));
+		return 1;
+	}
+	
+	fclose(f);
+
+	return 0;
+}
backlight_helper/org.x.xf86-video-intel.backlight-helper.policy.in new file +19 -0
new file mode 100644
index 0000000..37e9622
@@ -0,0 +1,19 @@
+<?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>
+  <vendor>The X.Org project</vendor>
+  <vendor_url>https://01.org/linuxgraphics/community/xf86-video-intel</vendor_url>
+  <icon_name>brightness</icon_name>
+  <action id="org.x.xf86-video-intel.backlight-helper">
+    <description>Modify lcd panel brightness</description>
+    <message>Authentication is required to modify the lcd panel 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">@prefix@/libexec/xf86-video-intel-backlight-helper</annotate>
+  </action>
+</policyconfig>
configure.ac +11 -0
index 4f73ba4..6bc80de 100644
@@ -62,6 +62,14 @@ AC_DISABLE_STATIC
 AC_PROG_LIBTOOL
 AC_SYS_LARGEFILE
 
+# Platform specific settings
+case $host_os in
+  *linux*)
+    backlight_helper=yes
+    ;;
+esac
+AM_CONDITIONAL(BUILD_BACKLIGHT_HELPER, [test "x$backlight_helper" = "xyes"])
+
 # Are we in a git checkout?
 dot_git=no
 if test -e .git; then
@@ -681,6 +689,7 @@ fi
 DRIVER_NAME="intel"
 AC_SUBST([DRIVER_NAME])
 AC_SUBST([moduledir])
+AC_DEFINE_DIR([PREFIX_PATH], prefix, [installation prefix])
 
 AC_CONFIG_FILES([
                 Makefile
@@ -700,6 +709,8 @@ AC_CONFIG_FILES([
                 xvmc/shader/vld/Makefile
 		test/Makefile
 		tools/Makefile
+		backlight_helper/Makefile
+		backlight_helper/org.x.xf86-video-intel.backlight-helper.policy
 ])
 AC_OUTPUT
 
src/Makefile.am +2 -0
index e87f030..842d0b2 100644
@@ -59,6 +59,8 @@ intel_drv_la_SOURCES = \
 	intel_driver.h \
 	intel_options.c \
 	intel_module.c \
+	backlight.c \
+	backlight.h \
 	compat-api.h \
 	$(NULL)
 
src/backlight.c new file +142 -0

142 lines not on this page · raw message

src/backlight.h new file +22 -0
new file mode 100644
index 0000000..dd036c4
@@ -0,0 +1,22 @@
+#ifndef BACKLIGHT_H
+#define BACKLIGHT_H
+
+struct backlight_helper {
+	int child_created;
+	int fds[2];
+	int pid;
+	const char *iface;
+};
+
+#ifdef __linux__ 
+
+void backlight_helper_set(struct backlight_helper *helper,
+			 xf86OutputPtr output, const char *iface, int level);
+void backlight_helper_cleanup(struct backlight_helper *helper);
+
+#else
+
+#define backlight_helper_cleanup(helper)
+
+#endif
+#endif
src/sna/sna_display.c +9 -8
index 521d4ef..559c8fa 100644
@@ -44,6 +44,7 @@
 #include "sna_reg.h"
 #include "fb/fbpict.h"
 #include "intel_options.h"
+#include "backlight.h"
 
 #include <xf86Crtc.h>
 
@@ -144,6 +145,7 @@ struct sna_output {
 	char *backlight_iface;
 	int backlight_active_level;
 	int backlight_max;
+	struct backlight_helper backlight_helper;
 
 	int num_modes;
 	struct drm_mode_modeinfo *modes;
@@ -391,6 +393,12 @@ sna_output_backlight_set(xf86OutputPtr output, int level)
 		BACKLIGHT_CLASS, sna_output->backlight_iface);
 	fd = open(path, O_RDWR);
 	if (fd == -1) {
+		/* If this is an access error, invoke the helper instead */
+		if (errno == EACCES)  {
+			backlight_helper_set(&sna_output->backlight_helper,
+				output, sna_output->backlight_iface, level);
+			return;
+		}
 		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, "failed to open %s for backlight "
 			   "control: %s\n", path, strerror(errno));
 		return;
@@ -447,14 +455,6 @@ sna_output_backlight_get_max(xf86OutputPtr output)
 	char path[1024], val[BACKLIGHT_VALUE_LEN];
 	int fd, max = 0;
 
-	/* We are used as an initial check to see if we can
-	 * control the backlight, so first test if we can set values.
-	 */
-	sprintf(path, "%s/%s/brightness",
-		BACKLIGHT_CLASS, sna_output->backlight_iface);
-	if (access(path, R_OK | W_OK))
-		return -1;
-
 	sprintf(path, "%s/%s/max_brightness",
 		BACKLIGHT_CLASS, sna_output->backlight_iface);
 	fd = open(path, O_RDONLY);
@@ -2539,6 +2539,7 @@ sna_output_destroy(xf86OutputPtr output)
 	free(sna_output->prop_ids);
 	free(sna_output->prop_values);
 
+	backlight_helper_cleanup(&sna_output->backlight_helper);
 	free(sna_output->backlight_iface);
 
 	free(sna_output);
src/uxa/intel_display.c +9 -8
index e1b2920..41b391e 100644
@@ -43,6 +43,7 @@
 #include "intel.h"
 #include "intel_bufmgr.h"
 #include "intel_options.h"
+#include "backlight.h"
 #include "xf86drm.h"
 #include "xf86drmMode.h"
 #include "X11/Xatom.h"
@@ -123,6 +124,7 @@ struct intel_output {
 	const char *backlight_iface;
 	int backlight_active_level;
 	int backlight_max;
+	struct backlight_helper backlight_helper;
 	xf86OutputPtr output;
 	struct list link;
 };
@@ -245,6 +247,12 @@ intel_output_backlight_set(xf86OutputPtr output, int level)
 		BACKLIGHT_CLASS, intel_output->backlight_iface);
 	fd = open(path, O_RDWR);
 	if (fd == -1) {
+		/* If this is an access error, invoke the helper instead */
+		if (errno == EACCES)  {
+			backlight_helper_set(&intel_output->backlight_helper,
+				output, intel_output->backlight_iface, level);
+			return;
+		}
 		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, "failed to open %s for backlight "
 			   "control: %s\n", path, strerror(errno));
 		return;
@@ -298,14 +306,6 @@ intel_output_backlight_get_max(xf86OutputPtr output)
 	char path[BACKLIGHT_PATH_LEN], val[BACKLIGHT_VALUE_LEN];
 	int fd, max = 0;
 
-	/* We are used as an initial check to see if we can
-	 * control the backlight, so first test if we can set values.
-	 */
-	sprintf(path, "%s/%s/brightness",
-		BACKLIGHT_CLASS, intel_output->backlight_iface);
-	if (access(path, R_OK | W_OK))
-		return -1;
-
 	sprintf(path, "%s/%s/max_brightness",
 		BACKLIGHT_CLASS, intel_output->backlight_iface);
 	fd = open(path, O_RDONLY);
@@ -1083,6 +1083,7 @@ intel_output_destroy(xf86OutputPtr output)
 	intel_output->mode_output = NULL;
 
 	list_del(&intel_output->link);
+	backlight_helper_cleanup(&intel_output->backlight_helper);
 	free(intel_output);
 
 	output->driver_private = NULL;
Signature · 1 line
1.8.5.3
#3 lore raw

Re: [PATCH 3/3] xf86-video-intel: Add a helper for setting backlight without root rights

Quoted 11 lines · Hans de Goede

Once the xserver stops running as root on kms capabable systems, we will need some other way to access the backlight.

The approach taken in this patch leaves most of the heavy lifting (wrt doing everything suid root safe) to pkexec, as is done in ie gnome-settings-daemon, which controls the backlight directly on ati and nouveau cards.

This commit adds src/backlight.h and src/backlight.c as a place to share common backlight code, in the future most of the duplicate backlight code inside src/sna/sna_display.c and src/uxa/intel_display.c should be moved there.

Right, I agree and think we can make that transition now. It should not result in much more code than motion than introducing the helper. Importantly, I think it will also clarify the tests we require before declaring the backlight functional.

Is there a reason why the standalone helper is not kept alive? We could just connect the pipe to the helper's stdin and launch it as a daemon rather than keeping a child around who's only task is to spawn the standalone helper everytime?

Otherwise the only other tweak I can see would be to replace the #ifdef __linux__ with something like #ifdef USE_BACKLIGHT_HELPER -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#4 lore raw

Re: [PATCH 3/3] xf86-video-intel: Add a helper for setting backlight without root rights

Hi,

Quoted 9 lines · Chris Wilson
Quoted 8 lines · Hans de Goede

Once the xserver stops running as root on kms capabable systems, we will need some other way to access the backlight.

The approach taken in this patch leaves most of the heavy lifting (wrt doing everything suid root safe) to pkexec, as is done in ie gnome-settings-daemon, which controls the backlight directly on ati and nouveau cards.

Quoted 8 lines
Quoted 3 lines

This commit adds src/backlight.h and src/backlight.c as a place to share common backlight code, in the future most of the duplicate backlight code inside src/sna/sna_display.c and src/uxa/intel_display.c should be moved there.

Right, I agree and think we can make that transition now. It should not result in much more code than motion than introducing the helper. Importantly, I think it will also clarify the tests we require before declaring the backlight functional.

So you would like me to unify things before adding the helper I assume, so first a unifying patch introducing backlight.[c,h] and then a patch adding the helper on top ?

Note I might chicken out wrt the bits for determining which iface to use, at a first glance those seem significantly different between the sna and uxa code, but the rest should be easy to unify.

Quoted 4 lines

Is there a reason why the standalone helper is not kept alive? We could just connect the pipe to the helper's stdin and launch it as a daemon rather than keeping a child around who's only task is to spawn the standalone helper everytime?

Hmm, so to be clear what you mean is having the helper take only the iface on its cmdline, and then read level values from stdin, until it gets EOF on stdin, yes that should work nicely, I'll change that in the next fd.

Quoted 2 lines

Otherwise the only other tweak I can see would be to replace the #ifdef __linux__ with something like #ifdef USE_BACKLIGHT_HELPER

Yes that would be cleaner I'll change that too.

Regards,

Hans

#5 lore raw

Re: [PATCH 3/3] xf86-video-intel: Add a helper for setting backlight without root rights

Quoted 16 lines · Hans de Goede

Hi,

Quoted 13 lines · Chris Wilson
Quoted 11 lines · Hans de Goede

Once the xserver stops running as root on kms capabable systems, we will need some other way to access the backlight.

The approach taken in this patch leaves most of the heavy lifting (wrt doing everything suid root safe) to pkexec, as is done in ie gnome-settings-daemon, which controls the backlight directly on ati and nouveau cards.

This commit adds src/backlight.h and src/backlight.c as a place to share common backlight code, in the future most of the duplicate backlight code inside src/sna/sna_display.c and src/uxa/intel_display.c should be moved there.

Quoted 8 lines
Quoted 4 lines

Right, I agree and think we can make that transition now. It should not result in much more code than motion than introducing the helper. Importantly, I think it will also clarify the tests we require before declaring the backlight functional.

So you would like me to unify things before adding the helper I assume, so first a unifying patch introducing backlight.[c,h] and then a patch adding the helper on top ?

No, I've just moved some code around in your patch and reduced a little more duplication. I'm happy with it all now, except for one minor niggle..

How do you make pkexec work? On my f20, it just hangs in polkit_authority_check_authorization_sync()

I've verfied that the direct interface works. I've verifed that the helper works. But pkexec doesn't launch the helper. :(

Quoted 4 lines

Note I might chicken out wrt the bits for determining which iface to use, at a first glance those seem significantly different between the sna and uxa code, but the rest should be easy to unify.

Quoted 8 lines
Quoted 4 lines

Is there a reason why the standalone helper is not kept alive? We could just connect the pipe to the helper's stdin and launch it as a daemon rather than keeping a child around who's only task is to spawn the standalone helper everytime?

Hmm, so to be clear what you mean is having the helper take only the iface on its cmdline, and then read level values from stdin, until it gets EOF on stdin, yes that should work nicely, I'll change that in the next fd.

Already done.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#6 lore raw

Re: [PATCH 3/3] xf86-video-intel: Add a helper for setting backlight without root rights

Hi,

Quoted 22 lines · Chris Wilson
Quoted 21 lines · Hans de Goede

Hi,

Quoted 17 lines · Chris Wilson
Quoted 11 lines · Hans de Goede

Once the xserver stops running as root on kms capabable systems, we will need some other way to access the backlight.

The approach taken in this patch leaves most of the heavy lifting (wrt doing everything suid root safe) to pkexec, as is done in ie gnome-settings-daemon, which controls the backlight directly on ati and nouveau cards.

This commit adds src/backlight.h and src/backlight.c as a place to share common backlight code, in the future most of the duplicate backlight code inside src/sna/sna_display.c and src/uxa/intel_display.c should be moved there.

Right, I agree and think we can make that transition now. It should not result in much more code than motion than introducing the helper. Importantly, I think it will also clarify the tests we require before declaring the backlight functional.

Quoted 7 lines
Quoted 3 lines

So you would like me to unify things before adding the helper I assume, so first a unifying patch introducing backlight.[c,h] and then a patch adding the helper on top ?

No, I've just moved some code around in your patch and reduced a little more duplication. I'm happy with it all now, except for one minor niggle..

Nice, thanks for working on this! I'll run some tests with your modified code coming Monday to ensure that everything works as it should with pkexec and the xserver running as a regular user.

Quoted 2 lines

How do you make pkexec work? On my f20, it just hangs in polkit_authority_check_authorization_sync()

Do you have selinux in enforcing mode ? That is know to cause this issue. I need to file selinux policy bugs for both this as well as for Xorg's inability to talk to systemd-logind when selinux is in enforcing mode. Doing:
setenforce 0 as root may help.

Regards,

Hans

#7 lore raw

PATCH 1/1 intel: Add a helper for setting backlight without root rights

In reply to Hans de Goede

From: Hans de Goede <[email protected]>

Once the xserver stops running as root on kms capabable systems, we will need some other way to access the backlight.

The approach taken in this patch leaves most of the heavy lifting (wrt doing everything suid root safe) to pkexec, as is done in ie gnome-settings-daemon, which controls the backlight directly on ati and nouveau cards.

This commit adds src/backlight.h and src/backlight.c as a place to share common backlight code, in the future most of the duplicate backlight code inside src/sna/sna_display.c and src/uxa/intel_display.c should be moved there.

---
 Makefile.am                                        |   6 +-
 configure.ac                                       |  20 +-
 src/Makefile.am                                    |   2 +
 src/backlight.c                                    | 225 +++++++++++++++++++++
 src/backlight.h                                    |  46 +++++
 src/sna/sna_display.c                              | 194 +++++-------------
 src/uxa/intel_display.c                            | 168 ++++-----------
 tools/Makefile.am                                  |  26 ++-
 tools/backlight_helper.c                           |  56 +++++
 ...g.x.xf86-video-intel.backlight-helper.policy.in |  19 ++
 10 files changed, 467 insertions(+), 295 deletions(-)
 create mode 100644 src/backlight.c
 create mode 100644 src/backlight.h
 create mode 100644 tools/backlight_helper.c
 create mode 100644 tools/org.x.xf86-video-intel.backlight-helper.policy.in
Makefile.am +1 -5
index 71c7698..6bb4854 100644
@@ -20,11 +20,7 @@
 
 ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4
 
-SUBDIRS = man xvmc src
-
-if BUILD_TOOLS
-SUBDIRS += tools
-endif
+SUBDIRS = man xvmc src tools
 
 MAINTAINERCLEANFILES = ChangeLog INSTALL
 
configure.ac +17 -3
index 4f73ba4..c9410c1 100644
@@ -62,6 +62,18 @@ AC_DISABLE_STATIC
 AC_PROG_LIBTOOL
 AC_SYS_LARGEFILE
 
+# Platform specific settings
+case $host_os in
+  *linux*)
+    backlight_helper=yes
+    ;;
+esac
+AM_CONDITIONAL(BUILD_BACKLIGHT_HELPER, [test "x$backlight_helper" = "xyes"])
+if test "x$backlight_helper" = "xyes"; then
+	tools_msg="$tools_msg xf86-video-intel-backlight-helper"
+	AC_DEFINE(USE_BACKLIGHT_HELPER, 1, [Enable use of the backlight helper interfaces])
+fi
+
 # Are we in a git checkout?
 dot_git=no
 if test -e .git; then
@@ -218,6 +230,8 @@ if test "x$tools" = "xyes"; then
       AC_CHECK_HEADERS([X11/extensions/XShm.h X11/extensions/shmproto.h X11/extensions/shmstr.h], [], [tools=no],
 		       [#include <X11/Xlibint.h>
 			#include <X11/Xproto.h>])
+
+      tools_msg="$tools_msg intel-virtual-output"
 fi
 
 AM_CONDITIONAL(BUILD_TOOLS, test "x$tools" = "xyes")
@@ -681,6 +695,7 @@ fi
 DRIVER_NAME="intel"
 AC_SUBST([DRIVER_NAME])
 AC_SUBST([moduledir])
+AC_DEFINE_DIR([PREFIX_PATH], prefix, [installation prefix])
 
 AC_CONFIG_FILES([
                 Makefile
@@ -700,6 +715,7 @@ AC_CONFIG_FILES([
                 xvmc/shader/vld/Makefile
 		test/Makefile
 		tools/Makefile
+		tools/org.x.xf86-video-intel.backlight-helper.policy
 ])
 AC_OUTPUT
 
@@ -730,9 +746,7 @@ if test "x$dri_msg" = "x"; then
 	dri_msg=" none"
 fi
 
-if test "x$tools" = "xyes"; then
-	tools_msg=" intel-virtual-output"
-else
+if test "x$tools_msg" = "x"; then
 	tools_msg=" none"
 fi
 
src/Makefile.am +2 -0
index b7ccde6..da75125 100644
@@ -52,6 +52,8 @@ endif
 NULL:=#
 
 intel_drv_la_SOURCES = \
+	backlight.c \
+	backlight.h \
 	fd.h \
 	fd.c \
 	i915_pciids.h \
src/backlight.c new file +225 -0

225 lines not on this page · raw message

src/backlight.h new file +46 -0

46 lines not on this page · raw message

src/sna/sna_display.c +45 -149

362 lines not on this page · raw message

src/uxa/intel_display.c +34 -134

279 lines not on this page · raw message

tools/Makefile.am +22 -4
index d294e2a..c168e27 100644
@@ -20,23 +20,41 @@
 
 AM_CFLAGS = \
 	@CWARNFLAGS@ \
-	$(TOOL_CFLAGS) \
 	@NOWARNFLAGS@ \
 	$(NULL)
 
 drivermandir = $(DRIVER_MAN_DIR)
+backlight_helperdir = $(prefix)/libexec
+policydir = $(datarootdir)/polkit-1/actions
 
+if BUILD_TOOLS
 bin_PROGRAMS = intel-virtual-output
 driverman_DATA = intel-virtual-output.$(DRIVER_MAN_SUFFIX)
+endif
+
+if BUILD_BACKLIGHT_HELPER
+backlight_helper_PROGRAMS = xf86-video-intel-backlight-helper
+nodist_policy_DATA = org.x.xf86-video-intel.backlight-helper.policy
+endif
 
+intel_virtual_output_CFLAGS = \
+	@CWARNFLAGS@ \
+	$(TOOL_CFLAGS) \
+	@NOWARNFLAGS@ \
+	$(NULL)
 intel_virtual_output_SOURCES = \
 	virtual.c \
 	$(NULL)
+intel_virtual_output_LDADD = \
+	$(TOOL_LIBS) \
+	$(NULL)
 
-intel_virtual_output_LDADD = $(TOOL_LIBS)
+xf86_video_intel_backlight_helper_SOURCES = \
+	backlight_helper.c \
+	$(NULL)
 
-EXTRA_DIST = intel-virtual-output.man
-CLEANFILES = $(driverman_DATA)
+EXTRA_DIST = intel-virtual-output.man org.x.xf86-video-intel.backlight-helper.policy.in
+CLEANFILES = $(driverman_DATA) $(nodist_policy_DATA)
 
 # String replacements in MAN_SUBSTS now come from xorg-macros.m4 via configure
 SUFFIXES = .$(DRIVER_MAN_SUFFIX) .man
tools/backlight_helper.c new file +56 -0

56 lines not on this page · raw message

tools/org.x.xf86-video-intel.backlight-helper.policy.in new file +19 -0
new file mode 100644
index 0000000..37e9622
@@ -0,0 +1,19 @@
+<?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>
+  <vendor>The X.Org project</vendor>
+  <vendor_url>https://01.org/linuxgraphics/community/xf86-video-intel</vendor_url>
+  <icon_name>brightness</icon_name>
+  <action id="org.x.xf86-video-intel.backlight-helper">
+    <description>Modify lcd panel brightness</description>
+    <message>Authentication is required to modify the lcd panel 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">@prefix@/libexec/xf86-video-intel-backlight-helper</annotate>
+  </action>
+</policyconfig>
Signature · 1 line
1.9.0.rc3
#8 lore raw

Re: [PATCH] intel: Add a helper for setting backlight without root rights

Quoted 5 lines · Chris Wilson

From: Hans de Goede <[email protected]>

Once the xserver stops running as root on kms capabable systems, we will need some other way to access the backlight.

Quoted 8 lines

The approach taken in this patch leaves most of the heavy lifting (wrt doing everything suid root safe) to pkexec, as is done in ie gnome-settings-daemon, which controls the backlight directly on ati and nouveau cards.

This commit adds src/backlight.h and src/backlight.c as a place to share common backlight code, in the future most of the duplicate backlight code inside src/sna/sna_display.c and src/uxa/intel_display.c should be moved there.

Spent some more time bikeshedding, satisfying myself that it all should
be working properly, e.g. (echo 15 ; sleep 2; echo 4; sleep 1; echo -e
"20\n10"; sleep 1; echo -n 1; sleep 1; echo 5) | pkexec /usr/libexec/xf86-video-intel-backlight-helper works and so decided that it was just pkexec not behaving as expected
during Xorg launch.

Overall is was nice improvement, thanks a lot.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre