Hello.
I'm trying to get a list of acpi batteries and ac devices on the
notebook.
I see them in /devices/pseudo:
$ ls -ld /devices/pseudo/acpi_drv\@0*
drwxr-xr-x 2 root sys 2 Dec 23 2014 /devices/pseudo/acpi_drv@0
crw-rw-rw- 1 root sys 3, 512 Dec 23 11:32
/devices/pseudo/acpi_drv@0:ac0
crw-rw-rw- 1 root sys 3, 256 Dec 23 11:32
/devices/pseudo/acpi_drv@0:battery0
crw-rw-rw- 1 root sys 3, 1280 Dec 23 11:34
/devices/pseudo/acpi_drv@0:hotkey
But when I try to do it in C, I fail. The attached program shows only
In acpi_drv
/pseudo/acpi_drv@0
is_laptop=0
(no /dev/pseudo/acpi_drv@0:* as I would expected). What am I doing
wrong?
--
System Administrator of Southern Federal University Computer Center
------------------------------------------
illumos-discuss
Archives:
https://illumos.topicbox.com/groups/discuss/discussions/T736693effb971e17-Me2954a0ef0fe150583bb99e7
Powered by Topicbox: https://topicbox.com
#include <stdio.h>
#include <libdevinfo.h>
#include <limits.h>
#include <fcntl.h>
#include <sys/acpi_drv.h>
#define DEVFS_PREFIX "/devices"
static int
find_acpi_drv(di_node_t node, void *arg)
{
int *pfound;
pfound = (int *) arg;
*pfound = 0;
char * dn=di_driver_name(node);
if (dn && !strcmp("acpi_drv",dn)) {
di_devlink_handle_t devlink_hdl;
di_minor_t minor;
printf("In acpi_drv\n");
puts(di_devfs_path(node));
if ((devlink_hdl = di_devlink_init(NULL, 0)) == NULL) {
printf("Can't init devlink_hdl");
return DI_WALK_CONTINUE;
}
minor = DI_MINOR_NIL;
while ((minor = di_minor_next(node, minor)) != DI_MINOR_NIL) {
char *dp;
char fdp[PATH_MAX];
int fd;
int pow;
puts("In minor loop");
dp=di_devfs_path(node);
if (!dp) {
printf("Couldn't get path for acpi_drv device");
di_devlink_fini(&devlink_hdl);
continue;
}
sprintf(fdp,"%s%s:%s",DEVFS_PREFIX,dp,di_minor_name(minor));
printf("fdp=%s\n", fdp);
di_devfs_path_free(dp);
}
di_devlink_fini(&devlink_hdl);
}
return DI_WALK_CONTINUE;
}
int
up_native_is_laptop()
{
int found;
di_node_t root_node;
errno = 0;
if((root_node = di_init("/", DINFOSUBTREE)) == DI_NODE_NIL) {
perror("di_init() failed");
return 0;
}
di_walk_node(root_node, DI_WALK_CLDFIRST, &found, find_acpi_drv);
di_fini(root_node);
return found;
}
int
main()
{
printf("is_laptop=%d\n", up_native_is_laptop());
return 0;
}