diff options
author | Miciah Masters <miciah.masters@gmail.com> | 2017-01-15 02:18:49 -0500 |
---|---|---|
committer | Miciah Dashiel Butler Masters <mmasters@redhat.com> | 2017-01-15 02:31:30 -0500 |
commit | 4aa6d8fff1e1e034c1a73d02d3515df36b93bbaf (patch) | |
tree | 4225395216194fde1ee4569b0d3d317d5f3d2c64 /brightnessctl.c | |
parent | 0cedae398a108e287edb440ddcf877fb58bcb272 (diff) |
Print error if run dir is not a directory
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
%
Diffstat (limited to 'brightnessctl.c')
-rw-r--r-- | brightnessctl.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/brightnessctl.c b/brightnessctl.c index 55352d2..cbfe410 100644 --- a/brightnessctl.c +++ b/brightnessctl.c @@ -417,8 +417,10 @@ int save_device_data(struct device *dev) { if (stat(c_path, &sb)) goto fail; } - if (!S_ISDIR(sb.st_mode)) + if (!S_ISDIR(sb.st_mode)) { + errno = ENOTDIR; goto fail; + } if (!(fp = fopen(d_path, "w"))) goto fail; if (fwrite(c, 1, s, fp) < s) { @@ -472,7 +474,11 @@ static int ensure_run_dir() { if (stat(run_dir, &sb)) return 0; } - return S_ISDIR(sb.st_mode); + if (!S_ISDIR(sb.st_mode)) { + errno = ENOTDIR; + return 0; + } + return 1; } char *_cat_with(char c, ...) { |