backlight.c revision 39883f622f392d8579f4428fc5a789a102efbb10
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "util.h"
#include "mkdir.h"
#include "fileio.h"
#include "libudev.h"
#include "udev-util.h"
struct udev_device *parent;
if (!parent)
return NULL;
if (!subsystem)
return NULL;
if (!sysname)
return NULL;
const char *c;
if (!c)
return NULL;
c += strspn(c, "0123456789");
if (*c == '-') {
/* A connector DRM device, let's ignore all but LVDS and eDP! */
if (!startswith(c, "-LVDS-") &&
!startswith(c, "-Embedded DisplayPort-"))
return NULL;
}
const char *value;
if (value) {
unsigned long class = 0;
return NULL;
}
/* Graphics card */
if (class == 0x30000)
return parent;
}
return parent;
return find_pci_or_platform_parent(parent);
}
assert(a);
assert(b);
return false;
return false;
return true;
}
struct udev_device *parent;
const char *v, *subsystem;
int r;
/* Verify whether we should actually care for a specific
* backlight device. For backlight devices there might be
* multiple ways to access the same control: "firmware"
* (i.e. ACPI), "platform" (i.e. via the machine's EC) and
* "raw" (via the graphics card). In general we should prefer
* "firmware" (i.e. ACPI) or "platform" access over "raw"
* compatibility with possible low-level hotkey handling of
* screen brightness. The kernel will already make sure to
* expose only one of "firmware" and "platform" for the same
* device to userspace. However, we still need to make sure
* that we use "raw" only if no "firmware" or "platform"
* device for the same device exists. */
return true;
if (!streq_ptr(v, "raw"))
return true;
if (!parent)
return true;
if (!subsystem)
return true;
if (!enumerate)
return true;
if (r < 0)
return true;
if (r < 0)
return true;
struct udev_device *other_parent;
const char *other_subsystem;
if (!other)
return true;
continue;
continue;
/* OK, so there's another backlight device, and it's a
* platform or firmware device, so, let's see if we
* can verify it belongs to the same device as
* ours. */
if (!other_parent)
continue;
/* Both have the same PCI parent, that means
* we are out. */
log_debug("Skipping backlight device %s, since backlight device %s is on same PCI device and, takes precedence.", udev_device_get_sysname(device), udev_device_get_sysname(other));
return false;
}
/* The other is connected to the platform bus
* and we are a PCI device, that also means we
* are out. */
log_debug("Skipping backlight device %s, since backlight device %s is a platform device and takes precedence.", udev_device_get_sysname(device), udev_device_get_sysname(other));
return false;
}
}
return true;
}
_cleanup_free_ char *saved = NULL, *ss = NULL, *escaped_ss = NULL, *escaped_sysname = NULL, *escaped_path_id = NULL;
int r;
if (argc != 3) {
log_error("This program requires two arguments.");
return EXIT_FAILURE;
}
log_open();
umask(0022);
if (r < 0) {
return EXIT_FAILURE;
}
if (!udev) {
log_oom();
return EXIT_FAILURE;
}
if (!sysname) {
log_error("Requires pair of subsystem and sysname for specifying backlight device.");
return EXIT_FAILURE;
}
if (!ss) {
log_oom();
return EXIT_FAILURE;
}
sysname++;
return EXIT_FAILURE;
}
errno = 0;
if (!device) {
if (errno != 0)
else
log_oom();
return EXIT_FAILURE;
}
if (!escaped_ss) {
log_oom();
return EXIT_FAILURE;
}
if (!escaped_sysname) {
log_oom();
return EXIT_FAILURE;
}
if (path_id) {
if (!escaped_path_id) {
log_oom();
return EXIT_FAILURE;
}
saved = strjoin("/var/lib/systemd/backlight/", escaped_path_id, ":", escaped_ss, ":", escaped_sysname, NULL);
} else
if (!saved) {
log_oom();
return EXIT_FAILURE;
}
/* If there are multiple conflicting backlight devices, then
* their probing at boot-time might happen in any order. This
* means the validity checking of the device then is not
* reliable, since it might not see other devices conflicting
* with a specific backlight. To deal with this, we will
* actively delete backlight state files at shutdown (where
* device probing should be complete), so that the validity
* check at boot time doesn't have to be reliable. */
return EXIT_SUCCESS;
if (r < 0) {
if (r == -ENOENT)
return EXIT_SUCCESS;
return EXIT_FAILURE;
}
if (r < 0) {
return EXIT_FAILURE;
}
const char *value;
return EXIT_SUCCESS;
}
if (!value) {
return EXIT_FAILURE;
}
if (r < 0) {
return EXIT_FAILURE;
}
} else {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}