diff --git a/src/cmd.c b/src/cmd.c index 2a31421..ca847a4 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -155,7 +155,7 @@ struct arg_values process_cmd_args(int argc, char** argv){ //Check for switches if(CHECK_OPTION(GET, argv[i])){ - curr->operation |= OP_GET; + curr->operation = OP_GET; continue; }else if(CHECK_OPTION(FADE, argv[i])){ diff --git a/src/rexbacklight.c b/src/rexbacklight.c index eaa115a..1b8fba9 100644 --- a/src/rexbacklight.c +++ b/src/rexbacklight.c @@ -264,7 +264,8 @@ void do_list(struct arg_values* args){ } //Run requested operation on a per device basis -void run_device_operations(struct arg_values* a){ +int run_device_operations(struct arg_values* a){ + int changes = 0; for(a = a->next;a;a = a->next){ switch(a->operation){ case OP_LIST: @@ -284,10 +285,12 @@ void run_device_operations(struct arg_values* a){ case OP_SET: if(prep_offset(a)) break; + ++changes; fade_out(a); break; }; } + return changes; } //If a global operation is requested, run this to fill arg with all devices, each with the global operation @@ -312,6 +315,7 @@ int main(int argc, char** argv){ struct arg_values args; //A linked list of devices and the requested settings. struct string_array device_names; //List of all led/backlight devices in sysfs. + int should_save = 0; args = process_cmd_args(argc, argv); if(args.operation == OP_USAGE){ @@ -360,9 +364,14 @@ int main(int argc, char** argv){ if(!args.next){ populate_args(&args, &device_names); } - run_device_operations(&args); + should_save = (run_device_operations(&args) > 0); #ifdef ENABLE_RESTORE_FILE - save_restore_file(&device_names, &args); //performs cleanup on args + if(should_save) + save_restore_file(&device_names, &args); //performs cleanup on args + else + free_cmd_args(&args); +#else + free_cmd_args(&args); #endif free_string_array(&device_names);