int cthd_zone_surface::zone_bind_sensors() { int i = 0; while (skin_sensors[i]) { sensor = thd_engine->search_sensor(skin_sensors[i]); if (sensor) break; ++i; } if (!sensor) { thd_log_error("No SKIN sensor \n"); return THD_ERROR; } bind_sensor(sensor); return THD_SUCCESS; }
// Setup dbus server static int thd_dbus_server_proc(gboolean no_daemon) { DBusGConnection *bus; DBusGProxy *bus_proxy; GMainLoop *main_loop; GError *error = NULL; guint result; PrefObject *value_obj; thd_engine = NULL; // Initialize the GType/GObject system g_type_init(); // Create a main loop that will dispatch callbacks g_main_loop = main_loop = g_main_loop_new(NULL, FALSE); if (main_loop == NULL) { thd_log_error("Couldn't create GMainLoop:"); return THD_FATAL_ERROR; } if (dbus_enable) { bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); if (error != NULL) { thd_log_error("Couldn't connect to session bus: %s:", error->message); return THD_FATAL_ERROR; } // Get a bus proxy instance bus_proxy = dbus_g_proxy_new_for_name(bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (bus_proxy == NULL) { thd_log_error("Failed to get a proxy for D-Bus:"); return THD_FATAL_ERROR; } thd_log_debug("Registering the well-known name (%s)\n", THD_SERVICE_NAME); // register the well-known name if (!dbus_g_proxy_call(bus_proxy, "RequestName", &error, G_TYPE_STRING, THD_SERVICE_NAME, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID)) { thd_log_error("D-Bus.RequestName RPC failed: %s\n", error->message); return THD_FATAL_ERROR; } thd_log_debug("RequestName returned %d.\n", result); if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { thd_log_error("Failed to get the primary well-known name:"); return THD_FATAL_ERROR; } value_obj = (PrefObject*) g_object_new(PREF_TYPE_OBJECT, NULL); if (value_obj == NULL) { thd_log_error("Failed to create one Value instance:"); return THD_FATAL_ERROR; } thd_log_debug("Registering it on the D-Bus.\n"); dbus_g_connection_register_g_object(bus, THD_SERVICE_OBJECT_PATH, G_OBJECT(value_obj)); } if (!no_daemon) { printf("Ready to serve requests: Daemonizing.. %d\n", thd_daemonize); thd_log_info( "thermald ver %s: Ready to serve requests: Daemonizing..\n", TD_DIST_VERSION); if (daemon(0, 1) != 0) { thd_log_error("Failed to daemonize.\n"); return THD_FATAL_ERROR; } } thd_engine = new cthd_engine_default(); if (exclusive_control) thd_engine->set_control_mode(EXCLUSIVE); // Initialize thermald objects thd_engine->set_poll_interval(thd_poll_interval); if (thd_engine->thd_engine_start(ignore_cpuid_check) != THD_SUCCESS) { thd_log_error("THD engine start failed: "); closelog(); exit(1); } // Start service requests on the D-Bus thd_log_debug("Start main loop\n"); g_main_loop_run(main_loop); thd_log_warn("Oops g main loop exit..\n"); return THD_SUCCESS; }
int main(int argc, char *argv[]) { int c; int option_index = 0; bool no_daemon = false; bool exclusive_control = false; bool dbus_enable = false; bool test_mode = false; const char* const short_options = "hvnp:de"; static struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { "no-daemon", no_argument, 0, 'n' }, { "poll-interval", required_argument, 0, 'p' }, { "dbus-enable", no_argument, 0, 'd' }, { "exclusive_control", no_argument, 0, 'e' }, { "test-mode", no_argument, 0, 't' }, { NULL, 0, NULL, 0 } }; if (argc > 1) { while ((c = getopt_long(argc, argv, short_options, long_options, &option_index)) != -1) { int this_option_optind = optind ? optind : 1; switch (c) { case 'h': print_usage(stdout, 0); break; case 'v': fprintf(stdout, "1.03-01\n"); exit(0); break; case 'n': no_daemon = true; break; case 'd': dbus_enable = true; break; case 'p': thd_poll_interval = atoi(optarg); break; case 'e': exclusive_control = true; break; case 't': test_mode = true; break; case -1: case 0: break; default: break; } } } if (getuid() != 0 && !test_mode) { fprintf(stderr, "You must be root to run thermal daemon!\n"); exit(1); } if ((c = mkdir(TDRUNDIR, 0755)) != 0) { if (errno != EEXIST) { fprintf(stderr, "Cannot create '%s': %s\n", TDRUNDIR, strerror(errno)); exit(1); } } mkdir(TDCONFDIR, 0755); // Don't care return value as directory if (!no_daemon) { daemonize((char *) "/tmp/", (char *) "/tmp/thermald.pid"); } else signal(SIGINT, signal_handler); thd_log_info( "Linux Thermal Daemon is starting mode %d : poll_interval %d :ex_control %d\n", no_daemon, thd_poll_interval, exclusive_control); thd_engine = new cthd_engine_default(); if (exclusive_control) thd_engine->set_control_mode(EXCLUSIVE); thd_engine->set_poll_interval(thd_poll_interval); // Initialize thermald objects if (thd_engine->thd_engine_start(false) != THD_SUCCESS) { thd_log_error("thermald engine start failed: "); exit(1); } #ifdef VALGRIND_TEST // lots of STL lib function don't free memory // when called with exit(). // Here just run for some time and gracefully return. sleep(10); if (pid_file_handle) close(pid_file_handle); thd_engine->thd_engine_terminate(); sleep(1); delete thd_engine; #else for (;;) sleep(0xffff); thd_log_info("Linux Thermal Daemon is exiting \n"); #endif return 0; }
// Setup dbus server static int thd_dbus_server_proc(gboolean no_daemon) { DBusGConnection *bus; DBusGProxy *bus_proxy; GMainLoop *main_loop; GError *error = NULL; guint result; PrefObject *value_obj; // Initialize the GType/GObject system g_type_init(); // Create a main loop that will dispatch callbacks main_loop = g_main_loop_new(NULL, FALSE); if(main_loop == NULL) { thd_log_error("Couldn't create GMainLoop:"); return THD_FATAL_ERROR; } if(dbus_enable) { bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); if(error != NULL) { thd_log_error("Couldn't connect to session bus: %s:", error->message); return THD_FATAL_ERROR; } // Get a bus proxy instance bus_proxy = dbus_g_proxy_new_for_name(bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if(bus_proxy == NULL) { thd_log_error("Failed to get a proxy for D-Bus:"); return THD_FATAL_ERROR; } thd_log_debug("Registering the well-known name (%s)\n", THD_SERVICE_NAME); // register the well-known name if(!dbus_g_proxy_call(bus_proxy, "RequestName", &error, G_TYPE_STRING, THD_SERVICE_NAME, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID)) { thd_log_error("D-Bus.RequestName RPC failed: %s\n", error->message); return THD_FATAL_ERROR; } thd_log_debug("RequestName returned %d.\n", result); if(result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { thd_log_error("Failed to get the primary well-known name:"); return THD_FATAL_ERROR; } value_obj = (PrefObject*)g_object_new(PREF_TYPE_OBJECT, NULL); if(value_obj == NULL) { thd_log_error("Failed to create one Value instance:"); return THD_FATAL_ERROR; } thd_log_debug("Registering it on the D-Bus.\n"); dbus_g_connection_register_g_object(bus, THD_SERVICE_OBJECT_PATH, G_OBJECT (value_obj)); } if(!no_daemon) { printf("Ready to serve requests: Daemonizing.. %d\n", thd_daemonize); thd_log_info("thermald ver %s: Ready to serve requests: Daemonizing..\n", TD_DIST_VERSION); if(daemon(0, 1) != 0) { thd_log_error("Failed to daemonize.\n"); return THD_FATAL_ERROR; } } if(use_thermal_sys_fs) thd_engine = new cthd_engine_therm_sysfs(); else { cthd_parse parser; bool matched = false; // if there is XML config for this platform // Use this instead of default DTS sensor and associated cdevs if(parser.parser_init() == THD_SUCCESS) { if(parser.start_parse() == THD_SUCCESS) { matched = parser.platform_matched(); } } if (matched) { thd_log_warn("UUID matched, so will load zones and cdevs from thermal-conf.xml\n"); thd_engine = new cthd_engine_therm_sysfs(); } else thd_engine = new cthd_engine_dts(); } // Initialize thermald objects if(thd_engine->thd_engine_start() != THD_SUCCESS) { thd_log_error("THD engine start failed: "); closelog(); exit(1); } // Start service requests on the D-Bus thd_log_debug("Start main loop\n"); g_main_loop_run(main_loop); thd_log_warn("Oops g main loop exit..\n"); return THD_SUCCESS; }