ソースを参照

Fix wrong behavior of 'light_controllerAccessible'

This function was:
- Reading values from the controller
- Checking write permission even when we just want reading values
- Checking the mincap file instead of the actual controller

The last one is also true for other functions using
'light_getBrightness'.
This commit fixes that.
Abdullah ibn Nadjo 6 年 前
コミット
9f9d6ae447
共有1 個のファイルを変更した59 個の追加20 個の削除を含む
  1. 59
    20
      src/light.c

+ 59
- 20
src/light.c ファイルの表示

@@ -569,14 +569,34 @@ LIGHT_BOOL light_genPath(char const *controller, LIGHT_TARGET type, char **buffe
569 569
   return TRUE;
570 570
 }
571 571
 
572
+LIGHT_BOOL light_getBrightnessPath(char const *controller, char **path)
573
+{
574
+  LIGHT_TARGET target;
575
+
576
+  if(light_Configuration.target == LIGHT_MIN_CAP)
577
+  {
578
+    target = LIGHT_BRIGHTNESS;
579
+  }
580
+  else
581
+  {
582
+    target = light_Configuration.target;
583
+  }
584
+
585
+  if(!light_genPath(controller, target, path))
586
+  {
587
+    LIGHT_ERR("could not generate path to brightness file");
588
+    return FALSE;
589
+  }
590
+  return TRUE;
591
+}
592
+
572 593
 LIGHT_BOOL light_getBrightness(char const *controller, unsigned long *v)
573 594
 {
574 595
   char *brightnessPath = NULL;
575 596
   LIGHT_BOOL readVal = FALSE;
576 597
 
577
-  if(!light_genPath(controller, light_Configuration.target, &brightnessPath))
598
+  if(!light_getBrightnessPath(controller, &brightnessPath))
578 599
   {
579
-    LIGHT_ERR("could not generate path to brightness file");
580 600
     return FALSE;
581 601
   }
582 602
   LIGHT_NOTE(brightnessPath)
@@ -592,12 +612,10 @@ LIGHT_BOOL light_getBrightness(char const *controller, unsigned long *v)
592 612
   return TRUE;
593 613
 }
594 614
 
595
-LIGHT_BOOL light_getMaxBrightness(char const *controller, unsigned long *v)
615
+LIGHT_BOOL light_getMaxBrightnessPath(char const *controller, char **path)
596 616
 {
597
-  char *maxPath;
598
-  LIGHT_BOOL readVal = FALSE;
599
-
600 617
   LIGHT_TARGET target;
618
+
601 619
   if(light_Configuration.target == LIGHT_KEYBOARD)
602 620
   {
603 621
     target = LIGHT_KEYBOARD_MAX_BRIGHTNESS;
@@ -607,12 +625,23 @@ LIGHT_BOOL light_getMaxBrightness(char const *controller, unsigned long *v)
607 625
     target = LIGHT_MAX_BRIGHTNESS;
608 626
   }
609 627
 
610
-  if(!light_genPath(controller, target, &maxPath))
628
+  if(!light_genPath(controller, target, path))
611 629
   {
612 630
     LIGHT_ERR("could not generate path to maximum brightness file");
613 631
     return FALSE;
614 632
   }
633
+  return TRUE;
634
+}
615 635
 
636
+LIGHT_BOOL light_getMaxBrightness(char const *controller, unsigned long *v)
637
+{
638
+  char *maxPath = NULL;
639
+  LIGHT_BOOL readVal = FALSE;
640
+
641
+  if (!light_getMaxBrightnessPath(controller, &maxPath))
642
+  {
643
+    return FALSE;
644
+  }
616 645
   readVal = light_readULong(maxPath , v);
617 646
   free(maxPath);
618 647
 
@@ -656,34 +685,44 @@ LIGHT_BOOL light_setBrightness(char const *controller, unsigned long v)
656 685
 LIGHT_BOOL light_controllerAccessible(char const *controller)
657 686
 {
658 687
   char *brightnessPath = NULL;
659
-  unsigned long dummy;
660 688
 
661
-  if(!light_getBrightness(controller, &dummy))
689
+  /* On auto mode, we need to check if we can read the max brightness value
690
+     of the controller for later computation */
691
+  if(light_Configuration.controllerMode == LIGHT_AUTO ||
692
+     light_Configuration.target == LIGHT_MAX_BRIGHTNESS)
662 693
   {
663
-    LIGHT_NOTE(controller)
664
-    LIGHT_WARN("could not read controllers brightness file, so controller is not accessible")
665
-    return FALSE;
666
-  }
667
-
668
-  if(!light_getMaxBrightness(controller, &dummy))
669
-  {
670
-    LIGHT_WARN("could not read controller max brightness file, so controller is not accessible")
671
-    return FALSE;
694
+    if(!light_getMaxBrightnessPath(controller, &brightnessPath))
695
+    {
696
+      return FALSE;
697
+    }
698
+    if(!light_isReadable(brightnessPath))
699
+    {
700
+      LIGHT_WARN("could not open controller max brightness file for reading, so controller is not accessible");
701
+      free(brightnessPath);
702
+      return FALSE;
703
+    }
704
+    free(brightnessPath);
672 705
   }
673 706
 
674
-  if(!light_genPath(controller, light_Configuration.target, &brightnessPath))
707
+  if(!light_getBrightnessPath(controller, &brightnessPath))
675 708
   {
676
-    LIGHT_ERR("could not generate path to brightness file");
677 709
     return FALSE;
678 710
   }
679 711
 
680 712
   if(light_Configuration.operationMode != LIGHT_GET &&
713
+     light_Configuration.target != LIGHT_MIN_CAP &&
681 714
      !light_isWritable(brightnessPath))
682 715
   {
683 716
     LIGHT_WARN("could not open controller brightness file for writing, so controller is not accessible");
684 717
     free(brightnessPath);
685 718
     return FALSE;
686 719
   }
720
+  else if (!light_isReadable(brightnessPath))
721
+  {
722
+    LIGHT_WARN("could not open controller brightness file for reading, so controller is not accessible");
723
+    free(brightnessPath);
724
+    return FALSE;
725
+  }
687 726
 
688 727
   free(brightnessPath);
689 728
   return TRUE;