static void attach_process_update (AttachProcess * ap) { gchar *tmp, *tmp1, *cmd; gchar *shell; gchar *argv[4]; GError *err = NULL; GtkTreeStore *store; gboolean result; g_return_if_fail (ap); store = GTK_TREE_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (ap->treeview))); g_return_if_fail (store); if (anjuta_util_prog_is_installed ("ps", TRUE) == FALSE) return; tmp = anjuta_util_get_a_tmp_file (); #if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) cmd = g_strconcat ("ps axw -o pid,user,lstart,args > ", tmp, NULL); #else cmd = g_strconcat ("ps axw -H -o pid,user,start_time,args > ", tmp, NULL); #endif shell = anjuta_util_user_shell (); argv[0] = shell; argv[1] = "-c"; argv[2] = cmd; argv[3] = NULL; if (!g_spawn_sync (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL, NULL, &err)) { anjuta_util_dialog_error (NULL, _("Unable to execute: \"%s\". " "The returned error was: \"%s\"."), cmd, err->message); g_error_free (err); g_free (tmp); g_free (cmd); return; } g_free (cmd); result = g_file_get_contents (tmp, &tmp1, NULL, NULL); remove (tmp); g_free (tmp); if (! result) { anjuta_util_dialog_error_system (NULL, errno, _("Unable to open the file: %s\n"), tmp); return; } attach_process_clear (ap, CLEAR_UPDATE); ap->ps_output = anjuta_util_convert_to_utf8 (tmp1); g_free (tmp1); if (ap->ps_output) { attach_process_review (ap); } }
static void attach_process_update (AttachProcess * ap) { gchar *tmp, *tmp1, *cmd; gint ch_pid; gchar *shell; GtkTreeStore *store; gboolean result; g_return_if_fail (ap); store = GTK_TREE_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (ap->treeview))); g_return_if_fail (store); if (anjuta_util_prog_is_installed ("ps", TRUE) == FALSE) return; tmp = anjuta_util_get_a_tmp_file (); #if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) cmd = g_strconcat ("ps axw -o pid,user,lstart,args > ", tmp, NULL); #else cmd = g_strconcat ("ps axw -H -o pid,user,start_time,args > ", tmp, NULL); #endif shell = anjuta_util_user_shell (); ch_pid = fork (); if (ch_pid == 0) { execlp (shell, shell, "-c", cmd, NULL); } if (ch_pid < 0) { anjuta_util_dialog_error_system (NULL, errno, _("Unable to execute: %s."), cmd); g_free (tmp); g_free (cmd); return; } waitpid (ch_pid, NULL, 0); g_free (cmd); result = g_file_get_contents (tmp, &tmp1, NULL, NULL); remove (tmp); g_free (tmp); if (! result) { anjuta_util_dialog_error_system (NULL, errno, _("Unable to open the file: %s\n"), tmp); return; } attach_process_clear (ap, CLEAR_UPDATE); ap->ps_output = anjuta_util_convert_to_utf8 (tmp1); g_free (tmp1); if (ap->ps_output) { attach_process_review (ap); } }
static GPid execute_without_terminal (RunProgramPlugin *plugin, const gchar *dir, gchar *cmd, gchar **env) { char *user_shell; char * argv[4]; GPid pid; RunProgramChild *child; gchar **new_env; /* Create environment variable array with new user variable */ new_env = merge_environment_variable (env); /* Run user program using in a shell */ user_shell = anjuta_util_user_shell (); argv[0] = user_shell; argv[1] = "-c"; argv[2] = cmd; argv[3] = NULL; child = g_new0 (RunProgramChild, 1); plugin->child = g_list_prepend (plugin->child, child); if (g_spawn_async_with_pipes (dir, argv, new_env, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL, NULL, NULL, NULL)) { child->pid = pid; child->source = g_child_watch_add (pid, on_child_terminated, plugin); } else { pid = 0; } g_free (user_shell); g_strfreev (new_env); return pid; }