summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/power/gsd-backlight-helper.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/plugins/power/gsd-backlight-helper.c b/plugins/power/gsd-backlight-helper.c
index c370c791..f0fbbb59 100644
--- a/plugins/power/gsd-backlight-helper.c
+++ b/plugins/power/gsd-backlight-helper.c
@@ -85,13 +85,6 @@ main (int argc, char *argv[])
goto done;
}
- device = realpath (argv[1], NULL);
- if (device == NULL) {
- fprintf (stderr, "Error: Could not canonicalize given path (%d: %s)\n", errno, strerror (errno));
- result = GSD_BACKLIGHT_HELPER_EXIT_CODE_FAILED;
- 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));
@@ -99,6 +92,9 @@ main (int argc, char *argv[])
goto done;
}
+ /* May be NULL if the path cannot be resolved */
+ device = realpath (argv[1], NULL);
+
while ((ep = readdir (dp))) {
char *path;
@@ -108,7 +104,7 @@ main (int argc, char *argv[])
/* Leave room for "/brightness" */
snprintf (tmp, sizeof(tmp) - 11, "/sys/class/backlight/%s", ep->d_name);
path = realpath (tmp, NULL);
- if (strcmp (path, device) == 0) {
+ if (path && device && strcmp (path, device) == 0) {
free (path);
strcat (tmp, "/brightness");