static GtkWidget * make_menubar (void) { GtkWidget *w, *menu; GtkWidget *menubar = gtk_menu_bar_new (); /* FIXME: add translatable string here */ w = gtk_menu_item_new_with_label ("Menu"); gtk_menu_shell_append (GTK_MENU_SHELL (menubar), w); gtk_widget_show (GTK_WIDGET (w)); menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (w), menu); w = gtk_image_menu_item_new_with_mnemonic (_("Select _Language...")); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (w), gtk_image_new_from_icon_name ("preferences-desktop-locale", GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), w); gtk_widget_show (GTK_WIDGET (w)); g_signal_connect (G_OBJECT (w), "activate", G_CALLBACK (activate_button), "language_button"); w = gtk_image_menu_item_new_with_mnemonic (_("Select _Session...")); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (w), gtk_image_new_from_icon_name ("user-desktop", GTK_ICON_SIZE_MENU)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), w); gtk_widget_show (GTK_WIDGET (w)); g_signal_connect (G_OBJECT (w), "activate", G_CALLBACK (activate_button), "session_button"); greeter_system_append_system_menu (menu); /* Add a quit/disconnect item when in xdmcp mode or flexi mode */ /* Do note that the order is important, we always want "Quit" for * flexi, even if not local (non-local xnest). and Disconnect * only for xdmcp */ if ( ! ve_string_empty (g_getenv ("MDM_FLEXI_SERVER"))) { w = gtk_image_menu_item_new_with_mnemonic (_("_Quit")); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (w), gtk_image_new_from_icon_name ("system-log-out", GTK_ICON_SIZE_MENU)); } else if (ve_string_empty (g_getenv ("MDM_IS_LOCAL"))) { w = gtk_image_menu_item_new_with_mnemonic (_("D_isconnect")); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (w), gtk_image_new_from_icon_name ("system-log-out", GTK_ICON_SIZE_MENU)); } else { w = NULL; } if (w != NULL) { GtkWidget *sep; /* add separator before the quit */ sep = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL (menu), sep); gtk_widget_show (GTK_WIDGET (sep)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), w); gtk_widget_show (GTK_WIDGET (w)); g_signal_connect (G_OBJECT (w), "activate", G_CALLBACK (gtk_main_quit), NULL); } g_signal_connect (G_OBJECT(gtk_menu_item_get_submenu( gtk_container_get_children(GTK_CONTAINER(menubar))->data)), "selection-done", G_CALLBACK (menubar_done), NULL); return menubar; }
int main( int argc, char *argv[]) #endif { // command_line_path = argv[0]; // g_debug ("argc = %d", argc); // print_array ("argv", argv); // i18n support. We need to support i18n under console, too. setlocale(LC_ALL, ""); bindtextdomain (BINARY, LOCALEDIR); bind_textdomain_codeset (BINARY, "UTF-8"); textdomain (BINARY); const gchar *user_config_dir = g_get_user_config_dir(); #if ! defined(SAFEMODE) && defined(DEVELOP) g_message("Running %s without SAFE MODE!", PACKAGE); #endif #ifdef OUT_OF_MEMORY # undef g_strdup_printf #endif if (user_config_dir) profile_dir = g_strdup_printf("%s/%s", user_config_dir, BINARY); #ifdef OUT_OF_MEMORY #define g_strdup_printf(...) NULL #endif proc_exist = check_if_default_proc_dir_exist(NULL); // g_debug ("Get proc_exist = %d, proc_file_system_path = %s", proc_exist, proc_file_system_path); shell = g_getenv("SHELL"); if (shell==NULL) shell = ""; gboolean pwd_need_be_free = FALSE; pwd = (gchar *)g_getenv("PWD"); if (pwd==NULL) { pwd_need_be_free = TRUE; pwd = g_get_current_dir(); } if (pwd==NULL) { pwd_need_be_free = FALSE; pwd = ""; } // g_debug("Got $PWD = %s", pwd); home = g_getenv("HOME"); if (home==NULL) home = ""; // g_debug("Get $HOME = %s", home); // deal the command line options command_option(argc, argv); if (wmclass_name==NULL) wmclass_name = g_getenv("RESOURCE_NAME"); if (wmclass_name==NULL) wmclass_name = ""; if (wmclass_class==NULL) wmclass_class = ""; // g_debug("Got wmclass_name = %s, wmclass_class = %s", wmclass_name, wmclass_class); // init the gtk+2 engine // GTK3: get gtk_test_widget_click() working... // gdk_disable_multidevice(); #ifndef UNIT_TEST gtk_init(&argc, &argv); #endif // FIXME: we should get the single_process from profile. Current is command-line option only. if (single_process) { // init socket data if (init_socket_data()) { // trying to connect to an existing LilyTerm if (query_socket()) { // success, sent the argc/argv to socket then quit // g_debug("A LilyTerm socket server is exist already. exiting..."); if (send_socket(argc, argv, TRUE)) { g_free(profile_dir); exit (0); } } // no LilyTerm exist. create a socket server // g_debug("Creating a LilyTerm socket server..."); init_socket_server(); g_atexit((GVoidFunc)shutdown_socket_server); } } // start LilyTerm // empty_environ = g_strsplit("", " ", -1); extern gchar **environ; // print_array("main(): environ", environ); gchar *environ_str = convert_array_to_string(environ, '\t'); window_list = NULL; // g_debug("Got environ_str (in main.c) = %s", environ_str); selection_clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); selection_primary = gtk_clipboard_get(GDK_SELECTION_PRIMARY); system_locale_list = get_locale_list(); // g_debug("Got system_locale_list = %s", system_locale_list); init_LC_CTYPE = g_strdup(get_default_lc_data(LC_CTYPE)); // g_debug("Got init_LC_CTYPE = %s", init_LC_CTYPE); init_LANGUAGE = g_strdup(get_default_lc_data(LANGUAGE)); // g_debug("Got init_LANGUAGE = %s", init_LANGUAGE); init_LC_MESSAGES = g_strdup(get_default_lc_data(LC_MESSAGES)); // g_debug("init_LC_MESSAGES = %s", init_LC_MESSAGES); init_encoding = (gchar *)get_encoding_from_locale(NULL); if (! compare_strings(init_encoding, "ANSI_X3.4-1968", TRUE)) { g_free(init_encoding); init_encoding = g_strdup("UTF-8"); } // g_debug("init_encoding = %s", init_encoding); SYSTEM_VTE_CJK_WIDTH_STR = g_getenv("VTE_CJK_WIDTH"); // g_debug ("Got SYSTEM_VTE_CJK_WIDTH_STR = %s", SYSTEM_VTE_CJK_WIDTH_STR); // FIXME: signal(SIGCHLD, SIG_IGN); // The first window of LilyTerm // Convert the GdkColor to GdkRGBA convert_system_color_to_rgba(); // g_debug("Got original encoding = %s", get_encoding_from_locale(NULL)); //GtkNotebook *new_window(int argc, // char *argv[], // gchar *shell, // gchar *environment, // gchar *locale_list, // gchar *PWD, // gchar *HOME, // gchar *VTE_CJK_WIDTH_STR, // gboolean VTE_CJK_WIDTH_STR_overwrite_profile, // gchar *wmclass_name, // gchar *wmclass_class, // gchar *user_environ, // gchar *encoding, // gboolean encoding_overwrite_profile, // gchar *lc_messages, // struct Window *win_data_orig, // struct Page *page_data_orig) if ((new_window(argc, argv, (gchar *) shell, environ_str, system_locale_list, (gchar *) pwd, (gchar *) home, SYSTEM_VTE_CJK_WIDTH_STR, FALSE, wmclass_name, wmclass_class, NULL, init_encoding, FALSE, init_LC_MESSAGES, NULL, NULL)) || window_list) { // The argv of "main" LilyTerm can't be free. // Set it to NULL here to avoid double_free(). argv=NULL; #ifdef ENABLE_X_STARTUP_NOTIFICATION_ID gdk_notify_startup_complete_with_id(PACKAGE); #endif // g_debug("gtk_main_level = %d", gtk_main_level()); if (! gtk_main_level()) gtk_main(); } #ifdef DETAIL else { // g_debug("Got window_list = %p", window_list); // GList *win_list = window_list; // gint i=0; // // while (win_list) // { // g_debug("Got %d win_data = %p", ++i, win_list->data); // win_list = win_list->next; // } g_debug("??? The creation of first window is FAIL!!!"); } #endif extern struct KeyValue system_keys[KEYS]; gint i; // g_debug("Clear function key data!!"); for (i=KEY_SWITCH_TO_TAB_1; i<=KEY_SWITCH_TO_TAB_12; i++) { g_free(system_keys[i].name); g_free(system_keys[i].topic); g_free(system_keys[i].comment); g_free(system_keys[i].translation); #ifdef UNIT_TEST system_keys[i].name = NULL; system_keys[i].topic = NULL; system_keys[i].comment = NULL; system_keys[i].translation = NULL; #endif } // g_free(pwd); // g_strfreev(empty_environ); g_free(environ_str); g_free(init_encoding); g_free(system_locale_list); g_free(profile_dir); if (pwd_need_be_free) g_free(pwd); g_free(restricted_locale_message); g_list_free(window_list); g_free(init_LC_CTYPE); g_free(init_LC_MESSAGES); #ifdef UNIT_TEST // empty_environ = NULL; environ_str = NULL; init_encoding = NULL; system_locale_list = NULL; profile_dir = NULL; restricted_locale_message = NULL; window_list = NULL; init_LC_CTYPE = NULL; init_LC_MESSAGES = NULL; #endif return 0; }
int rpmostree_compose_builtin_tree (int argc, char **argv, GCancellable *cancellable, GError **error) { int exit_status = EXIT_FAILURE; GError *temp_error = NULL; GOptionContext *context = g_option_context_new ("TREEFILE - Run yum and commit the result to an OSTree repository"); RpmOstreeTreeComposeContext selfdata = { NULL, }; RpmOstreeTreeComposeContext *self = &selfdata; JsonNode *treefile_rootval = NULL; JsonObject *treefile = NULL; g_autofree char *cachekey = NULL; g_autofree char *new_inputhash = NULL; g_autoptr(GFile) previous_root = NULL; g_autofree char *previous_checksum = NULL; g_autoptr(GFile) yumroot = NULL; g_autoptr(GFile) yumroot_varcache = NULL; glnx_fd_close int rootfs_fd = -1; glnx_unref_object OstreeRepo *repo = NULL; g_autoptr(GPtrArray) bootstrap_packages = NULL; g_autoptr(GPtrArray) packages = NULL; g_autoptr(GFile) treefile_path = NULL; g_autoptr(GFile) treefile_dirpath = NULL; g_autoptr(GFile) repo_path = NULL; glnx_unref_object JsonParser *treefile_parser = NULL; gs_unref_variant_builder GVariantBuilder *metadata_builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); g_autoptr(RpmOstreeContext) corectx = NULL; g_autoptr(GHashTable) varsubsts = NULL; gboolean workdir_is_tmp = FALSE; g_autofree char *next_version = NULL; self->treefile_context_dirs = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); if (!rpmostree_option_context_parse (context, option_entries, &argc, &argv, RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, cancellable, NULL, error)) goto out; if (argc < 2) { rpmostree_usage_error (context, "TREEFILE must be specified", error); goto out; } if (!opt_repo) { rpmostree_usage_error (context, "--repo must be specified", error); goto out; } if (getuid () != 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "compose tree must presently be run as uid 0 (root)"); goto out; } /* Test whether or not bwrap is going to work - we will fail inside e.g. a Docker * container without --privileged or userns exposed. */ if (!rpmostree_bwrap_selftest (error)) goto out; repo_path = g_file_new_for_path (opt_repo); repo = self->repo = ostree_repo_new (repo_path); if (!ostree_repo_open (repo, cancellable, error)) goto out; treefile_path = g_file_new_for_path (argv[1]); if (opt_workdir) { self->workdir = g_file_new_for_path (opt_workdir); } else { g_autofree char *tmpd = NULL; if (!rpmostree_mkdtemp ("/var/tmp/rpm-ostree.XXXXXX", &tmpd, NULL, error)) goto out; self->workdir = g_file_new_for_path (tmpd); workdir_is_tmp = TRUE; if (opt_workdir_tmpfs) { if (mount ("tmpfs", tmpd, "tmpfs", 0, (const void*)"mode=755") != 0) { _rpmostree_set_prefix_error_from_errno (error, errno, "mount(tmpfs): "); goto out; } } } if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (self->workdir), FALSE, &self->workdir_dfd, error)) goto out; if (opt_cachedir) { if (!glnx_opendirat (AT_FDCWD, opt_cachedir, TRUE, &self->cachedir_dfd, error)) { g_prefix_error (error, "Opening cachedir '%s': ", opt_cachedir); goto out; } } else { self->cachedir_dfd = fcntl (self->workdir_dfd, F_DUPFD_CLOEXEC, 3); if (self->cachedir_dfd < 0) { glnx_set_error_from_errno (error); goto out; } } if (opt_metadata_strings) { if (!parse_keyvalue_strings (opt_metadata_strings, metadata_builder, error)) goto out; } if (fchdir (self->workdir_dfd) != 0) { glnx_set_error_from_errno (error); goto out; } corectx = rpmostree_context_new_compose (self->cachedir_dfd, cancellable, error); if (!corectx) goto out; varsubsts = rpmostree_context_get_varsubsts (corectx); treefile_parser = json_parser_new (); if (!json_parser_load_from_file (treefile_parser, gs_file_get_path_cached (treefile_path), error)) goto out; treefile_rootval = json_parser_get_root (treefile_parser); if (!JSON_NODE_HOLDS_OBJECT (treefile_rootval)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Treefile root is not an object"); goto out; } treefile = json_node_get_object (treefile_rootval); if (!process_includes (self, treefile_path, 0, treefile, cancellable, error)) goto out; if (opt_print_only) { glnx_unref_object JsonGenerator *generator = json_generator_new (); g_autoptr(GOutputStream) stdout = g_unix_output_stream_new (1, FALSE); json_generator_set_pretty (generator, TRUE); json_generator_set_root (generator, treefile_rootval); (void) json_generator_to_stream (generator, stdout, NULL, NULL); exit_status = EXIT_SUCCESS; goto out; } { const char *input_ref = _rpmostree_jsonutil_object_require_string_member (treefile, "ref", error); if (!input_ref) goto out; self->ref = _rpmostree_varsubst_string (input_ref, varsubsts, error); if (!self->ref) goto out; } if (!ostree_repo_read_commit (repo, self->ref, &previous_root, &previous_checksum, cancellable, &temp_error)) { if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_clear_error (&temp_error); g_print ("No previous commit for %s\n", self->ref); } else { g_propagate_error (error, temp_error); goto out; } } else g_print ("Previous commit: %s\n", previous_checksum); self->previous_checksum = previous_checksum; yumroot = g_file_get_child (self->workdir, "rootfs.tmp"); if (!glnx_shutil_rm_rf_at (self->workdir_dfd, "rootfs.tmp", cancellable, error)) goto out; if (json_object_has_member (treefile, "automatic_version_prefix") && !compose_strv_contains_prefix (opt_metadata_strings, "version=")) { g_autoptr(GVariant) variant = NULL; g_autofree char *last_version = NULL; const char *ver_prefix; ver_prefix = _rpmostree_jsonutil_object_require_string_member (treefile, "automatic_version_prefix", error); if (!ver_prefix) goto out; if (previous_checksum) { if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, previous_checksum, &variant, error)) goto out; last_version = checksum_version (variant); } next_version = _rpmostree_util_next_version (ver_prefix, last_version); g_variant_builder_add (metadata_builder, "{sv}", "version", g_variant_new_string (next_version)); } bootstrap_packages = g_ptr_array_new (); packages = g_ptr_array_new (); if (json_object_has_member (treefile, "bootstrap_packages")) { if (!_rpmostree_jsonutil_append_string_array_to (treefile, "bootstrap_packages", packages, error)) goto out; } if (!_rpmostree_jsonutil_append_string_array_to (treefile, "packages", packages, error)) goto out; { g_autofree char *thisarch_packages = g_strconcat ("packages-", dnf_context_get_base_arch (rpmostree_context_get_hif (corectx)), NULL); if (json_object_has_member (treefile, thisarch_packages)) { if (!_rpmostree_jsonutil_append_string_array_to (treefile, thisarch_packages, packages, error)) goto out; } } g_ptr_array_add (packages, NULL); { glnx_unref_object JsonGenerator *generator = json_generator_new (); char *treefile_buf = NULL; gsize len; json_generator_set_root (generator, treefile_rootval); json_generator_set_pretty (generator, TRUE); treefile_buf = json_generator_to_data (generator, &len); self->serialized_treefile = g_bytes_new_take (treefile_buf, len); } treefile_dirpath = g_file_get_parent (treefile_path); if (TRUE) { gboolean generate_from_previous = TRUE; if (!_rpmostree_jsonutil_object_get_optional_boolean_member (treefile, "preserve-passwd", &generate_from_previous, error)) goto out; if (generate_from_previous) { if (!rpmostree_generate_passwd_from_previous (repo, yumroot, treefile_dirpath, previous_root, treefile, cancellable, error)) goto out; } } { gboolean unmodified = FALSE; if (!install_packages_in_root (self, corectx, treefile, yumroot, (char**)packages->pdata, opt_force_nocache ? NULL : &unmodified, &new_inputhash, cancellable, error)) goto out; if (unmodified) { g_print ("No apparent changes since previous commit; use --force-nocache to override\n"); exit_status = EXIT_SUCCESS; goto out; } else if (opt_dry_run) { g_print ("--dry-run complete, exiting\n"); exit_status = EXIT_SUCCESS; goto out; } } if (g_strcmp0 (g_getenv ("RPM_OSTREE_BREAK"), "post-yum") == 0) goto out; if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (yumroot), TRUE, &rootfs_fd, error)) goto out; if (!rpmostree_treefile_postprocessing (rootfs_fd, self->treefile_context_dirs->pdata[0], self->serialized_treefile, treefile, next_version, cancellable, error)) goto out; if (!rpmostree_prepare_rootfs_for_commit (yumroot, treefile, cancellable, error)) goto out; /* Reopen since the prepare renamed */ (void) close (rootfs_fd); if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (yumroot), TRUE, &rootfs_fd, error)) goto out; if (!rpmostree_copy_additional_files (yumroot, self->treefile_context_dirs->pdata[0], treefile, cancellable, error)) goto out; if (!rpmostree_check_passwd (repo, yumroot, treefile_dirpath, treefile, previous_checksum, cancellable, error)) goto out; if (!rpmostree_check_groups (repo, yumroot, treefile_dirpath, treefile, previous_checksum, cancellable, error)) goto out; { const char *gpgkey; gboolean selinux = TRUE; g_autoptr(GVariant) metadata = NULL; g_variant_builder_add (metadata_builder, "{sv}", "rpmostree.inputhash", g_variant_new_string (new_inputhash)); metadata = g_variant_ref_sink (g_variant_builder_end (metadata_builder)); if (!_rpmostree_jsonutil_object_get_optional_string_member (treefile, "gpg_key", &gpgkey, error)) goto out; if (!_rpmostree_jsonutil_object_get_optional_boolean_member (treefile, "selinux", &selinux, error)) goto out; { g_autofree char *new_revision = NULL; if (!rpmostree_commit (rootfs_fd, repo, self->ref, metadata, gpgkey, selinux, NULL, &new_revision, cancellable, error)) goto out; g_print ("%s => %s\n", self->ref, new_revision); } } if (opt_touch_if_changed) { gs_fd_close int fd = open (opt_touch_if_changed, O_CREAT|O_WRONLY|O_NOCTTY, 0644); if (fd == -1) { gs_set_error_from_errno (error, errno); g_prefix_error (error, "Updating '%s': ", opt_touch_if_changed); goto out; } if (futimens (fd, NULL) == -1) { gs_set_error_from_errno (error, errno); goto out; } } exit_status = EXIT_SUCCESS; out: /* Explicitly close this one now as it may have references to files * we delete below. */ g_clear_object (&corectx); /* Move back out of the workding directory to ensure unmount works */ (void )chdir ("/"); if (self->workdir_dfd != -1) (void) close (self->workdir_dfd); if (workdir_is_tmp) { if (opt_workdir_tmpfs) if (umount (gs_file_get_path_cached (self->workdir)) != 0) { fprintf (stderr, "warning: umount failed: %m\n"); } (void) gs_shutil_rm_rf (self->workdir, NULL, NULL); } if (self) { g_clear_object (&self->workdir); g_clear_pointer (&self->serialized_treefile, g_bytes_unref); g_ptr_array_unref (self->treefile_context_dirs); } return exit_status; }
static gboolean spawn_x_server (State *state, gboolean allow_remote_connections, GCancellable *cancellable) { GPtrArray *arguments = NULL; GSubprocessLauncher *launcher = NULL; GSubprocess *subprocess = NULL; GInputStream *input_stream = NULL; GDataInputStream *data_stream = NULL; GError *error = NULL; char *auth_file; gboolean is_running = FALSE; int ret; int pipe_fds[2]; char *display_fd_string = NULL; char *vt_string = NULL; char *display_number; gsize display_number_size; auth_file = prepare_auth_file (); g_debug ("Running X server"); ret = g_unix_open_pipe (pipe_fds, FD_CLOEXEC, &error); if (!ret) { g_debug ("could not open pipe: %s", error->message); goto out; } arguments = g_ptr_array_new (); launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDIN_INHERIT); g_subprocess_launcher_setenv (launcher, "XORG_RUN_AS_USER_OK", "1", TRUE); g_subprocess_launcher_take_fd (launcher, pipe_fds[1], DISPLAY_FILENO); if (g_getenv ("XDG_VTNR") != NULL) { int vt; vt = atoi (g_getenv ("XDG_VTNR")); if (vt > 0 && vt < 64) { vt_string = g_strdup_printf ("vt%d", vt); } } display_fd_string = g_strdup_printf ("%d", DISPLAY_FILENO); g_ptr_array_add (arguments, X_SERVER); if (vt_string != NULL) { g_ptr_array_add (arguments, vt_string); } g_ptr_array_add (arguments, "-displayfd"); g_ptr_array_add (arguments, display_fd_string); g_ptr_array_add (arguments, "-auth"); g_ptr_array_add (arguments, auth_file); /* If we were compiled with Xserver >= 1.17 we need to specify * '-listen tcp' as the X server dosen't listen on tcp sockets * by default anymore. In older versions we need to pass * -nolisten tcp to disable listening on tcp sockets. */ #ifdef HAVE_XSERVER_THAT_DEFAULTS_TO_LOCAL_ONLY if (allow_remote_connections) { g_ptr_array_add (arguments, "-listen"); g_ptr_array_add (arguments, "tcp"); } #else if (!allow_remote_connections) { g_ptr_array_add (arguments, "-nolisten"); g_ptr_array_add (arguments, "tcp"); } #endif g_ptr_array_add (arguments, "-background"); g_ptr_array_add (arguments, "none"); g_ptr_array_add (arguments, "-noreset"); g_ptr_array_add (arguments, "-keeptty"); g_ptr_array_add (arguments, "-verbose"); if (state->debug_enabled) { g_ptr_array_add (arguments, "7"); } else { g_ptr_array_add (arguments, "3"); } if (state->debug_enabled) { g_ptr_array_add (arguments, "-core"); } g_ptr_array_add (arguments, NULL); subprocess = g_subprocess_launcher_spawnv (launcher, (const char * const *) arguments->pdata, &error); g_free (display_fd_string); g_clear_object (&launcher); g_ptr_array_free (arguments, TRUE); if (subprocess == NULL) { g_debug ("could not start X server: %s", error->message); goto out; } input_stream = g_unix_input_stream_new (pipe_fds[0], TRUE); data_stream = g_data_input_stream_new (input_stream); g_clear_object (&input_stream); display_number = g_data_input_stream_read_line (data_stream, &display_number_size, cancellable, &error); if (error != NULL) { g_debug ("could not read display string from X server: %s", error->message); goto out; } if (display_number == NULL) { g_debug ("X server did not write display string"); goto out; } state->display_name = g_strdup_printf (":%s", display_number); g_clear_pointer (&display_number, g_free); state->auth_file = g_strdup (auth_file); state->x_subprocess = g_object_ref (subprocess); g_subprocess_wait_async (state->x_subprocess, cancellable, (GAsyncReadyCallback) on_x_server_finished, state); is_running = TRUE; out: g_clear_pointer (&auth_file, g_free); g_clear_object (&data_stream); g_clear_object (&subprocess); g_clear_object (&launcher); g_clear_error (&error); return is_running; }
const gchar *g_get_user_name(void) { // The normal glib version parses pwent entries return g_getenv("TEST_USER"); }
int main (int argc, char **argv) { GOptionContext *context; GOptionGroup *group; GError* err = NULL; int i; int args_len; mode_t dir_permissions; char *basename; setlocale (LC_ALL, ""); basename = g_path_get_basename (argv[0]); if (g_strcmp0 (basename, "desktop-file-edit") == 0) edit_mode = TRUE; g_free (basename); context = g_option_context_new (""); g_option_context_set_summary (context, edit_mode ? _("Edit a desktop file.") : _("Install desktop files.")); g_option_context_add_main_entries (context, main_options, NULL); if (!edit_mode) { group = g_option_group_new ("install", _("Installation options for desktop file"), _("Show desktop file installation options"), NULL, NULL); g_option_group_add_entries (group, install_options); g_option_context_add_group (context, group); } group = g_option_group_new ("edit", _("Edition options for desktop file"), _("Show desktop file edition options"), NULL, NULL); g_option_group_add_entries (group, edit_options); g_option_group_set_parse_hooks (group, NULL, post_parse_edit_options_callback); g_option_context_add_group (context, group); err = NULL; g_option_context_parse (context, &argc, &argv, &err); if (err != NULL) { g_printerr ("%s\n", err->message); g_printerr (_("Run '%s --help' to see a full list of available command line options.\n"), argv[0]); g_error_free (err); return 1; } if (!edit_mode) { if (vendor_name == NULL && g_getenv ("DESKTOP_FILE_VENDOR")) vendor_name = g_strdup (g_getenv ("DESKTOP_FILE_VENDOR")); if (target_dir == NULL && g_getenv ("DESKTOP_FILE_INSTALL_DIR")) target_dir = g_strdup (g_getenv ("DESKTOP_FILE_INSTALL_DIR")); if (target_dir == NULL) { if (g_getenv ("RPM_BUILD_ROOT")) target_dir = g_build_filename (g_getenv ("RPM_BUILD_ROOT"), DATADIR, "applications", NULL); else target_dir = g_build_filename (DATADIR, "applications", NULL); } /* Create the target directory */ dir_permissions = permissions; /* Add search bit when the target file is readable */ if (permissions & 0400) dir_permissions |= 0100; if (permissions & 0040) dir_permissions |= 0010; if (permissions & 0004) dir_permissions |= 0001; g_mkdir_with_parents (target_dir, dir_permissions); } args_len = 0; for (i = 0; args && args[i]; i++) args_len++; if (edit_mode) { if (args_len == 0) { g_printerr (_("Must specify a desktop file to process.\n")); return 1; } if (args_len > 1) { g_printerr (_("Only one desktop file can be processed at once.\n")); return 1; } } else { if (args_len == 0) { g_printerr (_("Must specify one or more desktop files to process.\n")); return 1; } } for (i = 0; args && args[i]; i++) { err = NULL; process_one_file (args[i], &err); if (err != NULL) { g_printerr (_("Error on file \"%s\": %s\n"), args[i], err->message); g_error_free (err); return 1; } } #if GLIB_CHECK_VERSION(2,28,0) g_slist_free_full (edit_actions, (GDestroyNotify) dfu_edit_action_free); #else g_slist_foreach (edit_actions, (GFunc) dfu_edit_action_free, NULL); g_slist_free (edit_actions); #endif g_option_context_free (context); return 0; }
static gboolean clutter_backend_real_create_context (ClutterBackend *backend, GError **error) { GError *internal_error = NULL; const char *drivers_list; char **known_drivers; gboolean allow_any; int i; if (allowed_drivers == NULL) allowed_drivers = CLUTTER_DRIVERS; allow_any = strstr (allowed_drivers, "*") != NULL; drivers_list = g_getenv ("CLUTTER_DRIVER"); if (drivers_list == NULL) drivers_list = allowed_drivers; known_drivers = g_strsplit (drivers_list, ",", 0); for (i = 0; backend->cogl_context == NULL && known_drivers[i] != NULL; i++) { const char *driver_name = known_drivers[i]; gboolean is_any = g_str_equal (driver_name, "*"); int j; for (j = 0; j < G_N_ELEMENTS (all_known_drivers); j++) { if (!allow_any && !is_any && !strstr (driver_name, all_known_drivers[j].driver_name)) continue; if ((allow_any && is_any) || (is_any && strstr (allowed_drivers, all_known_drivers[j].driver_name)) || g_str_equal (all_known_drivers[j].driver_name, driver_name)) { CLUTTER_NOTE (BACKEND, "Checking for the %s driver", all_known_drivers[j].driver_desc); if (clutter_backend_do_real_create_context (backend, all_known_drivers[j].driver_id, &internal_error)) break; if (internal_error) { CLUTTER_NOTE (BACKEND, "Unable to use the %s driver: %s", all_known_drivers[j].driver_desc, internal_error->message); g_clear_error (&internal_error); } } } } g_strfreev (known_drivers); if (backend->cogl_context == NULL) { if (internal_error != NULL) g_propagate_error (error, internal_error); else g_set_error_literal (error, CLUTTER_INIT_ERROR, CLUTTER_INIT_ERROR_BACKEND, _("Unable to initialize the Clutter backend: no available drivers found.")); return FALSE; } backend->cogl_source = cogl_glib_source_new (backend->cogl_context, G_PRIORITY_DEFAULT); g_source_attach (backend->cogl_source, NULL); return TRUE; }
int main (int argc, char **argv) { struct sigaction sa; GError *error; char *display_str; CsmManager *manager; CsmStore *client_store; CsmXsmpServer *xsmp_server; MdmSignalHandler *signal_handler; static char **override_autostart_dirs = NULL; static char *session_name = NULL; static GOptionEntry entries[] = { { "autostart", 'a', 0, G_OPTION_ARG_STRING_ARRAY, &override_autostart_dirs, N_("Override standard autostart directories"), N_("AUTOSTART_DIR") }, { "session", 0, 0, G_OPTION_ARG_STRING, &session_name, N_("Session to use"), N_("SESSION_NAME") }, { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debugging code"), NULL }, { "failsafe", 'f', 0, G_OPTION_ARG_NONE, &failsafe, N_("Do not load user-specified applications"), NULL }, { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Version of this application"), NULL }, /* Translators: the 'fail whale' is the black dialog we show when something goes seriously wrong */ { "whale", 0, 0, G_OPTION_ARG_NONE, &please_fail, N_("Show the fail whale dialog for testing"), NULL }, { NULL, 0, 0, 0, NULL, NULL, NULL } }; /* Make sure that we have a session bus */ if (!require_dbus_session (argc, argv, &error)) { csm_util_init_error (TRUE, "%s", error->message); } bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); sa.sa_handler = SIG_IGN; sa.sa_flags = 0; sigemptyset (&sa.sa_mask); sigaction (SIGPIPE, &sa, 0); error = NULL; gtk_init_with_args (&argc, &argv, (char *) _(" - the Cinnamon session manager"), entries, GETTEXT_PACKAGE, &error); if (error != NULL) { g_warning ("%s", error->message); exit (1); } if (show_version) { g_print ("%s %s\n", argv [0], VERSION); exit (1); } if (please_fail) { csm_fail_whale_dialog_we_failed (TRUE, TRUE); gtk_main (); exit (1); } mdm_log_init (); mdm_log_set_debug (debug); /* Set DISPLAY explicitly for all our children, in case --display * was specified on the command line. */ display_str = gdk_get_display (); csm_util_setenv ("DISPLAY", display_str); g_free (display_str); const gchar *gtk_modules; gchar *new_gtk_modules = NULL; gtk_modules = g_getenv ("GTK_MODULES"); if (gtk_modules != NULL && g_strstr_len (gtk_modules, -1, "overlay-scrollbar")) { int i = 0; new_gtk_modules = g_strconcat ("", NULL); gchar **module_list = g_strsplit (gtk_modules, ":", -1); for (i = 0; i < g_strv_length (module_list); i++) { if (!g_strstr_len (module_list[i], -1, "overlay-scrollbar")) { gchar *tmp = new_gtk_modules; new_gtk_modules = g_strconcat (tmp, ":", module_list[i], NULL); g_free (tmp); } } g_strfreev (module_list); } if (new_gtk_modules) { csm_util_setenv ("GTK_MODULES", new_gtk_modules); } g_free (new_gtk_modules); /* Some third-party programs rely on GNOME_DESKTOP_SESSION_ID to * detect if GNOME is running. We keep this for compatibility reasons. */ csm_util_setenv ("GNOME_DESKTOP_SESSION_ID", "this-is-deprecated"); csm_util_setenv ("CLUTTER_BACKEND", "x11"); client_store = csm_store_new (); /* Talk to logind before acquiring a name, since it does synchronous * calls at initialization time that invoke a main loop and if we * already owned a name, then we would service too early during * that main loop. */ g_object_unref (csm_get_system ()); xsmp_server = csm_xsmp_server_new (client_store); if (!acquire_name ()) { csm_fail_whale_dialog_we_failed (TRUE, TRUE); gtk_main (); exit (1); } manager = csm_manager_new (client_store, failsafe); /* signal_handler = mdm_signal_handler_new (); mdm_signal_handler_add_fatal (signal_handler); mdm_signal_handler_add (signal_handler, SIGFPE, signal_cb, NULL); mdm_signal_handler_add (signal_handler, SIGHUP, signal_cb, NULL); mdm_signal_handler_add (signal_handler, SIGUSR1, signal_cb, NULL); mdm_signal_handler_add (signal_handler, SIGTERM, signal_cb, manager); mdm_signal_handler_add (signal_handler, SIGINT, signal_cb, manager); mdm_signal_handler_set_fatal_func (signal_handler, shutdown_cb, manager); */ if (IS_STRING_EMPTY (session_name)) session_name = _csm_manager_get_default_session (manager); csm_util_set_autostart_dirs (override_autostart_dirs); if (!csm_session_fill (manager, session_name)) { csm_util_init_error (TRUE, "Failed to load session \"%s\"", session_name ? session_name : "(null)"); } csm_xsmp_server_start (xsmp_server); csm_manager_start (manager); gtk_main (); if (xsmp_server != NULL) { g_object_unref (xsmp_server); } if (manager != NULL) { g_debug ("Unreffing manager"); g_object_unref (manager); } if (client_store != NULL) { g_object_unref (client_store); } if (bus_proxy != NULL) { g_object_unref (bus_proxy); } mdm_log_shutdown (); return 0; }
int cliprdr_init() { char filename[256]; struct list* names; struct list* values; char* name; char* value; int index; int display_num; display_num = g_get_display_num_from_display(g_getenv("DISPLAY")); if(display_num == 0) { g_printf("cliprdr[cliprdr_init]: Display must be different of 0\n"); return ERROR; } l_config = g_malloc(sizeof(struct log_config), 1); l_config->program_name = "cliprdr"; l_config->log_file = 0; l_config->fd = 0; l_config->log_level = LOG_LEVEL_DEBUG; l_config->enable_syslog = 0; l_config->syslog_level = LOG_LEVEL_DEBUG; names = list_create(); names->auto_free = 1; values = list_create(); values->auto_free = 1; g_snprintf(filename, 255, "%s/cliprdr.conf", XRDP_CFG_PATH); if (file_by_name_read_section(filename, CLIPRDR_CFG_GLOBAL, names, values) == 0) { for (index = 0; index < names->count; index++) { name = (char*)list_get_item(names, index); value = (char*)list_get_item(values, index); if (0 == g_strcasecmp(name, CLIPRDR_CFG_NAME)) { if( g_strlen(value) > 1) { l_config->program_name = (char*)g_strdup(value); } } } } if (file_by_name_read_section(filename, CLIPRDR_CFG_LOGGING, names, values) == 0) { for (index = 0; index < names->count; index++) { name = (char*)list_get_item(names, index); value = (char*)list_get_item(values, index); if (0 == g_strcasecmp(name, CLIPRDR_CFG_LOG_LEVEL)) { l_config->log_level = log_text2level(value); } } } list_delete(names); list_delete(values); if(log_start(l_config) != LOG_STARTUP_OK) { g_printf("vchannel[vchannel_init]: Unable to start log system\n"); return ERROR; } else { return LOG_STARTUP_OK; } return 0; }
void gnc_module_init_backend_dbi (void) { const char* driver_dir; int num_drivers; gboolean have_sqlite3_driver = FALSE; gboolean have_mysql_driver = FALSE; gboolean have_pgsql_driver = FALSE; /* Initialize libdbi and see which drivers are available. Only register qof backends which have drivers available. */ driver_dir = g_getenv ("GNC_DBD_DIR"); if (driver_dir == nullptr) { PINFO ("GNC_DBD_DIR not set: using libdbi built-in default\n"); } /* dbi_initialize returns -1 in case of errors */ #if HAVE_LIBDBI_R if (dbi_instance) return; num_drivers = dbi_initialize_r (driver_dir, &dbi_instance); #else num_drivers = dbi_initialize (driver_dir); #endif if (num_drivers <= 0) { gchar* dir = g_build_filename (gnc_path_get_libdir (), "dbd", nullptr); #if HAVE_LIBDBI_R if (dbi_instance) return; num_drivers = dbi_initialize_r (dir, &dbi_instance); #else num_drivers = dbi_initialize (dir); #endif g_free (dir); } if (num_drivers <= 0) { PWARN ("No DBD drivers found\n"); } else { dbi_driver driver = nullptr; PINFO ("%d DBD drivers found\n", num_drivers); do { #if HAVE_LIBDBI_R driver = dbi_driver_list_r (driver, dbi_instance); #else driver = dbi_driver_list (driver); #endif if (driver != nullptr) { const gchar* name = dbi_driver_get_name (driver); PINFO ("Driver: %s\n", name); if (strcmp (name, "sqlite3") == 0) { have_sqlite3_driver = TRUE; } else if (strcmp (name, "mysql") == 0) { have_mysql_driver = TRUE; } else if (strcmp (name, "pgsql") == 0) { have_pgsql_driver = TRUE; } } } while (driver != nullptr); } if (have_sqlite3_driver) { const char* name = "GnuCash Libdbi (SQLITE3) Backend"; auto prov = QofBackendProvider_ptr(new QofDbiBackendProvider<DbType::DBI_SQLITE>{name, FILE_URI_TYPE}); qof_backend_register_provider(std::move(prov)); prov = QofBackendProvider_ptr(new QofDbiBackendProvider<DbType::DBI_SQLITE>{name, SQLITE3_URI_TYPE}); qof_backend_register_provider(std::move(prov)); } if (have_mysql_driver) { const char *name = "GnuCash Libdbi (MYSQL) Backend"; auto prov = QofBackendProvider_ptr(new QofDbiBackendProvider<DbType::DBI_MYSQL>{name, "mysql"}); qof_backend_register_provider(std::move(prov)); } if (have_pgsql_driver) { const char* name = "GnuCash Libdbi (POSTGRESQL) Backend"; auto prov = QofBackendProvider_ptr(new QofDbiBackendProvider<DbType::DBI_PGSQL>{name, "postgres"}); qof_backend_register_provider(std::move(prov)); } /* If needed, set log level to DEBUG so that SQl statements will be put into the gnucash.trace file. */ /* qof_log_set_level( log_module, QOF_LOG_DEBUG ); */ }
/** * gst_tag_freeform_string_to_utf8: * @data: string data * @size: length of string data, or -1 if the string is NUL-terminated * @env_vars: a NULL-terminated string array of environment variable names, * or NULL * * Convenience function to read a string with unknown character encoding. If * the string is already in UTF-8 encoding, it will be returned right away. * If not it tries to detect byte-order-mark for UTF-16/32 cases and use that. * Otherwise, the environment will be searched for a number of environment * variables (whose names are specified in the NULL-terminated string array * @env_vars) containing a list of character encodings to try/use. If none * are specified, the current locale will be tried. If that also doesn't work, * WINDOWS-1252/ISO-8859-1 is assumed (which will almost always succeed). * * Returns: a newly-allocated string in UTF-8 encoding, or NULL * * Since: 0.10.13 */ gchar * gst_tag_freeform_string_to_utf8 (const gchar * data, gint size, const gchar ** env_vars) { const gchar *cur_loc = NULL; gsize bytes_read; gchar *utf8 = NULL; g_return_val_if_fail (data != NULL, NULL); if (size < 0) size = strlen (data); /* chop off trailing string terminators to make sure utf8_validate doesn't * get to see them (since that would make the utf8 check fail) */ while (size > 0 && data[size - 1] == '\0') --size; /* Should we try the charsets specified * via environment variables FIRST ? */ if (g_utf8_validate (data, size, NULL)) { utf8 = g_strndup (data, size); GST_LOG ("String '%s' is valid UTF-8 already", utf8); goto beach; } /* check for and use byte-order-mark for UTF-16/32 cases */ if (size >= 2) { const gchar *c = NULL; gint prefix, ssize; if (size >= 4) { prefix = 4; ssize = GST_ROUND_DOWN_4 (size - 4); switch (GST_READ_UINT32_BE (data)) { case 0x0000FEFF: c = "UTF-32BE"; break; case 0xFFFE0000: c = "UTF-32LE"; break; default: break; } } if (!c) { prefix = 2; ssize = GST_ROUND_DOWN_2 (size - 2); switch (GST_READ_UINT16_BE (data)) { case 0xFEFF: c = "UTF-16BE"; break; case 0xFFFE: c = "UTF-16LE"; break; default: break; } } if (c) { GST_LOG ("Trying to convert freeform string to UTF-8 from '%s'", c); if ((utf8 = g_convert (data + prefix, ssize, "UTF-8", c, &bytes_read, NULL, NULL))) { if (bytes_read == ssize) goto beach; g_free (utf8); utf8 = NULL; } } } while (env_vars && *env_vars != NULL) { const gchar *env = NULL; /* Try charsets specified via the environment */ env = g_getenv (*env_vars); if (env != NULL && *env != '\0') { gchar **c, **csets; csets = g_strsplit (env, G_SEARCHPATH_SEPARATOR_S, -1); for (c = csets; c && *c; ++c) { GST_LOG ("Trying to convert freeform string to UTF-8 from '%s'", *c); if ((utf8 = g_convert (data, size, "UTF-8", *c, &bytes_read, NULL, NULL))) { if (bytes_read == size) { g_strfreev (csets); goto beach; } g_free (utf8); utf8 = NULL; } } g_strfreev (csets); } ++env_vars; } /* Try current locale (if not UTF-8) */ if (!g_get_charset (&cur_loc)) { GST_LOG ("Trying to convert freeform string using locale ('%s')", cur_loc); if ((utf8 = g_locale_to_utf8 (data, size, &bytes_read, NULL, NULL))) { if (bytes_read == size) { goto beach; } g_free (utf8); utf8 = NULL; } } /* Try Windows-1252 (which is a superset of ISO 8859-1 that uses a control * character range in ISO 8859-1 for more printable characters) */ { GError *err = NULL; GST_LOG ("Trying to convert freeform string using Windows-1252/ISO-8859-1 " "fallback"); utf8 = g_convert (data, size, "UTF-8", "WINDOWS-1252", &bytes_read, NULL, &err); if (err != NULL) { /* fallback in case iconv implementation doesn't support windows-1252 * for some reason */ if (err->code == G_CONVERT_ERROR_NO_CONVERSION) { g_free (utf8); utf8 = g_convert (data, size, "UTF-8", "ISO-8859-1", &bytes_read, NULL, NULL); } g_error_free (err); } if (utf8 != NULL && bytes_read == size) goto beach; } g_free (utf8); return NULL; beach: g_strchomp (utf8); if (utf8 && utf8[0] != '\0') { GST_LOG ("Returning '%s'", utf8); return utf8; } g_free (utf8); return NULL; }
gboolean is_unity() { return g_strcmp0(g_getenv("XDG_CURRENT_DESKTOP"), "Unity") == 0; }
int main (int argc, char **argv) { GtkWidget *window; GtkWidget *collection; GError *err; clock_t start, end; GtkWidget *notebook; int i; bindtextdomain (GETTEXT_PACKAGE, MARCO_LOCALEDIR); textdomain(GETTEXT_PACKAGE); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); run_position_expression_tests (); #if 0 run_position_expression_timings (); #endif gtk_init (&argc, &argv); if (g_getenv ("MARCO_DEBUG") != NULL) { meta_set_debugging (TRUE); meta_set_verbose (TRUE); } start = clock (); err = NULL; if (argc == 1) global_theme = meta_theme_load ("ClearlooksRe", &err); else if (argc == 2) global_theme = meta_theme_load (argv[1], &err); else { g_printerr (_("Usage: marco-theme-viewer [THEMENAME]\n")); exit (1); } end = clock (); if (global_theme == NULL) { g_printerr (_("Error loading theme: %s\n"), err->message); g_error_free (err); exit (1); } g_print (_("Loaded theme \"%s\" in %g seconds\n"), global_theme->name, (end - start) / (double) CLOCKS_PER_SEC); run_theme_benchmark (); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 350, 350); if (strcmp (global_theme->name, global_theme->readable_name)==0) gtk_window_set_title (GTK_WINDOW (window), global_theme->readable_name); else { /* The theme directory name is different from the name the theme * gives itself within its file. Display both, directory name first. */ gchar *title = g_strconcat (global_theme->name, " - ", global_theme->readable_name, NULL); gtk_window_set_title (GTK_WINDOW (window), title); g_free (title); } g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_realize (window); g_assert (window->style); g_assert (window->style->font_desc); notebook = gtk_notebook_new (); gtk_container_add (GTK_CONTAINER (window), notebook); collection = preview_collection (FONT_SIZE_NORMAL, window->style->font_desc); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Normal Title Font"))); collection = preview_collection (FONT_SIZE_SMALL, window->style->font_desc); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Small Title Font"))); collection = preview_collection (FONT_SIZE_LARGE, window->style->font_desc); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Large Title Font"))); collection = previews_of_button_layouts (); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Button Layouts"))); collection = benchmark_summary (); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Benchmark"))); i = 0; while (i < (int) G_N_ELEMENTS (previews)) { /* preview widget likes to be realized before its size request. * it's lame that way. */ gtk_widget_realize (previews[i]); ++i; } gtk_widget_show_all (window); gtk_main (); return 0; }
static void run_position_expression_tests (void) { #if 0 int i; MetaPositionExprEnv env; i = 0; while (i < (int) G_N_ELEMENTS (position_expression_tests)) { GError *err; gboolean retval; const PositionExpressionTest *test; PosToken *tokens; int n_tokens; int x, y; test = &position_expression_tests[i]; if (g_getenv ("META_PRINT_TESTS") != NULL) g_print ("Test expression: \"%s\" expecting x = %d y = %d", test->expr, test->expected_x, test->expected_y); err = NULL; env.rect = meta_rect (test->rect.x, test->rect.y, test->rect.width, test->rect.height); env.object_width = -1; env.object_height = -1; env.left_width = 0; env.right_width = 0; env.top_height = 0; env.bottom_height = 0; env.title_width = 5; env.title_height = 5; env.icon_width = 32; env.icon_height = 32; env.mini_icon_width = 16; env.mini_icon_height = 16; env.theme = NULL; if (err == NULL) { retval = meta_parse_position_expression (tokens, n_tokens, &env, &x, &y, &err); } if (retval && err) g_error (_("position expression test returned TRUE but set error")); if (!retval && err == NULL) g_error (_("position expression test returned FALSE but didn't set error")); if (((int) test->expected_error) != NO_ERROR) { if (err == NULL) g_error (_("Error was expected but none given")); if (err->code != (int) test->expected_error) g_error (_("Error %d was expected but %d given"), test->expected_error, err->code); } else { if (err) g_error (_("Error not expected but one was returned: %s"), err->message); if (x != test->expected_x) g_error (_("x value was %d, %d was expected"), x, test->expected_x); if (y != test->expected_y) g_error (_("y value was %d, %d was expected"), y, test->expected_y); } if (err) g_error_free (err); meta_pos_tokens_free (tokens, n_tokens); ++i; } #endif }
static GPtrArray * gs_plugin_steam_parse_appinfo_file (const gchar *filename, GError **error) { GPtrArray *apps; GHashTable *app = NULL; const gchar *tmp; guint8 *data = NULL; gsize data_len = 0; guint i = 0; gboolean debug = g_getenv ("GS_PLUGIN_STEAM_DEBUG") != NULL; /* load file */ if (!g_file_get_contents (filename, (gchar **) &data, &data_len, error)) { gs_utils_error_convert_gio (error); return NULL; } /* a GPtrArray of GHashTable */ apps = g_ptr_array_new_with_free_func ((GDestroyNotify) g_hash_table_unref); /* find the first application and avoid header */ gs_plugin_steam_find_next_sync_point (data, data_len, &i); for (i = i + 1; i < data_len; i++) { if (debug) g_debug ("%04x {0x%02x} %s", i, data[i], gs_plugin_steam_token_kind_to_str (data[i])); if (data[i] == GS_PLUGIN_STEAM_TOKEN_START) { /* this is a new application/game */ if (data[i+1] == 0x02) { /* reset */ app = gs_plugin_steam_add_app (apps); i++; continue; } /* new group */ if (g_ascii_isprint (data[i+1])) { tmp = gs_plugin_steam_consume_string (data, data_len, &i); if (debug) g_debug ("[%s] {", tmp); continue; } /* something went wrong */ if (debug) g_debug ("CORRUPTION DETECTED"); gs_plugin_steam_find_next_sync_point (data, data_len, &i); continue; } if (data[i] == GS_PLUGIN_STEAM_TOKEN_END) { if (debug) g_debug ("}"); continue; } if (data[i] == GS_PLUGIN_STEAM_TOKEN_STRING) { const gchar *value; tmp = gs_plugin_steam_consume_string (data, data_len, &i); value = gs_plugin_steam_consume_string (data, data_len, &i); if (debug) g_debug ("\t%s=%s", tmp, value); if (tmp != NULL && value != NULL) { if (g_hash_table_lookup (app, tmp) != NULL) continue; g_hash_table_insert (app, g_strdup (tmp), g_variant_new_string (value)); } continue; } if (data[i] == GS_PLUGIN_STEAM_TOKEN_INTEGER) { guint32 value; tmp = gs_plugin_steam_consume_string (data, data_len, &i); value = gs_plugin_steam_consume_uint32 (data, data_len, &i); if (debug) g_debug ("\t%s=%u", tmp, value); if (tmp != NULL) { if (g_hash_table_lookup (app, tmp) != NULL) continue; g_hash_table_insert (app, g_strdup (tmp), g_variant_new_uint32 (value)); } continue; } } return apps; }
/* * na_desktop_environment_detect_running_desktop: * * Have asked on xdg-list how to identify the currently running desktop environment * (see http://standards.freedesktop.org/menu-spec/latest/apb.html) * For now, just reproduce the xdg-open algorythm from xdg-utils 1.0 */ const gchar * na_desktop_environment_detect_running_desktop( void ) { static const gchar *thisfn = "na_desktop_environment_detect_running_desktop"; const gchar *value; gchar *output_str, *error_str; gint exit_status; GError *error; gboolean ok; int i; value = g_getenv( "XDG_CURRENT_DESKTOP" ); if( value && strlen( value )){ for( i = 0 ; st_desktops[i].id ; ++i ){ if( !strcmp( st_desktops[i].id, value )){ return( st_desktops[i].id ); } } } value = g_getenv( "KDE_FULL_SESSION" ); if( value && !strcmp( value, "true" )){ return( DESKTOP_KDE ); } /* MATE_DESKTOP_SESSION_ID=this-is-deprecated */ value = g_getenv( "MATE_DESKTOP_SESSION_ID" ); if( value && strlen( value )){ return( DESKTOP_MATE ); } value = g_getenv( "DESKTOP_SESSION" ); if( value ){ if( !strcmp( value, "mate" )){ return( DESKTOP_MATE ); } if( !strcmp( value, "xfce" )){ return( DESKTOP_XFCE ); } } output_str = NULL; error_str = NULL; error = NULL; if( g_spawn_command_line_sync( "dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.mate.SessionManager", &output_str, &error_str, &exit_status, &error )){ ok = ( exit_status == 0 && output_str && strlen( output_str ) && ( !error_str || !strlen( error_str ))); g_free( output_str ); g_free( error_str ); if( ok ){ return( DESKTOP_MATE ); } } if( error ){ g_warning( "%s: dbus-send: %s", thisfn, error->message ); g_error_free( error ); } output_str = NULL; error_str = NULL; error = NULL; if( g_spawn_command_line_sync( "xprop -root _DT_SAVE_MODE", &output_str, &error_str, &exit_status, &error )){ ok = ( exit_status == 0 && output_str && strlen( output_str ) && ( !error_str || !strlen( error_str ))); if( ok ){ ok = ( g_strstr_len( output_str, -1, "xfce" ) != NULL ); } g_free( output_str ); g_free( error_str ); if( ok ){ return( DESKTOP_XFCE ); } } if( error ){ g_warning( "%s: xprop: %s", thisfn, error->message ); g_error_free( error ); } /* do not know how to identify ROX * this one and other desktops are just identified as 'Old' (legacy systems) */ return( DESKTOP_OLD ); }
static gboolean gs_plugin_steam_refresh (GsPlugin *plugin, guint cache_age, GCancellable *cancellable, GError **error) { g_autoptr(AsStore) store = NULL; g_autoptr(GFile) file = NULL; g_autoptr(GPtrArray) apps = NULL; g_autofree gchar *fn = NULL; g_autofree gchar *fn_xml = NULL; /* check if exists */ fn = g_build_filename (g_get_user_data_dir (), "Steam", "appcache", "appinfo.vdf", NULL); if (!g_file_test (fn, G_FILE_TEST_EXISTS)) { g_debug ("no %s, so skipping", fn); return TRUE; } /* test cache age */ fn_xml = g_build_filename (g_get_user_data_dir (), "app-info", "xmls", "steam.xml.gz", NULL); file = g_file_new_for_path (fn_xml); if (cache_age > 0) { guint tmp; tmp = gs_utils_get_file_age (file); if (tmp < cache_age) { g_debug ("%s is only %u seconds old, so ignoring refresh", fn_xml, tmp); return TRUE; } } /* parse it */ apps = gs_plugin_steam_parse_appinfo_file (fn, error); if (apps == NULL) return FALSE; /* debug */ if (g_getenv ("GS_PLUGIN_STEAM_DEBUG") != NULL) gs_plugin_steam_dump_apps (apps); /* load existing AppStream XML */ store = as_store_new (); as_store_set_origin (store, "steam"); if (g_file_query_exists (file, cancellable)) { if (!as_store_from_file (store, file, NULL, cancellable, error)) return FALSE; } /* update any new applications */ if (!gs_plugin_steam_update_store (plugin, store, apps, error)) return FALSE; /* save new file */ if (!as_store_to_file (store, file, AS_NODE_TO_XML_FLAG_FORMAT_INDENT | AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE, NULL, error)) { gs_utils_error_convert_appstream (error); return FALSE; } return TRUE; }
int main (int argc, char **argv) { int c; char *config_dir = DEFAULT_CONFIG_DIR; char *seafile_dir = NULL; char *logfile = NULL; const char *debug_str = NULL; int daemon_mode = 1; int is_master = 0; CcnetClient *client; char *ccnet_debug_level_str = "info"; char *seafile_debug_level_str = "debug"; int cloud_mode = 0; #ifdef WIN32 argv = get_argv_utf8 (&argc); #endif while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) != EOF) { switch (c) { case 'h': exit (1); break; case 'v': exit (1); break; case 'c': config_dir = optarg; break; case 'd': seafile_dir = g_strdup(optarg); break; case 'f': daemon_mode = 0; break; case 'l': logfile = g_strdup(optarg); break; case 'D': debug_str = optarg; break; case 'g': ccnet_debug_level_str = optarg; break; case 'G': seafile_debug_level_str = optarg; break; case 'm': is_master = 1; case 'P': pidfile = optarg; break; case 'C': cloud_mode = 1; break; default: usage (); exit (1); } } argc -= optind; argv += optind; #ifndef WIN32 if (daemon_mode) daemon (1, 0); #endif cdc_init (); g_type_init (); #if !GLIB_CHECK_VERSION(2,32,0) g_thread_init (NULL); #endif if (!debug_str) debug_str = g_getenv("SEAFILE_DEBUG"); seafile_debug_set_flags_string (debug_str); if (seafile_dir == NULL) seafile_dir = g_build_filename (config_dir, "seafile", NULL); if (logfile == NULL) logfile = g_build_filename (seafile_dir, "seafile.log", NULL); if (seafile_log_init (logfile, ccnet_debug_level_str, seafile_debug_level_str) < 0) { seaf_warning ("Failed to init log.\n"); exit (1); } client = ccnet_init (config_dir); if (!client) exit (1); register_processors (client); start_rpc_service (client, cloud_mode); create_sync_rpc_clients (config_dir); create_async_rpc_clients (client); seaf = seafile_session_new (seafile_dir, client); if (!seaf) { seaf_warning ("Failed to create seafile session.\n"); exit (1); } seaf->is_master = is_master; seaf->ccnetrpc_client = ccnetrpc_client; seaf->async_ccnetrpc_client = async_ccnetrpc_client; seaf->ccnetrpc_client_t = ccnetrpc_client_t; seaf->async_ccnetrpc_client_t = async_ccnetrpc_client_t; seaf->client_pool = ccnet_client_pool_new (config_dir); seaf->cloud_mode = cloud_mode; load_history_config (); g_free (seafile_dir); g_free (logfile); set_signal_handlers (seaf); /* init seaf */ if (seafile_session_init (seaf) < 0) exit (1); if (seafile_session_start (seaf) < 0) exit (1); if (pidfile) { if (write_pidfile (pidfile) < 0) { ccnet_message ("Failed to write pidfile\n"); return -1; } } atexit (on_seaf_server_exit); ccnet_main (client); return 0; }
int main(int argc, char *argv[]) { evbase_t *evbase = NULL; evhtp_t *htp = NULL; int daemon_mode = 1; int c; char *logfile = NULL; char *ccnet_debug_level_str = "info"; char *http_debug_level_str = "debug"; const char *debug_str = NULL; char *temp_file_dir = NULL; #ifdef WIN32 argv = get_argv_utf8 (&argc); #endif config_dir = DEFAULT_CONFIG_DIR; while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != EOF) { switch (c) { case 'h': usage(); exit(0); case 'v': exit(-1); break; case 'c': config_dir = strdup(optarg); break; case 'd': seafile_dir = strdup(optarg); break; case 't': num_threads = atoi(optarg); break; case 'f': daemon_mode = 0; break; case 'l': logfile = g_strdup(optarg); break; case 'g': ccnet_debug_level_str = optarg; break; case 'G': http_debug_level_str = optarg; break; case 'D': debug_str = optarg; break; case 'k': temp_file_dir = optarg; break; case 'P': pidfile = optarg; break; default: usage(); exit(-1); } } #if !defined(WIN32) && !defined(__APPLE__) if (daemon_mode) daemon(1, 0); #endif #ifdef WIN32 WSADATA wsadata; WSAStartup(0x0101, &wsadata); #endif #if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init(); #endif if (!debug_str) debug_str = g_getenv("SEAFILE_DEBUG"); seafile_debug_set_flags_string (debug_str); if (seafile_dir == NULL) seafile_dir = g_build_filename (config_dir, "seafile-data", NULL); if (logfile == NULL) logfile = g_build_filename (seafile_dir, "http.log", NULL); if (seafile_log_init (logfile, ccnet_debug_level_str, http_debug_level_str) < 0) { g_warning ("Failed to init log.\n"); exit (1); } ccnet_client = ccnet_client_new(); if ((ccnet_client_load_confdir(ccnet_client, config_dir)) < 0) { g_warning ("Read config dir error\n"); return -1; } seaf = seafile_session_new (seafile_dir, ccnet_client); if (!seaf) { g_warning ("Failed to create seafile session.\n"); exit (1); } if (seafile_session_init(seaf) < 0) exit (1); if (temp_file_dir == NULL) seaf->http_temp_dir = g_build_filename (seaf->seaf_dir, "httptemp", NULL); else seaf->http_temp_dir = g_strdup(temp_file_dir); seaf->client_pool = ccnet_client_pool_new (config_dir); load_httpserver_config (seaf); if (use_https) { seaf_message ("host = %s, port = %d, https = true, pemfile = %s, privkey = %s\n", bind_addr, bind_port, pemfile, privkey); } else { seaf_message ("host = %s, port = %d, https = false\n", bind_addr, bind_port); } evbase = event_base_new(); htp = evhtp_new(evbase, NULL); if (pemfile != NULL) { evhtp_ssl_cfg_t scfg; memset (&scfg, 0, sizeof(scfg)); scfg.pemfile = pemfile; scfg.privfile = privkey; scfg.scache_type = evhtp_ssl_scache_type_internal; scfg.scache_timeout = 5000; evhtp_ssl_init (htp, &scfg); } if (access_file_init (htp) < 0) exit (1); if (upload_file_init (htp) < 0) exit (1); evhtp_set_gencb(htp, default_cb, NULL); evhtp_use_threads(htp, NULL, num_threads, NULL); if (evhtp_bind_socket(htp, bind_addr, bind_port, 128) < 0) { g_warning ("Could not bind socket: %s\n", strerror(errno)); exit(-1); } if (pidfile) { if (write_pidfile (pidfile) < 0) { seaf_message ("Failed to write pidfile\n"); return -1; } } atexit (on_httpserver_exit); event_base_loop(evbase, 0); return 0; }
int main (int argc, char *argv[]) { guint32 startup_timestamp; EmpathyStatusIcon *icon; EmpathyDispatcher *dispatcher; GtkWidget *window; MissionControl *mc; EmpathyIdle *idle; gboolean autoconnect = TRUE; gboolean no_connect = FALSE; gboolean hide_contact_list = FALSE; GError *error = NULL; GOptionEntry options[] = { { "no-connect", 'n', 0, G_OPTION_ARG_NONE, &no_connect, N_("Don't connect on startup"), NULL }, { "hide-contact-list", 'h', 0, G_OPTION_ARG_NONE, &hide_contact_list, N_("Don't show the contact list on startup"), NULL }, { NULL } }; bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); startup_timestamp = get_startup_timestamp (); if (!gtk_init_with_args (&argc, &argv, _("- Empathy Instant Messenger"), options, GETTEXT_PACKAGE, &error)) { g_warning ("Error in gtk init: %s", error->message); return EXIT_FAILURE; } if (g_getenv ("EMPATHY_TIMING") != NULL) { g_log_set_default_handler (tp_debug_timestamped_log_handler, NULL); } empathy_debug_set_flags (g_getenv ("EMPATHY_DEBUG")); tp_debug_divert_messages (g_getenv ("EMPATHY_LOGFILE")); g_set_application_name (PACKAGE_NAME); gtk_window_set_default_icon_name ("empathy"); gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), PKGDATADIR G_DIR_SEPARATOR_S "icons"); /* Setting up the bacon connection */ connection = bacon_message_connection_new ("empathy"); if (connection != NULL) { if (!bacon_message_connection_get_is_server (connection)) { gchar *message; DEBUG ("Activating existing instance"); message = g_strdup_printf ("%" G_GUINT32_FORMAT, startup_timestamp); bacon_message_connection_send (connection, message); /* We never popup a window, so tell startup-notification * that we are done. */ gdk_notify_startup_complete (); g_free (message); bacon_message_connection_free (connection); return EXIT_SUCCESS; } } else { g_warning ("Cannot create the 'empathy' bacon connection."); } /* Setting up MC */ mc = empathy_mission_control_new (); g_signal_connect (mc, "ServiceEnded", G_CALLBACK (service_ended_cb), NULL); g_signal_connect (mc, "Error", G_CALLBACK (operation_error_cb), NULL); /* Setting up Idle */ idle = empathy_idle_new (); empathy_idle_set_auto_away (idle, TRUE); use_nm_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_NM, idle); empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_NM, use_nm_notify_cb, idle); /* Autoconnect */ empathy_conf_get_bool (empathy_conf_get(), EMPATHY_PREFS_AUTOCONNECT, &autoconnect); if (autoconnect && ! no_connect && empathy_idle_get_state (idle) <= MC_PRESENCE_OFFLINE) { empathy_idle_set_state (idle, MC_PRESENCE_AVAILABLE); } create_salut_account (); /* Setting up UI */ window = empathy_main_window_show (); icon = empathy_status_icon_new (GTK_WINDOW (window), hide_contact_list); if (connection) { /* We se the callback here because we need window */ bacon_message_connection_set_callback (connection, on_bacon_message_received, window); } /* Handle channels */ dispatcher = empathy_dispatcher_new (); g_signal_connect (dispatcher, "dispatch-channel", G_CALLBACK (dispatch_channel_cb), NULL); gtk_main (); empathy_idle_set_state (idle, MC_PRESENCE_OFFLINE); g_object_unref (mc); g_object_unref (idle); g_object_unref (icon); g_object_unref (dispatcher); return EXIT_SUCCESS; }
static void clutter_backend_real_init_events (ClutterBackend *backend) { const char *input_backend = NULL; input_backend = g_getenv ("CLUTTER_INPUT_BACKEND"); if (input_backend != NULL) input_backend = g_intern_string (input_backend); #ifdef CLUTTER_INPUT_OSX if (clutter_check_windowing_backend (CLUTTER_WINDOWING_OSX) && (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_OSX))) { _clutter_backend_osx_events_init (backend); } else #endif #ifdef CLUTTER_INPUT_WIN32 if (clutter_check_windowing_backend (CLUTTER_WINDOWING_WIN32) && (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_WIN32))) { _clutter_backend_win32_events_init (backend); } else #endif #ifdef CLUTTER_INPUT_X11 if (clutter_check_windowing_backend (CLUTTER_WINDOWING_X11) && (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_X11))) { _clutter_backend_x11_events_init (backend); } else #endif #ifdef CLUTTER_INPUT_GDK if (clutter_check_windowing_backend (CLUTTER_WINDOWING_GDK) && (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_GDK))) { _clutter_backend_gdk_events_init (backend); } else #endif #ifdef CLUTTER_INPUT_EVDEV /* Evdev can be used regardless of the windowing system */ if ((input_backend != NULL && strcmp (input_backend, CLUTTER_INPUT_EVDEV) == 0) #ifdef CLUTTER_WINDOWING_EGL /* but we do want to always use it for EGL native */ || clutter_check_windowing_backend (CLUTTER_WINDOWING_EGL) #endif ) { _clutter_events_evdev_init (backend); } else #endif #ifdef CLUTTER_INPUT_TSLIB /* Tslib can be used regardless of the windowing system */ if (input_backend != NULL && strcmp (input_backend, CLUTTER_INPUT_TSLIB) == 0) { _clutter_events_tslib_init (backend); } else #endif #ifdef CLUTTER_INPUT_WAYLAND if (clutter_check_windowing_backend (CLUTTER_WINDOWING_WAYLAND) && (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_WAYLAND))) { _clutter_events_wayland_init (backend); } else #endif #ifdef CLUTTER_INPUT_MIR if (clutter_check_windowing_backend (CLUTTER_WINDOWING_MIR) && (input_backend == NULL || input_backend == I_(CLUTTER_INPUT_MIR))) { _clutter_events_mir_init (backend); } else #endif if (input_backend != NULL) { if (input_backend != I_(CLUTTER_INPUT_NULL)) g_error ("Unrecognized input backend '%s'", input_backend); } else g_error ("Unknown input backend"); }
static GstVaapiDisplay * gst_vaapi_create_display_from_gl_context (GstObject * gl_context_object) { #if USE_GST_GL_HELPERS GstGLContext *const gl_context = GST_GL_CONTEXT (gl_context_object); GstGLDisplay *const gl_display = gst_gl_context_get_display (gl_context); gpointer native_display = GSIZE_TO_POINTER (gst_gl_display_get_handle (gl_display)); GstVaapiDisplay *display, *out_display; GstVaapiDisplayType display_type; switch (gst_gl_display_get_handle_type (gl_display)) { #if USE_X11 case GST_GL_DISPLAY_TYPE_X11: display_type = GST_VAAPI_DISPLAY_TYPE_X11; break; #endif #if USE_WAYLAND case GST_GL_DISPLAY_TYPE_WAYLAND: display_type = GST_VAAPI_DISPLAY_TYPE_WAYLAND; break; #endif case GST_GL_DISPLAY_TYPE_ANY:{ /* Derive from the active window */ GstGLWindow *const gl_window = gst_gl_context_get_window (gl_context); const gchar *const gl_window_type = g_getenv ("GST_GL_WINDOW"); display_type = GST_VAAPI_DISPLAY_TYPE_ANY; if (!gl_window) break; native_display = GSIZE_TO_POINTER (gst_gl_window_get_display (gl_window)); if (gl_window_type) { #if USE_X11 if (!display_type && g_strcmp0 (gl_window_type, "x11") == 0) display_type = GST_VAAPI_DISPLAY_TYPE_X11; #endif #if USE_WAYLAND if (!display_type && g_strcmp0 (gl_window_type, "wayland") == 0) display_type = GST_VAAPI_DISPLAY_TYPE_WAYLAND; #endif } else { #if USE_X11 if (!display_type && GST_GL_HAVE_WINDOW_X11) display_type = GST_VAAPI_DISPLAY_TYPE_X11; #endif #if USE_WAYLAND if (!display_type && GST_GL_HAVE_WINDOW_WAYLAND) display_type = GST_VAAPI_DISPLAY_TYPE_WAYLAND; #endif } break; } default: display_type = GST_VAAPI_DISPLAY_TYPE_ANY; break; } if (!display_type) return NULL; display = gst_vaapi_create_display_from_handle (display_type, native_display); if (!display) return NULL; switch (gst_gl_context_get_gl_platform (gl_context)) { #if USE_EGL case GST_GL_PLATFORM_EGL:{ guint gles_version; switch (gst_gl_context_get_gl_api (gl_context)) { case GST_GL_API_GLES1: gles_version = 1; goto create_egl_display; case GST_GL_API_GLES2: gles_version = 2; goto create_egl_display; case GST_GL_API_OPENGL: case GST_GL_API_OPENGL3: gles_version = 0; create_egl_display: out_display = gst_vaapi_display_egl_new (display, gles_version); break; default: out_display = NULL; break; } if (!out_display) return NULL; gst_vaapi_display_egl_set_gl_context (GST_VAAPI_DISPLAY_EGL (out_display), GSIZE_TO_POINTER (gst_gl_context_get_gl_context (gl_context))); break; } #endif default: out_display = gst_vaapi_display_ref (display); break; } gst_vaapi_display_unref (display); return out_display; #endif GST_ERROR ("unsupported GStreamer version %s", GST_API_VERSION_S); return NULL; }
static gboolean spawn_session (State *state, gboolean run_script, GCancellable *cancellable) { GSubprocessLauncher *launcher = NULL; GSubprocess *subprocess = NULL; GError *error = NULL; gboolean is_running = FALSE; const char *vt; g_debug ("Running X session"); launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE); g_subprocess_launcher_setenv (launcher, "DISPLAY", state->display_name, TRUE); g_subprocess_launcher_setenv (launcher, "XAUTHORITY", state->auth_file, TRUE); if (state->environment != NULL) { size_t i; for (i = 0; state->environment[i] != NULL; i++) { g_auto(GStrv) environment_entry = NULL; if (state->environment[i] == '\0') { continue; } environment_entry = g_strsplit (state->environment[i], "=", 2); if (environment_entry[0] == NULL || environment_entry[1] == NULL) { continue; } g_subprocess_launcher_setenv (launcher, environment_entry[0], environment_entry[1], FALSE); } } if (state->bus_address != NULL) { g_subprocess_launcher_setenv (launcher, "DBUS_SESSION_BUS_ADDRESS", state->bus_address, TRUE); } vt = g_getenv ("XDG_VTNR"); if (vt != NULL) { g_subprocess_launcher_setenv (launcher, "WINDOWPATH", vt, TRUE); } if (run_script) { subprocess = g_subprocess_launcher_spawn (launcher, &error, GDMCONFDIR "/Xsession", state->session_command, NULL); } else { int ret; char **argv; ret = g_shell_parse_argv (state->session_command, NULL, &argv, &error); if (!ret) { g_debug ("could not parse session arguments: %s", error->message); goto out; } subprocess = g_subprocess_launcher_spawnv (launcher, (const char * const *) argv, &error); g_strfreev (argv); } if (subprocess == NULL) { g_debug ("could not start session: %s", error->message); goto out; } state->session_subprocess = g_object_ref (subprocess); g_subprocess_wait_async (state->session_subprocess, cancellable, (GAsyncReadyCallback) on_session_finished, state); is_running = TRUE; out: g_clear_object (&subprocess); return is_running; }
/* create a new tab */ static void tab_new(struct window *w) { term *t; int tmp; char **args = 0; const gchar *shell = g_getenv("SHELL"); if (!shell) { shell = "sh"; } g_shell_parse_argv(shell, 0, &args, 0); t = g_new0(term, 1); t->label = gtk_label_new(""); t->w = w; t->vte = vte_terminal_new(); int index = gtk_notebook_append_page(GTK_NOTEBOOK(w->notebook), t->vte, t->label); gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(w->notebook), t->vte, TRUE); if (index == 0) { gtk_notebook_set_show_tabs(GTK_NOTEBOOK(w->notebook), FALSE); vte_terminal_fork_command_full(VTE_TERMINAL(t->vte), VTE_PTY_DEFAULT, NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, t->pid, NULL); tab_geometry_hints(t); } else { struct term *previous = get_nth_term(w, gtk_notebook_get_current_page(GTK_NOTEBOOK(w->notebook))); vte_terminal_fork_command_full(VTE_TERMINAL(t->vte), VTE_PTY_DEFAULT, tab_get_cwd(previous), args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, t->pid, NULL); gtk_notebook_set_show_tabs(GTK_NOTEBOOK(w->notebook), TRUE); } g_object_set_qdata_full(G_OBJECT(gtk_notebook_get_nth_page( (GtkNotebook*)w->notebook, index)), term_data_id, t, NULL); g_signal_connect(G_OBJECT(t->vte), "child-exited", G_CALLBACK(tab_close), w); g_signal_connect(G_OBJECT(t->vte), "window-title-changed", G_CALLBACK(tab_title), t); g_signal_connect(G_OBJECT(t->vte), "button-press-event", G_CALLBACK(event_button), NULL); vte_terminal_set_allow_bold(VTE_TERMINAL(t->vte), config->allow_bold); vte_terminal_set_audible_bell(VTE_TERMINAL(t->vte), config->audible_bell); vte_terminal_set_background_transparent(VTE_TERMINAL(t->vte), config->bg_transparent); vte_terminal_set_background_saturation(VTE_TERMINAL(t->vte), config->bg_saturation); vte_terminal_set_background_image_file(VTE_TERMINAL(t->vte), config->bg_image); vte_terminal_set_font_from_string(VTE_TERMINAL(t->vte), config->font); vte_terminal_set_mouse_autohide(VTE_TERMINAL(t->vte), config->autohide_mouse); vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(t->vte), config->scroll_on_keystroke); vte_terminal_set_scroll_on_output(VTE_TERMINAL(t->vte), config->scroll_on_output); vte_terminal_set_scrollback_lines(VTE_TERMINAL(t->vte), config->num_scrollback_lines); vte_terminal_set_visible_bell(VTE_TERMINAL(t->vte), config->visible_bell); vte_terminal_set_word_chars(VTE_TERMINAL(t->vte), config->word_chars); vte_terminal_set_colors(VTE_TERMINAL(t->vte), &config->foreground, &config->background, config->colour_palette, DEFAULT_PALETTE_SIZE); tmp = vte_terminal_match_add_gregex( VTE_TERMINAL(t->vte), g_regex_new(config->url_regex, G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY, NULL), 0); vte_terminal_match_set_cursor_type(VTE_TERMINAL(t->vte), tmp, GDK_HAND2); gtk_widget_show_all(w->notebook); gtk_notebook_set_current_page(GTK_NOTEBOOK(w->notebook), index); gtk_widget_grab_focus(t->vte); }
// it will return TRUE if scucceed gboolean send_socket( int argc, char *argv[], gboolean wait) { #ifdef DETAIL g_debug("! Launch send_socket() to send data to the exiting LilyTerm !"); g_debug("! send_socket() argc = %d, wait = %d", argc, wait); print_array("! send_socket() argv", argv); #endif GError *error = NULL; gsize len; extern gchar **environ; gchar *locale_list = get_locale_list(); const gchar *VTE_CJK_WIDTH_STR = g_getenv("VTE_CJK_WIDTH"); // VTE_CJK_WIDTH can't = NULL if (VTE_CJK_WIDTH_STR == NULL) VTE_CJK_WIDTH_STR = ""; // g_debug("Got LOCALE = %s in send_socket...", get_encoding_from_locale(NULL)); gchar *encoding = get_encoding_from_locale(NULL); if (! compare_strings(encoding, "ANSI_X3.4-1968", TRUE)) { g_free(encoding); encoding = g_strdup("UTF-8"); } // g_debug("Got encoding = %s in send_socket...", encoding); gchar *lc_messages = g_strdup(get_default_lc_data(LC_MESSAGES)); gchar *environ_str = convert_array_to_string(environ, '\t'); // print_array("! send_socket() environ", environ); // g_debug("environ_str = %s", environ_str); gchar *argv_str = convert_array_to_string(argv, '\x10'); #ifdef SAFEMODE gboolean need_free_argv_str = TRUE; if (argv_str==NULL) argv_str=g_strdup(""); if (argv_str==NULL) { need_free_argv_str = FALSE; argv_str = ""; } #endif // g_debug("argv_str = %s", argv_str); // g_debug("SEND DATA: SOCKET_DATA_VERSION = %s", SOCKET_DATA_VERSION); // g_debug("SEND DATA: locale_list = %s", locale_list); // g_debug("SEND DATA: encoding = %s", encoding); // g_debug("SEND DATA: PWD = %s", PWD); // g_debug("SEND DATA: VTE_CJK_WIDTH_STR = %s", VTE_CJK_WIDTH_STR); // g_debug("SEND DATA: wmclass_name = %s", wmclass_name); // g_debug("SEND DATA: wmclass_class = %s", wmclass_class); // g_debug("SEND DATA: environ_str = %s", environ_str); // g_debug("SEND DATA: argv_str = %s", argv_str); // 0 1 2 3 4 5 6 7 8 9 10 11 // send data: SOCKET_DATA_VERSION SHELL LOCALE_LIST ENCODING LC_MESSAGES PWD HOME VTE_CJK_WIDTH_STR wmclass_name wmclass_class ENVIRON ARGV // 0 1 2 3 4 5 6 7 8 9 10 11 gchar *arg_str = g_strdup_printf("%s\x10%s\x10%s\x10%s\x10%s\x10%s\x10%s\x10%s\x10%s\x10%s\x10%s\x10%s\x10", SOCKET_DATA_VERSION, shell, locale_list, encoding, lc_messages, pwd, home, VTE_CJK_WIDTH_STR, wmclass_name, wmclass_class, environ_str, argv_str); // g_debug("arg_str = %s", arg_str); g_free(locale_list); g_free(encoding); g_free(lc_messages); g_free(environ_str); #ifdef SAFEMODE if (need_free_argv_str) #endif g_free(argv_str); // write data! #ifdef SAFEMODE if (fcntl(socket_fd, F_GETFL) < 0) return FALSE; #endif GIOChannel *channel = g_io_channel_unix_new(socket_fd); // main_channel is NULL, so that we don't need to launch clear_channel() if (!channel) return socket_fault(12, NULL, NULL, FALSE); // set the channel to read binary file if (g_io_channel_set_encoding(channel, NULL, &error) == G_IO_STATUS_ERROR) return socket_fault(9, error, channel, TRUE); g_io_channel_set_buffered (channel, FALSE); #ifdef SAFEMODE if ((arg_str == NULL) || (g_io_channel_write_chars(channel, arg_str, -1, &len, &error)==G_IO_STATUS_ERROR)) #else if (g_io_channel_write_chars(channel, arg_str, -1, &len, &error)==G_IO_STATUS_ERROR) #endif // main_channel is NULL, so that we don't need to launch clear_channel() return socket_fault(11, error, channel, TRUE); // flush writing datas if (g_io_channel_flush(channel, &error) == G_IO_STATUS_ERROR) // main_channel is NULL, so that we don't need to launch clear_channel() return socket_fault(13, error, channel, TRUE); g_free(arg_str); // So far so good. shutdown and clear channel! clear_channel(channel, TRUE); // FIXME: sleep for 1 sec to wait the socket server. any better idea? if (wait) sleep(1); return TRUE; }
//gboolean //gst_gl_context_create (GstGLContext * context, GstGLContext * other_context, GError ** error) static gpointer gst_gl_context_create_thread (GstGLContext * context) { GstGLContextClass *context_class; GstGLWindowClass *window_class; GstGLFuncs *gl; GstGLAPI compiled_api, user_api, gl_api, display_api; gchar *api_string; gchar *compiled_api_s; gchar *user_api_s; gchar *display_api_s; const gchar *user_choice; GError **error; GstGLContext *other_context; g_mutex_lock (&context->priv->render_lock); GST_DEBUG_OBJECT (context, "Creating thread"); error = context->priv->error; other_context = g_weak_ref_get (&context->priv->other_context_ref); context_class = GST_GL_CONTEXT_GET_CLASS (context); window_class = GST_GL_WINDOW_GET_CLASS (context->window); display_api = gst_gl_display_get_gl_api_unlocked (context->priv->display); if (display_api == GST_GL_API_NONE) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API, "Cannot create context with satisfying requested apis " "(display has no GL api!)"); goto failure; } if (window_class->open) { if (!window_class->open (context->window, error)) { GST_WARNING_OBJECT (context, "Failed to open window"); g_assert (error == NULL || *error != NULL); goto failure; } } gl = context->gl_vtable; compiled_api = _compiled_api (); compiled_api_s = gst_gl_api_to_string (compiled_api); user_choice = g_getenv ("GST_GL_API"); user_api = gst_gl_api_from_string (user_choice); user_api_s = gst_gl_api_to_string (user_api); display_api_s = gst_gl_api_to_string (display_api); if ((user_api & compiled_api & display_api) == GST_GL_API_NONE) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API, "Cannot create context with the user requested api (%s). " "We have support for (%s), display api (%s)", user_api_s, compiled_api_s, display_api_s); g_free (user_api_s); g_free (compiled_api_s); g_free (display_api_s); goto failure; } if (context_class->choose_format && !context_class->choose_format (context, error)) { GST_WARNING ("Failed to choose format"); g_assert (error == NULL || *error != NULL); g_free (compiled_api_s); g_free (user_api_s); g_free (display_api_s); goto failure; } GST_INFO_OBJECT (context, "Attempting to create opengl context. user chosen api(s) (%s), " "compiled api support (%s) display api (%s)", user_api_s, compiled_api_s, display_api_s); if (!context_class->create_context (context, compiled_api & user_api & display_api, other_context, error)) { GST_WARNING_OBJECT (context, "Failed to create context"); g_assert (error == NULL || *error != NULL); g_free (compiled_api_s); g_free (user_api_s); g_free (display_api_s); goto failure; } GST_INFO_OBJECT (context, "created context"); if (!gst_gl_context_activate (context, TRUE)) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE, "Failed to activate the GL Context"); g_free (compiled_api_s); g_free (user_api_s); g_free (display_api_s); goto failure; } gl_api = gst_gl_context_get_gl_api (context); g_assert (gl_api != GST_GL_API_NONE && gl_api != GST_GL_API_ANY); api_string = gst_gl_api_to_string (gl_api); GST_INFO_OBJECT (context, "available GL APIs: %s", api_string); if (((compiled_api & gl_api & display_api) & user_api) == GST_GL_API_NONE) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API, "failed to create context, context " "could not provide correct api. user (%s), compiled (%s), context (%s)", user_api_s, compiled_api_s, api_string); g_free (api_string); g_free (compiled_api_s); g_free (user_api_s); g_free (display_api_s); goto failure; } g_free (api_string); g_free (compiled_api_s); g_free (user_api_s); g_free (display_api_s); GST_DEBUG_OBJECT (context, "Filling info"); if (!gst_gl_context_fill_info (context, error)) { g_assert (error == NULL || *error != NULL); goto failure; } context->priv->alive = TRUE; if (gl->DebugMessageCallback) { #if !defined(GST_DISABLE_GST_DEBUG) GST_INFO_OBJECT (context, "Enabling GL context debugging"); /* enable them all */ gl->DebugMessageControl (GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, 0, GL_TRUE); gl->DebugMessageCallback (_gst_gl_debug_callback, context); #endif } if (other_context) { GST_DEBUG_OBJECT (context, "Unreffing other_context %" GST_PTR_FORMAT, other_context); gst_object_unref (other_context); } g_cond_signal (&context->priv->create_cond); // g_mutex_unlock (&context->priv->render_lock); gst_gl_window_send_message_async (context->window, (GstGLWindowCB) _unlock_create_thread, context, NULL); gst_gl_window_run (context->window); GST_INFO_OBJECT (context, "loop exited"); g_mutex_lock (&context->priv->render_lock); context->priv->alive = FALSE; gst_gl_context_activate (context, FALSE); context_class->destroy_context (context); /* User supplied callback */ if (context->window->close) context->window->close (context->window->close_data); /* window specific shutdown */ if (window_class->close) { window_class->close (context->window); } g_cond_signal (&context->priv->destroy_cond); g_mutex_unlock (&context->priv->render_lock); return NULL; failure: { if (other_context) gst_object_unref (other_context); g_cond_signal (&context->priv->create_cond); g_mutex_unlock (&context->priv->render_lock); return NULL; } }
gchar *get_locale_list() { #ifdef DETAIL g_debug("! Launch get_locale_list()!"); #endif #ifdef OUT_OF_MEMORY # undef g_getenv #endif return join_strings_to_string(' ', 14, g_getenv("LANG"), g_getenv("LC_CTYPE"), g_getenv("LC_NUMERIC"), g_getenv("LC_TIME"), g_getenv("LC_COLLATE"), g_getenv("LC_MONETARY"), g_getenv("LC_MESSAGES"), g_getenv("LC_PAPER"), g_getenv("LC_NAME"), g_getenv("LC_ADDRESS"), g_getenv("LC_TELEPHONE"), g_getenv("LC_MEASUREMENT"), g_getenv("LC_IDENTIFICATION"), g_getenv("LC_ALL")); #ifdef OUT_OF_MEMORY #define g_getenv(x) NULL #endif }
void gedit_debug_init (void) { if (g_getenv ("GEDIT_DEBUG") != NULL) { /* enable all debugging */ debug = ~GEDIT_NO_DEBUG; goto out; } if (g_getenv ("GEDIT_DEBUG_VIEW") != NULL) debug = debug | GEDIT_DEBUG_VIEW; if (g_getenv ("GEDIT_DEBUG_SEARCH") != NULL) debug = debug | GEDIT_DEBUG_SEARCH; if (g_getenv ("GEDIT_DEBUG_PREFS") != NULL) debug = debug | GEDIT_DEBUG_PREFS; if (g_getenv ("GEDIT_DEBUG_PRINT") != NULL) debug = debug | GEDIT_DEBUG_PRINT; if (g_getenv ("GEDIT_DEBUG_PLUGINS") != NULL) debug = debug | GEDIT_DEBUG_PLUGINS; if (g_getenv ("GEDIT_DEBUG_TAB") != NULL) debug = debug | GEDIT_DEBUG_TAB; if (g_getenv ("GEDIT_DEBUG_DOCUMENT") != NULL) debug = debug | GEDIT_DEBUG_DOCUMENT; if (g_getenv ("GEDIT_DEBUG_COMMANDS") != NULL) debug = debug | GEDIT_DEBUG_COMMANDS; if (g_getenv ("GEDIT_DEBUG_APP") != NULL) debug = debug | GEDIT_DEBUG_APP; if (g_getenv ("GEDIT_DEBUG_SESSION") != NULL) debug = debug | GEDIT_DEBUG_SESSION; if (g_getenv ("GEDIT_DEBUG_UTILS") != NULL) debug = debug | GEDIT_DEBUG_UTILS; if (g_getenv ("GEDIT_DEBUG_METADATA") != NULL) debug = debug | GEDIT_DEBUG_METADATA; if (g_getenv ("GEDIT_DEBUG_WINDOW") != NULL) debug = debug | GEDIT_DEBUG_WINDOW; if (g_getenv ("GEDIT_DEBUG_LOADER") != NULL) debug = debug | GEDIT_DEBUG_LOADER; if (g_getenv ("GEDIT_DEBUG_SAVER") != NULL) debug = debug | GEDIT_DEBUG_SAVER; out: #ifdef ENABLE_PROFILING if (debug != GEDIT_NO_DEBUG) timer = g_timer_new (); #endif return; }
gint camel_init (const gchar *configdir, gboolean nss_init) { CamelCertDB *certdb; gchar *path; if (initialised) return 0; bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); camel_debug_init (); if (nss_init) { static gchar v2_enabled = -1, weak_ciphers = -1; gchar *nss_configdir = NULL; gchar *nss_sql_configdir = NULL; SECStatus status = SECFailure; #if NSS_VMAJOR < 3 || (NSS_VMAJOR == 3 && NSS_VMINOR < 14) /* NSS pre-3.14 has most of the ciphers disabled, thus enable * weak ciphers, if it's compiled against such */ weak_ciphers = 1; #endif /* check camel-tcp-stream-ssl.c for the same "CAMEL_SSL_V2_ENABLE" */ if (v2_enabled == -1) v2_enabled = g_strcmp0 (g_getenv ("CAMEL_SSL_V2_ENABLE"), "1") == 0 ? 1 : 0; if (weak_ciphers == -1) weak_ciphers = g_strcmp0 (g_getenv ("CAMEL_SSL_WEAK_CIPHERS"), "1") == 0 ? 1 : 0; if (nss_initlock == NULL) { PR_Init (PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 10); nss_initlock = PR_NewLock (); } PR_Lock (nss_initlock); if (NSS_IsInitialized ()) goto skip_nss_init; #ifndef G_OS_WIN32 nss_configdir = g_strdup (configdir); #else nss_configdir = g_win32_locale_filename_from_utf8 (configdir); #endif if (nss_has_system_db ()) { nss_sql_configdir = g_strdup ("sql:" NSS_SYSTEM_DB ); } else { /* On Windows, we use the Evolution configdir. On other * operating systems we use ~/.pki/nssdb/, which is where * the user-specific part of the "shared system db" is * stored and is what Chrome uses too. * * We have to create the configdir if it does not exist, * to prevent camel from bailing out on first run. */ #ifdef G_OS_WIN32 g_mkdir_with_parents (configdir, 0700); nss_sql_configdir = g_strconcat ( "sql:", nss_configdir, NULL); #else gchar *user_nss_dir = g_build_filename ( g_get_home_dir (), ".pki/nssdb", NULL ); if (g_mkdir_with_parents (user_nss_dir, 0700)) g_warning ( "Failed to create SQL " "database directory %s: %s\n", user_nss_dir, strerror (errno)); nss_sql_configdir = g_strconcat ( "sql:", user_nss_dir, NULL); g_free (user_nss_dir); #endif } #if NSS_VMAJOR > 3 || (NSS_VMAJOR == 3 && NSS_VMINOR >= 12) /* See: https://wiki.mozilla.org/NSS_Shared_DB, * particularly "Mode 3A". Note that the target * directory MUST EXIST. */ status = NSS_InitWithMerge ( nss_sql_configdir, /* dest dir */ "", "", /* new DB name prefixes */ SECMOD_DB, /* secmod name */ nss_configdir, /* old DB dir */ "", "", /* old DB name prefixes */ nss_configdir, /* unique ID for old DB */ "Evolution S/MIME", /* UI name for old DB */ 0); /* flags */ if (status == SECFailure) { g_warning ( "Failed to initialize NSS SQL database in %s: NSS error %d", nss_sql_configdir, PORT_GetError ()); /* Fall back to opening the old DBM database */ } #endif /* Support old versions of libnss, pre-sqlite support. */ if (status == SECFailure) status = NSS_InitReadWrite (nss_configdir); if (status == SECFailure) { /* Fall back to using volatile dbs? */ status = NSS_NoDB_Init (nss_configdir); if (status == SECFailure) { g_free (nss_configdir); g_free (nss_sql_configdir); g_warning ("Failed to initialize NSS"); PR_Unlock (nss_initlock); return -1; } } nss_initialized = TRUE; skip_nss_init: NSS_SetDomesticPolicy (); if (weak_ciphers) { PRUint16 indx; /* enable SSL3/TLS cipher-suites */ for (indx = 0; indx < SSL_NumImplementedCiphers; indx++) { if (!SSL_IS_SSL2_CIPHER (SSL_ImplementedCiphers[indx]) && SSL_ImplementedCiphers[indx] != SSL_RSA_WITH_NULL_SHA && SSL_ImplementedCiphers[indx] != SSL_RSA_WITH_NULL_MD5) SSL_CipherPrefSetDefault (SSL_ImplementedCiphers[indx], PR_TRUE); } } SSL_OptionSetDefault (SSL_ENABLE_SSL2, v2_enabled ? PR_TRUE : PR_FALSE); SSL_OptionSetDefault (SSL_V2_COMPATIBLE_HELLO, PR_FALSE); SSL_OptionSetDefault (SSL_ENABLE_SSL3, PR_TRUE); SSL_OptionSetDefault (SSL_ENABLE_TLS, PR_TRUE); PR_Unlock (nss_initlock); g_free (nss_configdir); g_free (nss_sql_configdir); } path = g_strdup_printf ("%s/camel-cert.db", configdir); certdb = camel_certdb_new (); camel_certdb_set_filename (certdb, path); g_free (path); /* if we fail to load, who cares? it'll just be a volatile certdb */ camel_certdb_load (certdb); /* set this certdb as the default db */ camel_certdb_set_default (certdb); g_object_unref (certdb); initialised = TRUE; return 0; }
int main (int argc, char **argv) { GError *error; GHashTable *table; GHashTable *files; gchar *srcfile; gboolean show_version_and_exit = FALSE; gchar *target = NULL; gchar *binary_target = NULL; gboolean generate_automatic = FALSE; gboolean generate_source = FALSE; gboolean generate_header = FALSE; gboolean manual_register = FALSE; gboolean internal = FALSE; gboolean generate_dependencies = FALSE; gboolean generate_phony_targets = FALSE; char *dependency_file = NULL; char *c_name = NULL; char *c_name_no_underscores; const char *linkage = "extern"; GOptionContext *context; GOptionEntry entries[] = { { "version", 0, 0, G_OPTION_ARG_NONE, &show_version_and_exit, N_("Show program version and exit"), NULL }, { "target", 0, 0, G_OPTION_ARG_FILENAME, &target, N_("name of the output file"), N_("FILE") }, { "sourcedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &sourcedirs, N_("The directories where files are to be read from (default to current directory)"), N_("DIRECTORY") }, { "generate", 0, 0, G_OPTION_ARG_NONE, &generate_automatic, N_("Generate output in the format selected for by the target filename extension"), NULL }, { "generate-header", 0, 0, G_OPTION_ARG_NONE, &generate_header, N_("Generate source header"), NULL }, { "generate-source", 0, 0, G_OPTION_ARG_NONE, &generate_source, N_("Generate sourcecode used to link in the resource file into your code"), NULL }, { "generate-dependencies", 0, 0, G_OPTION_ARG_NONE, &generate_dependencies, N_("Generate dependency list"), NULL }, { "dependency-file", 0, 0, G_OPTION_ARG_FILENAME, &dependency_file, N_("name of the dependency file to generate"), N_("FILE") }, { "generate-phony-targets", 0, 0, G_OPTION_ARG_NONE, &generate_phony_targets, N_("Include phony targets in the generated dependency file"), NULL }, { "manual-register", 0, 0, G_OPTION_ARG_NONE, &manual_register, N_("Don’t automatically create and register resource"), NULL }, { "internal", 0, 0, G_OPTION_ARG_NONE, &internal, N_("Don’t export functions; declare them G_GNUC_INTERNAL"), NULL }, { "c-name", 0, 0, G_OPTION_ARG_STRING, &c_name, N_("C identifier name used for the generated source code"), NULL }, { NULL } }; #ifdef G_OS_WIN32 gchar *tmp; #endif setlocale (LC_ALL, ""); textdomain (GETTEXT_PACKAGE); #ifdef G_OS_WIN32 tmp = _glib_get_locale_dir (); bindtextdomain (GETTEXT_PACKAGE, tmp); g_free (tmp); #else bindtextdomain (GETTEXT_PACKAGE, GLIB_LOCALE_DIR); #endif #ifdef HAVE_BIND_TEXTDOMAIN_CODESET bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); #endif context = g_option_context_new (N_("FILE")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_set_summary (context, N_("Compile a resource specification into a resource file.\n" "Resource specification files have the extension .gresource.xml,\n" "and the resource file have the extension called .gresource.")); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("%s\n", error->message); return 1; } g_option_context_free (context); if (show_version_and_exit) { g_print (PACKAGE_VERSION "\n"); return 0; } if (argc != 2) { g_printerr (_("You should give exactly one file name\n")); g_free (c_name); return 1; } if (internal) linkage = "G_GNUC_INTERNAL"; srcfile = argv[1]; xmllint = g_strdup (g_getenv ("XMLLINT")); if (xmllint == NULL) xmllint = g_find_program_in_path ("xmllint"); if (xmllint == NULL) g_printerr ("XMLLINT not set and xmllint not found in path; skipping xml preprocessing.\n"); gdk_pixbuf_pixdata = g_strdup (g_getenv ("GDK_PIXBUF_PIXDATA")); if (gdk_pixbuf_pixdata == NULL) gdk_pixbuf_pixdata = g_find_program_in_path ("gdk-pixbuf-pixdata"); if (target == NULL) { char *dirname = g_path_get_dirname (srcfile); char *base = g_path_get_basename (srcfile); char *target_basename; if (g_str_has_suffix (base, ".xml")) base[strlen(base) - strlen (".xml")] = 0; if (generate_source) { if (g_str_has_suffix (base, ".gresource")) base[strlen(base) - strlen (".gresource")] = 0; target_basename = g_strconcat (base, ".c", NULL); } else if (generate_header) { if (g_str_has_suffix (base, ".gresource")) base[strlen(base) - strlen (".gresource")] = 0; target_basename = g_strconcat (base, ".h", NULL); } else { if (g_str_has_suffix (base, ".gresource")) target_basename = g_strdup (base); else target_basename = g_strconcat (base, ".gresource", NULL); } target = g_build_filename (dirname, target_basename, NULL); g_free (target_basename); g_free (dirname); g_free (base); } else if (generate_automatic) { if (extension_in_set (target, "c", "cc", "cpp", "cxx", "c++", NULL)) generate_source = TRUE; else if (extension_in_set (target, "h", "hh", "hpp", "hxx", "h++", NULL)) generate_header = TRUE; else if (extension_in_set (target, "gresource", NULL)) { } } files = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)file_data_free); if ((table = parse_resource_file (srcfile, !generate_dependencies, files)) == NULL) { g_free (target); g_free (c_name); return 1; } /* This can be used in the same invocation as other generate commands */ if (dependency_file != NULL) { /* Generate a .d file that describes the dependencies for * build tools, gcc -M -MF style */ GString *dep_string; GHashTableIter iter; gpointer key, data; FileData *file_data; char *escaped; g_hash_table_iter_init (&iter, files); dep_string = g_string_new (NULL); escaped = escape_makefile_string (srcfile); g_string_printf (dep_string, "%s:", escaped); g_free (escaped); /* First rule: foo.xml: resource1 resource2.. */ while (g_hash_table_iter_next (&iter, &key, &data)) { file_data = data; if (!g_str_equal (file_data->filename, srcfile)) { escaped = escape_makefile_string (file_data->filename); g_string_append_printf (dep_string, " %s", escaped); g_free (escaped); } } g_string_append (dep_string, "\n"); /* Optionally include phony targets as it silences `make` but * isn't supported on `ninja` at the moment. See also: `gcc -MP` */ if (generate_phony_targets) { g_string_append (dep_string, "\n"); /* One rule for every resource: resourceN: */ g_hash_table_iter_init (&iter, files); while (g_hash_table_iter_next (&iter, &key, &data)) { file_data = data; if (!g_str_equal (file_data->filename, srcfile)) { escaped = escape_makefile_string (file_data->filename); g_string_append_printf (dep_string, "%s:\n\n", escaped); g_free (escaped); } } } if (g_str_equal (dependency_file, "-")) { g_print ("%s\n", dep_string->str); } else { if (!g_file_set_contents (dependency_file, dep_string->str, dep_string->len, &error)) { g_printerr ("Error writing dependency file: %s\n", error->message); g_string_free (dep_string, TRUE); g_free (dependency_file); g_error_free (error); return 1; } } g_string_free (dep_string, TRUE); g_free (dependency_file); } if (generate_dependencies) { GHashTableIter iter; gpointer key, data; FileData *file_data; g_hash_table_iter_init (&iter, files); /* Generate list of files for direct use as dependencies in a Makefile */ while (g_hash_table_iter_next (&iter, &key, &data)) { file_data = data; g_print ("%s\n", file_data->filename); } } else if (generate_source || generate_header) { if (generate_source) { int fd = g_file_open_tmp (NULL, &binary_target, NULL); if (fd == -1) { g_printerr ("Can't open temp file\n"); g_free (c_name); return 1; } close (fd); } if (c_name == NULL) { char *base = g_path_get_basename (srcfile); GString *s; char *dot; int i; /* Remove extensions */ dot = strchr (base, '.'); if (dot) *dot = 0; s = g_string_new (""); for (i = 0; base[i] != 0; i++) { const char *first = G_CSET_A_2_Z G_CSET_a_2_z "_"; const char *rest = G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "_"; if (strchr ((i == 0) ? first : rest, base[i]) != NULL) g_string_append_c (s, base[i]); else if (base[i] == '-') g_string_append_c (s, '_'); } c_name = g_string_free (s, FALSE); } } else binary_target = g_strdup (target); c_name_no_underscores = c_name; while (c_name_no_underscores && *c_name_no_underscores == '_') c_name_no_underscores++; if (binary_target != NULL && !write_to_file (table, binary_target, &error)) { g_printerr ("%s\n", error->message); g_free (target); g_free (c_name); return 1; } if (generate_header) { FILE *file; file = fopen (target, "w"); if (file == NULL) { g_printerr ("can't write to file %s", target); g_free (c_name); return 1; } fprintf (file, "#ifndef __RESOURCE_%s_H__\n" "#define __RESOURCE_%s_H__\n" "\n" "#include <gio/gio.h>\n" "\n" "%s GResource *%s_get_resource (void);\n", c_name, c_name, linkage, c_name); if (manual_register) fprintf (file, "\n" "%s void %s_register_resource (void);\n" "%s void %s_unregister_resource (void);\n" "\n", linkage, c_name, linkage, c_name); fprintf (file, "#endif\n"); fclose (file); } else if (generate_source) { FILE *file; guint8 *data; gsize data_size; gsize i; if (!g_file_get_contents (binary_target, (char **)&data, &data_size, NULL)) { g_printerr ("can't read back temporary file"); g_free (c_name); return 1; } g_unlink (binary_target); file = fopen (target, "w"); if (file == NULL) { g_printerr ("can't write to file %s", target); g_free (c_name); return 1; } fprintf (file, "#include <gio/gio.h>\n" "\n" "#if defined (__ELF__) && ( __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6))\n" "# define SECTION __attribute__ ((section (\".gresource.%s\"), aligned (8)))\n" "#else\n" "# define SECTION\n" "#endif\n" "\n" "static const SECTION union { const guint8 data[%"G_GSIZE_FORMAT"]; const double alignment; void * const ptr;} %s_resource_data = { {\n", c_name_no_underscores, data_size, c_name); for (i = 0; i < data_size; i++) { if (i % 8 == 0) fprintf (file, " "); fprintf (file, "0x%2.2x", (int)data[i]); if (i != data_size - 1) fprintf (file, ", "); if ((i % 8 == 7) || (i == data_size - 1)) fprintf (file, "\n"); } fprintf (file, "} };\n"); fprintf (file, "\n" "static GStaticResource static_resource = { %s_resource_data.data, sizeof (%s_resource_data.data), NULL, NULL, NULL };\n" "%s GResource *%s_get_resource (void);\n" "GResource *%s_get_resource (void)\n" "{\n" " return g_static_resource_get_resource (&static_resource);\n" "}\n", c_name, c_name, linkage, c_name, c_name); if (manual_register) { fprintf (file, "\n" "%s void %s_unregister_resource (void);\n" "void %s_unregister_resource (void)\n" "{\n" " g_static_resource_fini (&static_resource);\n" "}\n" "\n" "%s void %s_register_resource (void);\n" "void %s_register_resource (void)\n" "{\n" " g_static_resource_init (&static_resource);\n" "}\n", linkage, c_name, c_name, linkage, c_name, c_name); } else { fprintf (file, "%s", gconstructor_code); fprintf (file, "\n" "#ifdef G_HAS_CONSTRUCTORS\n" "\n" "#ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA\n" "#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(resource_constructor)\n" "#endif\n" "G_DEFINE_CONSTRUCTOR(resource_constructor)\n" "#ifdef G_DEFINE_DESTRUCTOR_NEEDS_PRAGMA\n" "#pragma G_DEFINE_DESTRUCTOR_PRAGMA_ARGS(resource_destructor)\n" "#endif\n" "G_DEFINE_DESTRUCTOR(resource_destructor)\n" "\n" "#else\n" "#warning \"Constructor not supported on this compiler, linking in resources will not work\"\n" "#endif\n" "\n" "static void resource_constructor (void)\n" "{\n" " g_static_resource_init (&static_resource);\n" "}\n" "\n" "static void resource_destructor (void)\n" "{\n" " g_static_resource_fini (&static_resource);\n" "}\n"); } fclose (file); g_free (data); } g_free (binary_target); g_free (target); g_hash_table_destroy (table); g_free (xmllint); g_free (c_name); return 0; }