xref: /illumos-gate/usr/src/cmd/hal/addons/acpi/addon-acpi.c (revision 59d65d3175825093531e82f44269d948ed510a00)
1 /***************************************************************************
2  *
3  * addon-acpi.c : Poll battery and AC adapter devices and update
4  *                   properties
5  *
6  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
7  * Use is subject to license terms.
8  *
9  * Licensed under the Academic Free License version 2.1
10  *
11  **************************************************************************/
12 
13 #ifdef HAVE_CONFIG_H
14 #include <config.h>
15 #endif
16 
17 #include <stdio.h>
18 #include <unistd.h>
19 #include <stdlib.h>
20 #include <fcntl.h>
21 #include <sys/dkio.h>
22 #include <sys/stat.h>
23 #include <glib.h>
24 
25 #include <libhal.h>
26 #include "../../hald/logger.h"
27 #include "../../hald/util_helper.h"
28 #include "../../utils/acpi.h"
29 
30 int
31 main(int argc, char **argv)
32 {
33 	LibHalContext *ctx = NULL;
34 	DBusError error;
35 
36 	GMainLoop *loop = g_main_loop_new(NULL, FALSE);
37 
38 	drop_privileges(0);
39 	setup_logger();
40 
41 	dbus_error_init(&error);
42 	if ((ctx = libhal_ctx_init_direct(&error)) == NULL) {
43 		printf("main(): init_direct failed\n");
44 		return (0);
45 	}
46 	dbus_error_init(&error);
47 	if (!libhal_device_addon_is_ready(ctx, getenv("UDI"), &error)) {
48 		return (0);
49 	}
50 
51 	g_timeout_add(BATTERY_POLL_TIMER, update_devices, ctx);
52 
53 	g_main_loop_run(loop);
54 }
55