gint main (gint argc, gchar **argv) { GMainLoop *loop; GOptionContext *context; GError *error = NULL; context = g_option_context_new ("- CPUFreq Selector"); g_option_context_add_main_entries (context, options, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { if (error) { g_printerr ("%s\n", error->message); g_error_free (error); } g_option_context_free (context); return 1; } g_option_context_free (context); if (!cpufreq_selector_service_register (SELECTOR_SERVICE, &error)) { if (governor || frequency != 0) { cpufreq_selector_set_values_dbus (); return 0; } g_printerr ("%s\n", error->message); g_error_free (error); return 1; } cpufreq_selector_set_values (); loop = g_main_loop_new (NULL, FALSE); g_object_weak_ref (G_OBJECT (SELECTOR_SERVICE), (GWeakNotify) do_exit, loop); g_main_loop_run (loop); g_main_loop_unref (loop); return 0; }
gint main (gint argc, gchar **argv) { #ifdef HAVE_POLKIT GMainLoop *loop; #endif GOptionContext *context; GError *error = NULL; #ifndef HAVE_POLKIT if (geteuid () != 0) { g_printerr ("You must be root\n"); return 1; } if (argc < 2) { g_printerr ("Missing operand after `cpufreq-selector'\n"); g_printerr ("Try `cpufreq-selector --help' for more information.\n"); return 1; } #endif g_type_init (); context = g_option_context_new ("- CPUFreq Selector"); g_option_context_add_main_entries (context, options, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { if (error) { g_printerr ("%s\n", error->message); g_error_free (error); } g_option_context_free (context); return 1; } g_option_context_free (context); #ifdef HAVE_POLKIT if (!cpufreq_selector_service_register (SELECTOR_SERVICE, &error)) { if (governor || frequency != 0) { cpufreq_selector_set_values_dbus (); return 0; } g_printerr ("%s\n", error->message); g_error_free (error); return 1; } cpufreq_selector_set_values (); loop = g_main_loop_new (NULL, FALSE); g_object_weak_ref (G_OBJECT (SELECTOR_SERVICE), (GWeakNotify) do_exit, loop); g_main_loop_run (loop); g_main_loop_unref (loop); #else /* !HAVE_POLKIT */ cpufreq_selector_set_values (); #endif /* HAVE_POLKIT */ return 0; }