};
struct xs_handle *xs;
+static pthread_t worker_thread;
+
extern void initialize_system_state_info(void);
extern void monitor_acpi_events(void);
extern void acpi_events_cleanup(void);
}
#endif /* RUN_STANDALONE */
-int main(int argc, char *argv[])
+/*
+ * IMPORTANT: From the child process, we create a new thread
+ * to monitor acpid events. However, due to a bug in uClibc,
+ * the child process main thread does not get time slice
+ * after spawning a new thread. To work around this, we create
+ * a worker thread and then create an acpid monitor thread from
+ * this worker thread. This way both the worker thread and acpid
+ * thread will get time slices. This workaround will be removed
+ * once uClibc bug is fixed.
+ */
+static void *worker_thread_routine(void *arg)
{
-#ifndef RUN_STANDALONE
- daemonize();
-#endif
xs = (struct xs_handle *)xs_daemon_open();
- if ( xs == NULL )
- return -1;
+ if ( xs == NULL )
+ return 0;
initialize_system_state_info();
monitor_acpi_events();
- if ( write_one_time_battery_info() == 0 )
+ if ( write_one_time_battery_info() == 0 )
{
xs_daemon_close(xs);
- return -1;
+ return 0;
}
wait_for_and_update_battery_status_request();
return 0;
}
+int main(int argc, char *argv[])
+{
+#ifndef RUN_STANDALONE
+ daemonize();
+#endif
+
+ /* Refer to worker_thread_routine for why we create additional thread */
+ pthread_create(&worker_thread, NULL, &worker_thread_routine, NULL);
+
+ /* below won't get a time slice because of uClibc bug. */
+ while ( 1 )
+ sleep(60);
+
+ return 0;
+}
+