| Commit message (Collapse) | Author | Age |
... | |
| |
|
| |
|
|
|
| |
Dead link on AUR.
|
| |
|
|
|
|
|
|
|
|
|
|
| |
Restore device data only after successful read
Do not set curr_brightness to max after an unsuccessful restore
Fix ensure_dir
Do not ignore ignore value of fread (fixes #6)
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|
|
| |
Add static specifier to functions
|
| |
|
| |
|
|\
| |
| | |
Various fixes
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Print an error message if the run directory or the device-class
subdirectory exists but is not a directory.
Before:
% rm -rf /tmp/brightnessctl
% touch /tmp/brightnessctl
% brightnessctl -s
Device 'intel_backlight' of class 'backlight':
Current brightness: 1000 (20%)
Max brightness: 4794
% file /tmp/brightnessctl
/tmp/brightnessctl: empty
%
After:
% brightnessctl -s
Error saving device data: Not a directory
Could not save data for device 'intel_backlight'.
Device 'intel_backlight' of class 'backlight':
Current brightness: 1000 (20%)
Max brightness: 4794
%
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Make several changes to error handling:
• Check for negative values from sprintf, and treat them as errors.
• Check for errors from fscanf both by comparing its return value against
EOF and by checking ferror.
• Avoiding calling perror with errno set to -1. Either set a meaningful
value, such as EINVAL, or use fprintf if errno cannot be expected to
have a meaningful value.
• Instead of re-using errno for internal error handling, use a new variable
to indicate errors where it makes sense to do so.
• In read_device, print more specific error messages if we fail to read
a device's current or max brightness, and print an error message
immediately if a read fails, instead of only maybe at the end of
read_device.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Do not write a trailing NUL byte to the state file.
Before:
% brightnessctl -ms
intel_backlight,backlight,1000,20%,4794
% od -t x1z /tmp/brightnessctl/backlight/intel_backlight
0000000 31 30 30 30 00 >1000.<
0000005
%
After:
% brightnessctl -ms
intel_backlight,backlight,1000,20%,4794
% od -t x1z /tmp/brightnessctl/backlight/intel_backlight
0000000 31 30 30 30 >1000<
0000004
%
Note that restore still works:
% brightnessctl -mr
intel_backlight,backlight,1000,20%,4794
%
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
When creating the /tmp/brightnessctl directory or its subdirectories, clear
errno before calling mkdir, and call stat a second time after mkdir.
Previously, errno was not cleared, so even if the error was handled (by
creating the missing directory with mkdir), subsequent error handling code
read the old errno value from the failed stat call and printed an error
message.
Additionally, because we did not call stat again after calling mkdir, the
stat buffer had outdated information, and so S_ISDIR returned a false
negative.
As a result of these defects, invoking brightnessctl -s when
/tmp/brightnessctl did not exist would create /tmp/brightnessctl and fail.
Invoking brightnessctl -s a second time would create
/tmp/brightnessctl/backlight and fail. Invoking the command a third time
would succeed and write the state file under /tmp/brightnessctl/backlight/.
After this commit, brightnessctl -s succeeds the first time.
|
| |
| |
| |
| |
| |
| | |
The -r/--restore flag requires root, the same as the set verb does, so
print an error message if either the flag or the verb is used without
running as root.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
If no device is specified with the --device flag, set dev_name to the id of
the first device.
Before, if the --device flag is not used to specify the default device, the
dev pointer was set to first device found (see commit
c9140d1e5070dae2746d3b70c0390075bd5380f6), but the dev_name pointer was
left set to NULL. As a result, some error messages did not print the name
of the default device:
% brightnessctl -s
Error saving device data: No such file or directory
Could not save data for device '(null)'.
Device 'intel_backlight' of class 'backlight':
Current brightness: 1000 (20%)
Max brightness: 4794
% brightnessctl -s -m
Error saving device data: No such file or directory
Could not save data for device '(null)'.
intel_backlight,backlight,1000,20%,4794
%
After this commit, all error messages have the correct name:
% brightnessctl -s
Error saving device data: No such file or directory
Could not save data for device 'intel_backlight'.
Device 'intel_backlight' of class 'backlight':
Current brightness: 1000 (20%)
Max brightness: 4794
% brightnessctl -s -m
Error saving device data: No such file or directory
Could not save data for device 'intel_backlight'.
intel_backlight,backlight,1000,20%,4794
%
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Account for separators when computing the buffer size in cat_width in order
to avoid overflowing the buffer.
Previously, cat_width only accounted for the lengths of the strings being
catenated, but not the separators, which could result in buffer overflows.
For example, trace the execution of the following invocation of cat_with:
char s[5] = "xxxx";
cat_with(' ', s, s, s, s, s, s, s, s);
cat_with initialises size and length and allocates an initial buffer:
size = 32; /* size = 32 */
length = 0; /* length = 0 */
buf = calloc(1, size + 1); /* allocated 33 bytes for buf */
The first iteration of the main loop in cat_with catenates the first string
and a separator but fails to account for the separator in length:
length += strlen(curr); /* length = 4 */
while (length + 2 > size) /* 4 + 2 > 32 is false */
strcat(buf, curr); /* written 5 bytes to buf */
strcat(buf, split); /* written 6 bytes to buf */
Now we have written the string "xxxx " (6 bytes including NUL) to buf, but
length only counts the 4 bytes "xxxx" (excluding NUL).
In successive iterations, the discrepancy between the value in length and
the actual length of the string in the buffer grows:
length += strlen(curr); /* length = 8 */
while (length + 2 > size) /* 8 + 2 > 32 is false */
strcat(buf, curr); /* written 10 bytes to buf */
strcat(buf, split); /* written 11 bytes to buf */
Now we have written "xxxx xxxx " (11 bytes incl. NUL).
length += strlen(curr); /* length = 12 */
while (length + 2 > size) /* 12 + 2 > 32 is false */
strcat(buf, curr); /* written 15 bytes to buf */
strcat(buf, split); /* written 16 bytes to buf */
Now we have written "xxxx xxxx xxxx " (16 bytes incl. NUL).
length += strlen(curr); /* length = 16 */
while (length + 2 > size) /* 16 + 2 > 32 is false */
strcat(buf, curr); /* written 20 bytes to buf */
strcat(buf, split); /* written 21 bytes to buf */
Now we have written "xxxx xxxx xxxx xxxx " (21 bytes incl. NUL).
length += strlen(curr); /* length = 20 */
while (length + 2 > size) /* 20 + 2 > 32 is false */
strcat(buf, curr); /* written 25 bytes to buf */
strcat(buf, split); /* written 26 bytes to buf */
Now we have written "xxxx xxxx xxxx xxxx xxxx " (26 bytes incl. NUL).
length += strlen(curr); /* length = 24 */
while (length + 2 > size) /* 24 + 2 > 32 is false */
strcat(buf, curr); /* written 30 bytes to buf */
strcat(buf, split); /* written 31 bytes to buf */
Now we have written "xxxx xxxx xxxx xxxx xxxx xxxx " (31 bytes incl. NUL).
Eventually, the string can grow beyond the buffer before length grows large
enough to cause a re-allocation:
length += strlen(curr); /* length = 28 */
while (length + 2 > size) /* 28 + 2 > 32 is false */
strcat(buf, curr); /* written 35 bytes to buf */
strcat(buf, split); /* written 36 bytes to buf */
Note that we have not increased size or re-allocated the buffer, and so we
have written "xxxx xxxx xxxx xxxx xxxx xxxx xxxx" (35 bytes incl. NUL) to
a buffer for which we have allocated only 33 bytes.
|
| |
|
| |
|
| |
|
|\
| |
| |
| | |
Closes: #2
|
| | |
|
|\|
| |
| | |
Improve readme and help
|
|/ |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|