xref: /titanic_41/usr/src/cmd/hal/addons/acpi/addon-acpi.c (revision b6917abefc343244b784f0cc34bc65b01469c3bf)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
14 
15 #ifdef HAVE_CONFIG_H
16 #include <config.h>
17 #endif
18 
19 #include <stdio.h>
20 #include <unistd.h>
21 #include <stdlib.h>
22 #include <fcntl.h>
23 #include <sys/dkio.h>
24 #include <sys/stat.h>
25 #include <glib.h>
26 
27 #include <libhal.h>
28 #include "../../hald/logger.h"
29 #include "../../hald/util_helper.h"
30 #include "../../utils/acpi.h"
31 
32 int
33 main(int argc, char **argv)
34 {
35 	LibHalContext *ctx = NULL;
36 	DBusError error;
37 
38 	GMainLoop *loop = g_main_loop_new(NULL, FALSE);
39 
40 	drop_privileges(0);
41 	setup_logger();
42 
43 	dbus_error_init(&error);
44 	if ((ctx = libhal_ctx_init_direct(&error)) == NULL) {
45 		printf("main(): init_direct failed\n");
46 		return (0);
47 	}
48 	dbus_error_init(&error);
49 	if (!libhal_device_addon_is_ready(ctx, getenv("UDI"), &error)) {
50 		return (0);
51 	}
52 
53 	g_timeout_add(BATTERY_POLL_TIMER, update_devices, ctx);
54 
55 	g_main_loop_run(loop);
56 }
57