[gnome-settings-daemon/benzea/hide-realpath-errors: 2/2] power: Do not print an error for failures from realpath
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/benzea/hide-realpath-errors: 2/2] power: Do not print an error for failures from realpath
- Date: Tue, 30 Nov 2021 10:41:59 +0000 (UTC)
commit 1e8b4be01e42b076ad491d522d6e98b4fd4b5e57
Author: Benjamin Berg <bberg redhat com>
Date: Tue Nov 30 11:35:49 2021 +0100
power: Do not print an error for failures from realpath
Doing so leaks information about whether a file/directory exists even if
it is outside of the /sys/class/backlight directory.
Closes: #634
plugins/power/gsd-backlight-helper.c | 12 ++++--------
1 file 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");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]