Re: trying to sysctl(3) a char value

2010-11-24 Thread David DEMELIER
2010/11/24 Dan Nelson :
> In the last episode (Nov 24), David DEMELIER said:
>> Since I cannot adjust the brightness on my HP Probook because it sucks
>> I'm writing a small script that can be use instead. I need to sysctl
>> the following sysctl variables :
>>
>> hw.acpi.video.lcd0.brightness
>> hw.acpi.video.lcd0.levels
>>
>> the -brightness one is easy since it's an integer, but the levels is
>> possibly a char :
>>
>> mark...@melon ~ $ sysctl hw.acpi.video.lcd0.brightness
>> hw.acpi.video.lcd0.brightness: 90
>> mark...@melon ~ $ sysctl hw.acpi.video.lcd0.levels
>> hw.acpi.video.lcd0.levels: 100 50 0 5 10 15 20 25 30 33 36 40 43 46 50 55 60 
>> 65 70 75 80 83 86 90 93 96 100
>
> Looking at the source, that sysctl definition is CTLTYPE_OPAQUE with a
> display format of "I", which means that it's just an array of integers.
> Print each one in a loop.  You can also take a look at
> /usr/src/sbin/sysctl/sysctl.c to see how it printed the numbers.
>
> --
>        Dan Nelson
>        dnel...@allantgroup.com
>

Thank you, it works !

-- 
Demelier David
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: trying to sysctl(3) a char value

2010-11-24 Thread Dan Nelson
In the last episode (Nov 24), David DEMELIER said:
> Since I cannot adjust the brightness on my HP Probook because it sucks
> I'm writing a small script that can be use instead. I need to sysctl
> the following sysctl variables :
> 
> hw.acpi.video.lcd0.brightness
> hw.acpi.video.lcd0.levels
> 
> the -brightness one is easy since it's an integer, but the levels is
> possibly a char :
> 
> mark...@melon ~ $ sysctl hw.acpi.video.lcd0.brightness
> hw.acpi.video.lcd0.brightness: 90
> mark...@melon ~ $ sysctl hw.acpi.video.lcd0.levels
> hw.acpi.video.lcd0.levels: 100 50 0 5 10 15 20 25 30 33 36 40 43 46 50 55 60 
> 65 70 75 80 83 86 90 93 96 100

Looking at the source, that sysctl definition is CTLTYPE_OPAQUE with a
display format of "I", which means that it's just an array of integers. 
Print each one in a loop.  You can also take a look at
/usr/src/sbin/sysctl/sysctl.c to see how it printed the numbers.

-- 
Dan Nelson
dnel...@allantgroup.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


trying to sysctl(3) a char value

2010-11-24 Thread David DEMELIER
Hello,

Since I cannot adjust the brightness on my HP Probook because it sucks
I'm writing a small script that can be use instead. I need to sysctl
the following sysctl variables :

hw.acpi.video.lcd0.brightness
hw.acpi.video.lcd0.levels

the -brightness one is easy since it's an integer, but the levels is
possibly a char :

mark...@melon ~ $ sysctl hw.acpi.video.lcd0.brightness
hw.acpi.video.lcd0.brightness: 90
mark...@melon ~ $ sysctl hw.acpi.video.lcd0.levels
hw.acpi.video.lcd0.levels: 100 50 0 5 10 15 20 25 30 33 36 40 43 46 50
55 60 65 70 75 80 83 86 90 93 96 100

How can I store the content of hw.acpi.video.lcd0.levels? This small
code doesn't work :

#include 
#include 
#include 
#include 

int
main(int argc, char *argv[])
{
char buf[128];
size_t len;

len = sizeof (buf);

if (sysctlbyname("hw.acpi.video.lcd0.levels", &buf, &len, NULL, 0) == 
-1) {
perror("sysctl");
return -1;
}

printf("levels = %s\n", buf);
}

mark...@melon ~ $ ./a.out
levels = d

Kind regards,

-- 
Demelier David
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"