You are not logged in.

#1 2016-05-26 21:54:18

tyrann
Member
Registered: 2016-05-25
Posts: 13

[SOLVED] xbacklight problem

I'm trying to make the backlight of my Lenovo T460s (Skylake) to work. I am able to modify the backlight value manually via

/sys/class/backlight/intel_backlight

but it is a bit tedious.

So, xbacklight gives me "No outputs have backlight property", I followed the indication on the wiki about Backlight

I created a configuration file in /etc/X11/xorg.conf.d, called 20-intel.conf which looks like this:

Section "Device"
    	    Identifier  "Intel Graphics"
      	    Driver      "intel"
     	    Option      "Backlight"  "intel_backlight"
EndSection

Sadly with this, xorg won't start. I get the following error in the log:

[ 11579.922] 
X.Org X Server 1.18.3
Release Date: 2016-04-04
[ 11579.922] X Protocol Version 11, Revision 0
[ 11579.922] Build Operating System: Linux 4.2.5-1-ARCH x86_64 
[ 11579.922] Current Operating System: Linux archbase 4.5.4-1-ARCH #1 SMP PREEMPT Wed May 11 22:21:28 CEST 2016 x86_64
[ 11579.922] Kernel command line: initrd=\initramfs-linux.img root=/dev/sda3 rw
[ 11579.922] Build Date: 05 April 2016  05:24:02PM
[ 11579.922]  
[ 11579.922] Current version of pixman: 0.34.0
[ 11579.922] 	Before reporting problems, check http://wiki.x.org
	to make sure that you have the latest version.
[ 11579.922] Markers: (--) probed, (**) from config file, (==) default setting,
	(++) from command line, (!!) notice, (II) informational,
	(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
[ 11579.923] (==) Log file: "/home/tyrann/.local/share/xorg/Xorg.0.log", Time: Thu May 26 23:33:12 2016
[ 11579.923] (==) Using config directory: "/etc/X11/xorg.conf.d"
[ 11579.923] (==) Using system config directory "/usr/share/X11/xorg.conf.d"
[ 11579.923] (==) No Layout section.  Using the first Screen section.
[ 11579.923] (==) No screen section available. Using defaults.
[ 11579.923] (**) |-->Screen "Default Screen Section" (0)
[ 11579.923] (**) |   |-->Monitor "<default monitor>"
[ 11579.923] (==) No device specified for screen "Default Screen Section".
	Using the first device section listed.
[ 11579.923] (**) |   |-->Device "Intel Graphics"
[ 11579.923] (==) No monitor specified for screen "Default Screen Section".
	Using a default monitor configuration.
[ 11579.923] (==) Automatically adding devices
[ 11579.923] (==) Automatically enabling devices
[ 11579.923] (==) Automatically adding GPU devices
[ 11579.923] (==) Max clients allowed: 256, resource mask: 0x1fffff
[ 11579.923] (WW) `fonts.dir' not found (or not valid) in "/usr/share/fonts/100dpi/".
[ 11579.923] 	Entry deleted from font path.
[ 11579.923] 	(Run 'mkfontdir' on "/usr/share/fonts/100dpi/").
[ 11579.923] (WW) `fonts.dir' not found (or not valid) in "/usr/share/fonts/75dpi/".
[ 11579.923] 	Entry deleted from font path.
[ 11579.923] 	(Run 'mkfontdir' on "/usr/share/fonts/75dpi/").
[ 11579.923] (==) FontPath set to:
	/usr/share/fonts/misc/,
	/usr/share/fonts/TTF/,
	/usr/share/fonts/OTF/,
	/usr/share/fonts/Type1/
[ 11579.923] (==) ModulePath set to "/usr/lib/xorg/modules"
[ 11579.923] (II) The server relies on udev to provide the list of input devices.
	If no devices become available, reconfigure udev or disable AutoAddDevices.
[ 11579.923] (II) Loader magic: 0x819d20
[ 11579.923] (II) Module ABI versions:
[ 11579.923] 	X.Org ANSI C Emulation: 0.4
[ 11579.923] 	X.Org Video Driver: 20.0
[ 11579.923] 	X.Org XInput driver : 22.1
[ 11579.923] 	X.Org Server Extension : 9.0
[ 11579.924] (++) using VT number 1

[ 11579.924] (--) controlling tty is VT number 1, auto-enabling KeepTty
[ 11579.926] (II) systemd-logind: took control of session /org/freedesktop/login1/session/c1
[ 11579.927] (II) xfree86: Adding drm device (/dev/dri/card0)
[ 11579.927] (II) systemd-logind: got fd for /dev/dri/card0 226:0 fd 8 paused 0
[ 11579.929] (--) PCI:*(0:0:2:0) 8086:1916:17aa:2233 rev 7, Mem @ 0xf0000000/16777216, 0xe0000000/268435456, I/O @ 0x0000e000/64
[ 11579.930] (WW) Open ACPI failed (/var/run/acpid.socket) (No such file or directory)
[ 11579.930] (II) LoadModule: "glx"
[ 11579.930] (II) Loading /usr/lib/xorg/modules/extensions/libglx.so
[ 11579.931] (II) Module glx: vendor="X.Org Foundation"
[ 11579.931] 	compiled for 1.18.3, module version = 1.0.0
[ 11579.931] 	ABI class: X.Org Server Extension, version 9.0
[ 11579.931] (==) AIGLX enabled
[ 11579.931] (II) LoadModule: "intel"
[ 11579.931] (WW) Warning, couldn't open module intel
[ 11579.931] (II) UnloadModule: "intel"
[ 11579.931] (II) Unloading intel
[ 11579.931] (EE) Failed to load module "intel" (module does not exist, 0)
[ 11579.931] (EE) No drivers available.
[ 11579.931] (EE) 
Fatal server error:
[ 11579.931] (EE) no screens found(EE) 

Last edited by tyrann (2016-05-27 19:51:53)

Offline

#2 2016-05-27 16:04:06

tyrann
Member
Registered: 2016-05-25
Posts: 13

Re: [SOLVED] xbacklight problem

After a bit of research, I found out that the "modesetting" driver should be used instead of the intel one. However, modesetting does not seem to have a "Backlight" option.

So how can I pass the option so that xbacklight knows where to look?

Thanks

Offline

#3 2016-05-27 16:07:33

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,804

Re: [SOLVED] xbacklight problem

What is the output find /sys/class/backlight   ?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#4 2016-05-27 16:34:07

tyrann
Member
Registered: 2016-05-25
Posts: 13

Re: [SOLVED] xbacklight problem

Thank you for the reply, the output is:

/sys/class/backlight/
/sys/class/backlight/intel_backlight

Offline

#5 2016-05-27 17:14:51

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,804

Re: [SOLVED] xbacklight problem

That is interesting.  I recently changed from Intel to modesetting, but had not noticed this problem.  I see it as well.  The reason I did not notice is because I use my own backlight program for a variety of reasons.

If you are interested:

/**
 *
 * @mainpage Backlight
 *
 * @section Introduction
 * This program is a command line program that allows the brightness level of
 * an Intel video system to be read, set, incremented or decremented.
 * 
 * It will read and write @a /sys/class/backlight/intel_backlight/brightness
 * to establish the current backlight brightness and can write to that file to change 
 * the brightness.
 * 
 * To establish the maximum allowed brightness, it will read
 * @a /sys/class/backlight/intel_backlight/max_brightness
 * 
 * @author Eric Waller
 *
 * @date September 2015
 *
 * @copyright 
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 * 
 * @section Usage 
 * backlight [OPTION...]
 * Option          | Description
 * --------------- | --------------
 *   -d, --dec=INT | Decrement
 *   -i, --inc=INT | Increment
 *   -s, --set=INT | Set
 *   -v, --verbose | Produce verbose output
 *   -?, --help    | Give this help list
 *       --usage   | Give a short usage message
 *   -V, --version | Print program version
 * 
 * The program will report the maximum permitted brightness and the 
 * brightness setting when the program exits
 */

#include <stdlib.h>
#include <stdio.h>
#include <argp.h>

/**
 * Stores the values of the program options that are passed
 * in from the command line.  The values initially set to invalid values by
 * main and are updated as the command line parameters are parsed.  It is 
 * only permissible to specify one of inc, dec, or set.
 */
typedef struct {
  int verbose; /**< If set, be verbose */
  int inc;  /**< Value by which to increment the brightness */
  int dec;  /**< Value by which to decrement the brightness */
  int set;  /**< Value by which to set the brightness */ 
} ProgramArguments;

static ProgramArguments arguments;

///  Define the acceptable command line options

static struct argp_option options[] =               
{
  {"verbose", 'v', 0, 0, "Produce verbose output"},  /**< The verbose command line flag has no argument */
  {"inc", 'i', "INT",0,"Increment"},                 ///< increment command line flag requires an integer argument
  {"dec", 'd', "INT",0,"Decrement"},                 ///< decrement command line flag requires an integer argument
  {"set", 's', "INT",0,"Set"},                       ///< decrement command line flag requires an integer argument
  {0}
};

const char *argp_program_version = "backlight 0.1";
const char *argp_program_bug_address = "<ewwaller+code@gmail.com>";
static char doc[] =
  "backlight -- Read, set, increment, or decrement the backlight on Intel graphics based displays";

static char args_doc[] = "";
static error_t parse_opt (int key, char *arg, struct argp_state *state);

static struct argp argp = { options, parse_opt, args_doc, doc };


int
ReadSysFile(char *theFileName)
{
  /**  Read a file from @a /sys and interpret the data on the first line of 
   *   the "file" as an integer expresed as a ascii decimal string 
   *   
   *   @param[in] *theFileName A zero terminated string containing the name and
   *                           path of the sys file
   *   @return the integer value read from the file.  -1 indicates failure. 
   */

  char* readBuffer = NULL;
  long unsigned int  bufferSize = 0;
  
  FILE *theFile = fopen(theFileName,"r");
  if (!theFile)
    {
      fprintf(stderr,"\nCould not open the file %s\n",theFileName);
      return -1;
    }
  
  getline(&readBuffer, &bufferSize, theFile);
  if (readBuffer)
    {
      int theIntValue=atoi(readBuffer);
      free(readBuffer);
      readBuffer=NULL;
      bufferSize=0;
      fclose(theFile);
      return (theIntValue);
    }
  fclose(theFile);
  return -1;
}

int
WriteSysFile(char *theFileName, int theValue)
{
  /**  
   *   Write a file from /sys an interpret the data on the first line of the "file" as an integer expresed as a ascii decimal string 
   *    
   *   @param[in] *theFileName A pointer to a zero terminated string containing the 
   *                           name and path of the sys file
   *    @param[in] theValue    The value to be written to the file
   *    @return                0 or positive integer is success;  negative integer is failure
  */

  FILE *theFile = fopen(theFileName,"w");
  if (!theFile)
    {
      fprintf(stderr,"\nCould not open the file %s\n",theFileName);
      return -1;
    }
  int returnValue;
  returnValue = fprintf(theFile,"%i\n",theValue);
  fclose(theFile);
  return returnValue;
}

int
parseIntArgument(char *arg)
{
  /**
   *  Convert a null terminated string of decimal digits to an integer.  Any non-decimal 
   *  digits in the string will result in a failure.
   *  
   *  @param[in] arg A pointer to null terminated string of decimal digits
   *  @return A positive or zero integer represented by the string. 
   *  @warning An error condition will cause the program to exit with an error.
   */
  
  char *endptr, *str;
  long val;
  errno = 0;    /* To distinguish success/failure after call */
  val = strtol(arg, &endptr, 10);
  if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
      || (errno != 0 && val == 0))
    {
      perror("strtol");
      exit(EXIT_FAILURE);
    }
  
  if (endptr == str) {
    fprintf(stderr, "No digits were found\n");
    exit(EXIT_FAILURE);
  }
  if (*endptr)
    {+
      printf ("Non digit in decimal value\n");
      exit(EXIT_FAILURE);
    }
  /* If we got here, strtol() successfully parsed a number */
  return (int)val;
}

void
TooManyOptions(void)
{
  /**
   * A simple helper function that prints an error message and exits
   * @warning Calling this function causes the program to exit with an error.
   */

  printf("Increment, Decrement and Set are mutually exclusive options\n");
  exit(EXIT_FAILURE);
}

static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  /**
   *  Process the command line arguments and options.  Collect all 
   *  the options and remember their state. This function is called one
   *  time for each key.  As the keys are passed in, check to ensure they
   *  do not conflict with each other.  When there are no more keys, 
   *  ensure there are no additional parameters that were passed into the 
   *  program -- this one does not want any.
   *
   *  @param[in]     key    An integer that represents a char value of one 
   *                        of options passed from the command line.
   *  @param[in,out] *arg   A pointer to a null terminated string that is the argument of the 
   *                        option represented by key.
   *  @param[in]     *state  
   */
  
  ProgramArguments* argumentPtr = state->input;
  
  switch (key)
    {
    case 'v':
      argumentPtr->verbose = 1;
      break;
    case 'i':
      if ((arguments.dec != -1) || (arguments.set != -1))
	TooManyOptions();
      arguments.inc=parseIntArgument(arg);
      break;
    case 'd':
      if ((arguments.inc != -1) || (arguments.set != -1))
	TooManyOptions();
      arguments.dec=parseIntArgument(arg);
      break;
    case 's':
      if ((arguments.dec != -1) || (arguments.inc != -1))
	TooManyOptions();
      arguments.set=parseIntArgument(arg);
      break;
    case ARGP_KEY_NO_ARGS:
      /* If there are no Arguments, that is good.  We don't want any */
      break;
    case ARGP_KEY_ARG:
      /* I am not expecting any arguments that are not options. */
      argp_usage (state);
      break;
    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

int
main (int argc, char** argv)
{
  /**
   * This is the main function.   
   * line.  It will determine the maximum brightness permitted, and the current brightness,
   * and will parse the parameters passed in on the command and determine their validity.  If
   * they are valid, and they call for a change in the brightness setting, it will write to the
   * appropriate system file to cause the brightness to change.  
   *
   *  @param[in]  argc    An integer that represents the number of command line parameters.
   *  @param[in]  **argv  A pointer to an array of pointers to null terminated strings that store
   *                      the parameters on the command line.
   *  @return             An integer that represents the exit value of the program.  0 means success.
   */
  
  arguments.verbose = 0;
  arguments.set = -1;
  arguments.inc = -1;
  arguments.dec = -1;
  
  int max_brightness = 0;
  int brightness =0;
  max_brightness = ReadSysFile("/sys/class/backlight/intel_backlight/max_brightness");
  if (max_brightness < 0)
    exit(EXIT_FAILURE);
  brightness = ReadSysFile("/sys/class/backlight/intel_backlight/brightness");
  if (brightness < 0)
    exit(EXIT_FAILURE);
  argp_parse (&argp, argc, argv, 0, 0, &arguments);
  if (arguments.inc >= 0 ) brightness += arguments.inc;
  if (arguments.dec >= 0 ) brightness -= arguments.dec;
  if (arguments.set >= 0 ) brightness  = arguments.set;
  if (brightness<0) brightness = 0;
  if (brightness>max_brightness) brightness = max_brightness;
  if ((arguments.inc >= 0) || (arguments.dec >= 0) || (arguments.set >= 0))
    if (WriteSysFile("/sys/class/backlight/intel_backlight/brightness",brightness) < 0)
      printf("Unable to set brightness.  Check permissions");
  printf("Max Brightness = %i\n",max_brightness);
  printf("Current Brightness = %i\n",brightness);
  if (arguments.verbose)
    {
      printf("Increment:%i; Decrement:%i, Set:%i\n",arguments.inc,arguments.dec,arguments.set);
    }
}

Compile it, change the owner to root, and set the uid bit (chmod u+s filename).   See if it works for you

Last edited by ewaller (2016-09-28 01:55:03)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#6 2016-05-27 18:36:20

tyrann
Member
Registered: 2016-05-25
Posts: 13

Re: [SOLVED] xbacklight problem

Thanks a lot for sharing your program, this should indeed work. But this requires root access everytime you want to change the backlight, right?

Offline

#7 2016-05-27 19:08:56

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,804

Re: [SOLVED] xbacklight problem

Yes, and no.  When you set the uid bit in the permissions, it tells the kernel to run the program as if it were the owner of the file, not the user who is running it.   Security rules ONLY permit this for compiled binaries which is why I wrote it in C.

That is why we changed the owner to root, then set the UID.  Every time you run it as your user, it runs as if root were running it

Last edited by ewaller (2016-05-27 19:09:51)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#8 2016-05-27 19:50:28

tyrann
Member
Registered: 2016-05-25
Posts: 13

Re: [SOLVED] xbacklight problem

Thank you for the explanation, I didn't know this was possible to do for compiled binaries. It works great, thanks again.

Offline

Board footer

Powered by FluxBB