hmc
Active Member
Hi guys,
I need some advice from you please!
I need to read the integer value (0 .. 255) from
/sys/class/leds/pandora::keypad_bl/brightness
into a variable in my C code (the keyboard light configbutton plugin).
How can I do this properly?
I have tried two approaches (the target variable is kbl_status)
if ((fp = fopen("/sys/class/leds/pandora::keypad_bl/brightness", "r")) == NULL)
{
kbl_status = 0;
} else
{
fscanf(fp,"%d",&kbl_status);
fclose(fp);
}
This approach fails with:
What does this mean? %-)
The other approach is: I have a shell script, that returns the status value.
Now I want to call this shell script from teh Plugin code:
kbl_status = system("/usr/pandora/scripts/op_kbd_light.sh");
This call gives me a segfault, as soon as the plugin is loaded by configbutton. (Verified by replacing this line by "kbl_status=0", which gives no segfault).However, in the console output of configbutton I see that the shell script is actually executed.
I also verified that the script really returns the correct value:
$ /usr/pandora/scripts/op_kbd_light.sh
Keyboard Light On, Brightness: 255
$ echo $?
255
$
I'd greatly appreaciate any hint
in case it's relevant or you're interested: I have attached the entire plugin's code. (remove ".txt" extension and then untar)
Thanks!
kblight_plugin.tgz.txt
I need some advice from you please!
I need to read the integer value (0 .. 255) from
/sys/class/leds/pandora::keypad_bl/brightness
into a variable in my C code (the keyboard light configbutton plugin).
How can I do this properly?
I have tried two approaches (the target variable is kbl_status)
if ((fp = fopen("/sys/class/leds/pandora::keypad_bl/brightness", "r")) == NULL)
{
kbl_status = 0;
} else
{
fscanf(fp,"%d",&kbl_status);
fclose(fp);
}
This approach fails with:
Code:
*** glibc detected *** configbutton: double free or corruption (top): 0x00088ac8 ***
Aborted
The other approach is: I have a shell script, that returns the status value.
Now I want to call this shell script from teh Plugin code:
kbl_status = system("/usr/pandora/scripts/op_kbd_light.sh");
This call gives me a segfault, as soon as the plugin is loaded by configbutton. (Verified by replacing this line by "kbl_status=0", which gives no segfault).However, in the console output of configbutton I see that the shell script is actually executed.
I also verified that the script really returns the correct value:
$ /usr/pandora/scripts/op_kbd_light.sh
Keyboard Light On, Brightness: 255
$ echo $?
255
$
I'd greatly appreaciate any hint
in case it's relevant or you're interested: I have attached the entire plugin's code. (remove ".txt" extension and then untar)
Thanks!
kblight_plugin.tgz.txt
Attachments
Last edited by a moderator: