backlight: handle loading truncated file

I had accidentally filled my /var partition. This caused backlight to fail to
start even with disk space, because the brightness files were truncated to zero
size:

systemd-backlight[624]: acpi_video0: Failed to parse brightness "": Invalid argument
systemd-backlight[624]: acpi_video0: Failed to write system 'brightness' attribute: No such device or address
systemd[1]: systemd-backlight@backlight:acpi_video0.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: systemd-backlight@backlight:acpi_video0.service: Failed with result 'exit-code'.
systemd[1]: Failed to start Load/Save Screen Backlight Brightness of backlight:acpi_video0.

Handle a truncated file like non-existent file.
This commit is contained in:
Topi Miettinen 2019-01-31 19:07:06 +02:00
parent d6062e3b4f
commit cbed254f96

View file

@ -379,7 +379,7 @@ static int run(int argc, char *argv[]) {
clamp = shall_clamp(device);
r = read_one_line_file(saved, &value);
if (r == -ENOENT) {
if (IN_SET(r, -ENOENT, 0)) {
const char *curval;
/* Fallback to clamping current brightness or exit early if