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