1d2ec54f7Sphitran /*************************************************************************** 2d2ec54f7Sphitran * 3d2ec54f7Sphitran * probe-acpi.c : Probe for ACPI device information 4d2ec54f7Sphitran * 5*2d6b5ea7SGuoli Shu * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 6d2ec54f7Sphitran * Use is subject to license terms. 7d2ec54f7Sphitran * 8d2ec54f7Sphitran * Licensed under the Academic Free License version 2.1 9d2ec54f7Sphitran * 10d2ec54f7Sphitran **************************************************************************/ 11d2ec54f7Sphitran 12d2ec54f7Sphitran #ifdef HAVE_CONFIG_H 13d2ec54f7Sphitran #include <config.h> 14d2ec54f7Sphitran #endif 15d2ec54f7Sphitran 16d2ec54f7Sphitran #include <errno.h> 17d2ec54f7Sphitran #include <string.h> 18d2ec54f7Sphitran #include <strings.h> 19d2ec54f7Sphitran #include <ctype.h> 20d2ec54f7Sphitran #include <stdlib.h> 21d2ec54f7Sphitran #include <stdio.h> 22d2ec54f7Sphitran #include <sys/ioctl.h> 23d2ec54f7Sphitran #include <fcntl.h> 24d2ec54f7Sphitran #include <unistd.h> 25d2ec54f7Sphitran #include <glib.h> 26d2ec54f7Sphitran 27d2ec54f7Sphitran #include <libhal.h> 28d2ec54f7Sphitran #include <logger.h> 29d2ec54f7Sphitran #include "../utils/acpi.h" 30d2ec54f7Sphitran 31d2ec54f7Sphitran int 32d2ec54f7Sphitran main(int argc, char *argv[]) 33d2ec54f7Sphitran { 34d2ec54f7Sphitran int ret = 1; 35d2ec54f7Sphitran int fd = -1; 36d2ec54f7Sphitran char *udi; 37d2ec54f7Sphitran char device_file[HAL_PATH_MAX] = "/devices"; 38d2ec54f7Sphitran char *devfs_path; 39d2ec54f7Sphitran LibHalContext *ctx = NULL; 40d2ec54f7Sphitran DBusError error; 41d2ec54f7Sphitran 42d2ec54f7Sphitran if ((udi = getenv("UDI")) == NULL) 43d2ec54f7Sphitran goto out; 44d2ec54f7Sphitran if ((devfs_path = getenv("HAL_PROP_SOLARIS_DEVFS_PATH")) == NULL) 45d2ec54f7Sphitran goto out; 46d2ec54f7Sphitran strlcat(device_file, devfs_path, HAL_PATH_MAX); 47d2ec54f7Sphitran 48d2ec54f7Sphitran setup_logger(); 49d2ec54f7Sphitran 50d2ec54f7Sphitran dbus_error_init(&error); 51d2ec54f7Sphitran if ((ctx = libhal_ctx_init_direct(&error)) == NULL) 52d2ec54f7Sphitran goto out; 53d2ec54f7Sphitran 54d2ec54f7Sphitran HAL_DEBUG(("Doing probe-acpi for %s (udi=%s)", 55d2ec54f7Sphitran device_file, udi)); 56d2ec54f7Sphitran 57d2ec54f7Sphitran if ((fd = open(device_file, O_RDONLY | O_NONBLOCK)) < 0) { 58d2ec54f7Sphitran HAL_DEBUG(("Cannot open %s: %s", device_file, strerror(errno))); 59d2ec54f7Sphitran goto out; 60d2ec54f7Sphitran } 61d2ec54f7Sphitran if (strstr(udi, "_ac")) { 62d2ec54f7Sphitran ac_adapter_update(ctx, udi, fd); 63d2ec54f7Sphitran } else if (strstr(udi, "_battery")) { 64d2ec54f7Sphitran battery_update(ctx, udi, fd); 65d2ec54f7Sphitran } else if (strstr(udi, "_lid")) { 66d2ec54f7Sphitran lid_update(ctx, udi, fd); 67*2d6b5ea7SGuoli Shu } else if (strstr(udi, "_hotkey")) { 68d2ec54f7Sphitran laptop_panel_update(ctx, udi, fd); 69d2ec54f7Sphitran } 70d2ec54f7Sphitran 71d2ec54f7Sphitran ret = 0; 72d2ec54f7Sphitran 73d2ec54f7Sphitran out: 74d2ec54f7Sphitran if (fd >= 0) { 75d2ec54f7Sphitran close(fd); 76d2ec54f7Sphitran } 77d2ec54f7Sphitran 78d2ec54f7Sphitran if (ctx != NULL) { 79d2ec54f7Sphitran libhal_ctx_shutdown(ctx, &error); 80d2ec54f7Sphitran libhal_ctx_free(ctx); 81d2ec54f7Sphitran if (dbus_error_is_set(&error)) { 82d2ec54f7Sphitran dbus_error_free(&error); 83d2ec54f7Sphitran } 84d2ec54f7Sphitran } 85d2ec54f7Sphitran 86d2ec54f7Sphitran return (ret); 87d2ec54f7Sphitran } 88