Fix error output on invalid permissions to write to brightness file
This commit is contained in:
parent
50412e0006
commit
61e36bed19
@ -63,6 +63,15 @@ const char* max_brightness_file(void){return "max_brightness";}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//create a copy of a string and append a '/' character to the end
|
||||
char* add_slash_to(const char* name, size_t namelen){
|
||||
char* newname = malloc(namelen + 2);
|
||||
memcpy(newname, name, namelen);
|
||||
newname[namelen++] = '/';
|
||||
newname[namelen] = 0;
|
||||
return newname;
|
||||
}
|
||||
|
||||
//Get a list of led/backlight devices in sysfs
|
||||
struct string_array get_device_sources(void){
|
||||
DIR* fd;
|
||||
@ -162,6 +171,12 @@ void sleep_for(double time){
|
||||
nanosleep(&ts, NULL);
|
||||
}
|
||||
|
||||
void return_to_root_dir(void){
|
||||
if(chdir(device_dir())){
|
||||
io_error(IO_ERROR_OPEN, IO_ERROR_DIR, device_dir());
|
||||
return_value = RETVAL_INVALID_DIR;
|
||||
}
|
||||
}
|
||||
//update brightness incrementally over requested millisecond time interval
|
||||
void fade_out(struct arg_values* arg){
|
||||
FILE* fd;
|
||||
@ -177,8 +192,11 @@ void fade_out(struct arg_values* arg){
|
||||
start = get_time();
|
||||
fd = fopen(brightness_file(), "w+");
|
||||
if(!fd){
|
||||
io_error_3(IO_ERROR_OPEN, IO_ERROR_FILE, device_dir(), arg->device, brightness_file());
|
||||
char* devname = add_slash_to(arg->device, strlen(arg->device));
|
||||
io_error_3(IO_ERROR_OPEN, IO_ERROR_FILE, device_dir(), devname, brightness_file());
|
||||
return_value = RETVAL_INVALID_FILE;
|
||||
free(devname);
|
||||
return_to_root_dir();
|
||||
return;
|
||||
}
|
||||
fprintf(fd, "%d", (int)value);
|
||||
@ -201,18 +219,17 @@ void fade_out(struct arg_values* arg){
|
||||
}
|
||||
fd = fopen(brightness_file(), "w+");
|
||||
if(!fd){
|
||||
io_error_3(IO_ERROR_OPEN, IO_ERROR_FILE, device_dir(), arg->device, brightness_file());
|
||||
char* devname = add_slash_to(arg->device, strlen(arg->device));
|
||||
io_error_3(IO_ERROR_OPEN, IO_ERROR_FILE, device_dir(), devname, brightness_file());
|
||||
return_value = RETVAL_INVALID_FILE;
|
||||
free(devname);
|
||||
return_to_root_dir();
|
||||
return;
|
||||
}
|
||||
fprintf(fd, "%d", arg->act_delta);
|
||||
|
||||
fclose(fd);
|
||||
if(chdir(device_dir())){
|
||||
io_error(IO_ERROR_OPEN, IO_ERROR_DIR, device_dir());
|
||||
return_value = RETVAL_INVALID_DIR;
|
||||
return;
|
||||
}
|
||||
return_to_root_dir();
|
||||
}
|
||||
|
||||
int prep_offset(struct arg_values* args){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user