static void gm_platform_open_uri_fallback (const gchar *uri) { gchar *commandline = NULL; gboolean success = FALSE; if (!success && g_getenv("KDE_FULL_SESSION") != NULL) { commandline = g_strdup_printf ("kfmclient exec %s", uri); success = g_spawn_command_line_async (commandline, NULL); g_free (commandline); } if (!success) { commandline = g_strdup_printf ("sensible-browser %s", uri); success = g_spawn_command_line_async (commandline, NULL); g_free (commandline); } if (!success) { commandline = g_strdup_printf ("firefox %s", uri); success = g_spawn_command_line_async (commandline, NULL); g_free (commandline); } if (!success) { commandline = g_strdup_printf ("konqueror %s", uri); success = g_spawn_command_line_async (commandline, NULL); g_free (commandline); } }
static void drop_data_cb (GtkWidget *w, GdkDragContext *dc, gint x, gint y, GtkSelectionData *sel, guint info, guint t, gpointer data) { GdkAtom stgt; stgt = gtk_selection_data_get_target (sel); if (gtk_targets_include_uri (&stgt, 1)) { gchar **uris; gint i = 0; uris = gtk_selection_data_get_uris (sel); if (!uris) return; while (uris[i]) { gchar *dstr = g_uri_unescape_string (uris[i], NULL); if (options.common_data.command) { gchar *action = g_strdup_printf ("%s '%s'", options.common_data.command, dstr); g_spawn_command_line_async (action, NULL); g_free (action); } else { g_printf ("%s\n", dstr); fflush (stdout); } g_free (dstr); i++; } g_strfreev (uris); } else if (gtk_targets_include_text (&stgt, 1)) { guchar *str = gtk_selection_data_get_text (sel); if (str) { gchar *dstr = g_uri_unescape_string ((const gchar *) str, NULL); if (options.common_data.command) { gchar *action = g_strdup_printf ("%s '%s'", options.common_data.command, dstr); g_spawn_command_line_async (action, NULL); g_free (action); } else { g_printf ("%s\n", dstr); fflush (stdout); } g_free (dstr); g_free(str); } } }
static gboolean exec_skype() { GError *error; #ifdef USE_XVFB_SERVER PurpleAccount *acct = NULL; int skype_stdin; gchar **skype_list; gchar *command; if (!getenv("SKYPEDISPLAY")) setenv("SKYPEDISPLAY", ":25", 0); unsetenv("DBUS_SESSION_BUS_ADDRESS"); command = g_strconcat("Xvfb ", //"Xnest ", //Uncomment if using Xnest getenv("SKYPEDISPLAY"), " -ac -terminate -tst -xinerama", " -render -shmem -screen 0 320x240x16", //Dont use me if using Xnest NULL); if (g_spawn_command_line_async(command, NULL)) { acct = skype_get_account(NULL); skype_debug_info("skype_x11", "acct: %d\n", acct); if (acct && acct->username && acct->username[0] != '\0' && acct->password && acct->password[0] != '\0') { g_free(command); command = g_strconcat("skype --pipelogin -display ", getenv("SKYPEDISPLAY"), NULL); g_shell_parse_argv(command, NULL, &skype_list, NULL); if (g_spawn_async_with_pipes(NULL, skype_list, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &skype_stdin, NULL, NULL, NULL)) { g_strfreev(skype_list); write(skype_stdin, acct->username, strlen(acct->username)); write(skype_stdin, " ", 1); write(skype_stdin, acct->password, strlen(acct->password)); write(skype_stdin, "\n", 1); fsync(skype_stdin); skype_debug_info("skype_x11", "pipelogin worked\n"); g_free(command); return TRUE; } g_strfreev(skype_list); } } g_free(command); #endif if (g_spawn_command_line_async("skype --disable-cleanlooks", &error)) { return TRUE; } else { skype_debug_error("skype", "Could not start skype: %s\n", error->message); return FALSE; } }
gboolean on_mime_change_timer( gpointer user_data ) { //printf("MIME-UPDATE on_timer\n" ); char* cmd = g_strdup_printf( "update-mime-database %s/mime", g_get_user_data_dir() ); g_spawn_command_line_async( cmd, NULL ); g_free( cmd ); cmd = g_strdup_printf( "update-desktop-database %s/applications", g_get_user_data_dir() ); g_spawn_command_line_async( cmd, NULL ); g_free( cmd ); g_source_remove( mime_change_timer ); mime_change_timer = 0; return FALSE; }
static gboolean monitors_button_press_event(GtkWidget* widget, GdkEventButton* evt, Plugin *plugin) { MonitorsPlugin* mp = plugin->priv; /* Standard right-click handling. */ if (plugin_button_press_event(widget, evt, plugin)) return TRUE; if (mp->action != NULL) g_spawn_command_line_async(mp->action, NULL); else g_spawn_command_line_async("lxtask", NULL); return TRUE; }
JS_EXPORT_API void installer_finish_reboot () { finish_install_cleanup (); g_spawn_command_line_async ("reboot", NULL); gtk_main_quit (); }
static void infobar_response_cb (GtkInfoBar *info_bar, int response_id, gpointer user_data) { WallpaperData *wdata = user_data; const gchar *control_center_command = NULL; GError *error = NULL; g_return_if_fail (GTH_IS_BROWSER (wdata->browser)); switch (response_id) { case _RESPONSE_PREFERENCES: if (g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Cinnamon") == 0 || g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "X-Cinnamon") == 0) control_center_command = "cinnamon-settings backgrounds"; else if (g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "MATE") == 0) control_center_command = "mate-appearance-properties -p background"; else if (g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "GNOME") == 0) control_center_command = "gnome-control-center appearance"; else if (g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity") == 0) control_center_command = "unity-control-center appearance"; if (control_center_command != NULL && ! g_spawn_command_line_async (control_center_command, &error)) { _gtk_error_dialog_from_gerror_run (GTK_WINDOW (wdata->browser), _("Could not show the desktop background properties"), error); g_clear_error (&error); } break; case _RESPONSE_UNDO: wallpaper_style_set_as_current (&wdata->old_style); break; } gtk_widget_hide (GTK_WIDGET (info_bar)); wallpaper_data_free (wdata); }
static gboolean _get_active_player (void) { ol_log_func (); player = ol_player_get_active_player (); if (player == NULL) { gboolean ignore = FALSE; if (first_run) { OlConfig *config = ol_config_get_instance (); char *player_cmd = ol_config_get_string (config, "General", "startup-player"); if (!ol_is_string_empty (player_cmd)) { ignore = TRUE; ol_debugf ("Running %s\n", player_cmd); g_spawn_command_line_async (player_cmd, NULL); sleep (5); } g_free (player_cmd); } if (!ignore) { printf (_("No supported player is running, exit.\n")); gtk_main_quit (); } } ol_display_module_set_player (module, player); first_run = FALSE; return player != NULL; }
/* The following test function returns 1 only when the any one of the g_spawn_command_line_async * tests fails.For pass of all the test the function returns 0. */ int g_spawn_command_line_async_tests() { GError *error = NULL; int retVal = 0; if(g_spawn_command_line_async("helloworld.exe 1 2 3",&error)) { } else { if(error) { g_log(NULL,G_LOG_LEVEL_CRITICAL,"file %s: line %d Error Message:%s",__FILE__, __LINE__, error->message); g_error_free(error); error = NULL; } else { g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__); } retVal = 1; } return retVal; }
static void sound_callback(GObject *widget, gpointer user_data) { const char *command = SOUND_PREFS; if (!g_spawn_command_line_async(command, NULL)) g_printerr("Couldn't execute command: %s\n", command); }
int main (int argc, char *argv[]) { GError *error; gint ret; g_type_init (); g_test_init (&argc, &argv, NULL); /* all the tests rely on a shared main loop */ loop = g_main_loop_new (NULL, FALSE); session_bus_up (); /* this is safe; testserver will exit once the bus goes away */ g_assert (g_spawn_command_line_async (SRCDIR "/gdbus-testserver.py", NULL)); /* wait for the service to come up */ usleep (500 * 1000); /* Create the connection in the main thread */ error = NULL; c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); g_assert_no_error (error); g_assert (c != NULL); g_test_add_func ("/gdbus/connection-loss", test_connection_loss); ret = g_test_run(); g_object_unref (c); return ret; }
static void link_button_clicked_cb (GtkWidget *widget, LmplayerObject *lmplayer) { const char *uri; char *command, *browser, *escaped_uri; GError *error = NULL; uri = gtk_link_button_get_uri (GTK_LINK_BUTTON (widget)); escaped_uri = g_shell_quote (uri); browser = gconf_client_get_string (lmplayer->gc, "/desktop/gnome/url-handlers/http/command", NULL); if (browser == NULL || browser[0] == '\0') { char *message; message = g_strdup_printf(_("Could not launch URL \"%s\": %s"), uri, _("Default browser not configured")); //lmplayer_interface_error (_("Error launching URI"), message, GTK_WINDOW (lmplayer->win)); g_free (message); } else { char *message; command = g_strdup_printf (browser, escaped_uri); if (g_spawn_command_line_async ((const char*) command, &error) == FALSE) { message = g_strdup_printf(_("Could not launch URL \"%s\": %s"), uri, error->message); //lmplayer_interface_error (_("Error launching URI"), message, GTK_WINDOW (lmplayer->win)); g_free (message); g_error_free (error); } g_free (command); } g_free (escaped_uri); g_free (browser); }
void switch_user(struct passwd *pw, const char *run, char **env) { int fd; setenv("USER",pw->pw_name,1); setenv("LOGNAME",pw->pw_name,1); setenv("SHELL",pw->pw_shell,1); setenv("HOME",pw->pw_dir,1); g_spawn_command_line_sync ("/etc/lxdm/PreLogin",NULL,NULL,NULL,NULL); if( !pw || initgroups(pw->pw_name, pw->pw_gid) || setgid(pw->pw_gid) || setuid(pw->pw_uid)/* || setsid() == -1 */) exit(EXIT_FAILURE); chdir(pw->pw_dir); fd=open(".xsession-errors",O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR); if(fd!=-1) { dup2(fd,STDERR_FILENO); close(fd); } /* reset signal */ signal(SIGCHLD, SIG_DFL); signal(SIGTERM, SIG_DFL); signal(SIGPIPE, SIG_DFL); signal(SIGALRM, SIG_DFL); signal(SIGHUP, SIG_DFL); close_left_fds(); g_spawn_command_line_async ("/etc/lxdm/PostLogin",NULL); execl("/etc/lxdm/Xsession","/etc/lxdm/Xsession",run,NULL); perror("execle"); exit(EXIT_FAILURE); }
extern void OpenURL(const char *szURL) { const gchar *browser = get_web_browser(); gchar *commandString; GError *error = NULL; if (!(browser) || !(*browser)) { #ifdef WIN32 int win_error; gchar *url = g_filename_to_uri(szURL, NULL, NULL); win_error = (int) ShellExecute(NULL, TEXT("open"), url ? url : szURL, NULL, ".\\", SW_SHOWNORMAL); if (win_error < 33) outputerrf(_("Failed to perform default action on " "%s. Error code was %d"), url, win_error); g_free(url); return; #endif } commandString = g_strdup_printf("'%s' '%s'", browser, szURL); if (!g_spawn_command_line_async(commandString, &error)) { outputerrf(_("Browser couldn't open file (%s): %s\n"), commandString, error->message); g_error_free(error); } return; }
static void extract_to_callback (NautilusMenuItem *item, gpointer user_data) { GList *files; NautilusFileInfo *file; char *uri, *default_dir; GString *cmd; files = g_object_get_data (G_OBJECT (item), "files"); file = files->data; uri = nautilus_file_info_get_uri (file); default_dir = nautilus_file_info_get_parent_uri (file); cmd = g_string_new ("file-roller"); g_string_append_printf (cmd, " --default-dir=%s --extract %s", g_shell_quote (default_dir), g_shell_quote (uri)); #ifdef DEBUG g_print ("EXEC: %s\n", cmd->str); #endif g_spawn_command_line_async (cmd->str, NULL); g_string_free (cmd, TRUE); g_free (default_dir); g_free (uri); }
static void add_callback (NautilusMenuItem *item, gpointer user_data) { GList *files, *scan; NautilusFileInfo *file; char *uri, *dir; GString *cmd; files = g_object_get_data (G_OBJECT (item), "files"); file = files->data; uri = nautilus_file_info_get_uri (file); dir = g_path_get_dirname (uri); cmd = g_string_new ("file-roller"); g_string_append (cmd, " --notify"); g_string_append_printf (cmd," --default-dir=%s", g_shell_quote (dir)); g_string_append (cmd," --add"); g_free (dir); g_free (uri); for (scan = files; scan; scan = scan->next) { NautilusFileInfo *file = scan->data; uri = nautilus_file_info_get_uri (file); g_string_append_printf (cmd, " %s", g_shell_quote (uri)); g_free (uri); } g_spawn_command_line_async (cmd->str, NULL); g_string_free (cmd, TRUE); }
/* Handler for "button-press-event" event from main widget. */ static gboolean dclock_button_press_event(GtkWidget * widget, GdkEventButton * evt, Plugin * plugin) { DClockPlugin * dc = (DClockPlugin *) plugin->priv; /* Standard right-click handling. */ if (plugin_button_press_event(widget, evt, plugin)) return TRUE; /* If an action is set, execute it. */ if (dc->action != NULL) g_spawn_command_line_async(dc->action, NULL); /* If no action is set, toggle the presentation of the calendar. */ else { if (dc->calendar_window == NULL) { dc->calendar_window = dclock_create_calendar(dc); gtk_widget_show_all(dc->calendar_window); } else { gtk_widget_destroy(dc->calendar_window); dc->calendar_window = NULL; } } return TRUE; }
static void optimize_png (const gchar *png_path) { gchar *cmd = g_strconcat ("optipng -quiet", " ", png_path, NULL); g_spawn_command_line_async (cmd, NULL); g_free (cmd); }
JS_EXPORT_API void installer_show_log () { gchar *cmd = g_strdup_printf ("xdg-open %s\n", LOG_FILE_PATH); g_spawn_command_line_async (cmd, NULL); g_free (cmd); }
static void infobar_response_cb (GtkInfoBar *info_bar, int response_id, gpointer user_data) { WallpaperData *wdata = user_data; GError *error = NULL; g_return_if_fail (GTH_IS_BROWSER (wdata->browser)); switch (response_id) { case _RESPONSE_PREFERENCES: if (! g_spawn_command_line_async (DESKTOP_BACKGROUND_PROPERTIES_COMMAND, &error)) { _gtk_error_dialog_from_gerror_run (GTK_WINDOW (wdata->browser), _("Could not show the desktop background properties"), error); g_clear_error (&error); } break; case _RESPONSE_UNDO: wallpaper_style_set_as_current (&wdata->old_style); break; } gtk_widget_hide (GTK_WIDGET (info_bar)); wallpaper_data_free (wdata); }
static void wizard_callback(GtkWidget *button, gpointer user_data) { const char *command = "mate-bluetooth-wizard"; if (!g_spawn_command_line_async(command, NULL)) g_printerr("Couldn't execute command: %s\n", command); }
void settings_callback(GObject *widget, gpointer user_data) { const char *command = "cinnamon-settings bluetooth"; if (!g_spawn_command_line_async(command, NULL)) g_printerr("Couldn't execute command: %s\n", command); }
NCLError ncl_exec(char *cmd) { NCLError ret = NCLERR_PARSING_PARAMETERS; GError *gerr = NULL; ncl_cmd_func func = NULL; char **argv = NULL; int argc; if (!g_shell_parse_argv(g_strstrip(cmd), &argc, &argv, &gerr)) goto exit; if (!(func = ncl_prv_find_func(argv[0]))) { NCL_CMD_PRINTERR("'%s': Not NCL command, trying shell\n", cmd); g_spawn_command_line_async(cmd, &gerr); goto exit; } if ((ret = func(argc, argv)) != NCLERR_NOERROR) NCL_CMD_PRINTERR("'%s': %s\n", cmd, ncl_error_get_text(ret)); exit: if (gerr) { if (gerr->code == G_SHELL_ERROR_EMPTY_STRING) ret = NCLERR_NOERROR; if (ret != NCLERR_NOERROR) NCL_CMD_PRINTERR("%s\n", gerr->message); g_error_free(gerr); } g_strfreev(argv); return ret; }
static void extract_here_callback (CajaMenuItem *item, gpointer user_data) { GList *files, *scan; GString *cmd; files = g_object_get_data (G_OBJECT (item), "files"); cmd = g_string_new ("engrampa --extract-here"); for (scan = files; scan; scan = scan->next) { CajaFileInfo *file = scan->data; char *uri, *quoted_uri; uri = caja_file_info_get_uri (file); quoted_uri = g_shell_quote (uri); g_string_append_printf (cmd, " %s", quoted_uri); g_free (uri); g_free (quoted_uri); } g_spawn_command_line_async (cmd->str, NULL); #ifdef DEBUG g_print ("EXEC: %s\n", cmd->str); #endif g_string_free (cmd, TRUE); }
static gboolean display_clicked_cb (GtkButton *button, CcWacomPage *page) { g_spawn_command_line_async ("sagarmatha-settings display", NULL); return TRUE; }
static gboolean spawn_app(GtkWidget * widget, GdkEventButton * event, gpointer data) { gchar *app, *path; if (event->button != 1) return FALSE; path = g_object_get_data(G_OBJECT(widget), "path"); app = g_strdup_printf("\"%s/%s/AppRun\"", path, (gchar *) data); if (!g_spawn_command_line_async(app, NULL)) { GtkWidget *dialog; dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Cannot fork. Yay."); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } g_free(app); return FALSE; }
void wizard_callback(GObject *widget, gpointer user_data) { const char *command = "bluetooth-wizard"; if (!g_spawn_command_line_async(command, NULL)) g_printerr("Couldn't execute command: %s\n", command); }
static gboolean _url_opener_executable_launche(UrlOpener *opener, const gchar *url) { _UrlOpenerExecutable *opener_exe = (_UrlOpenerExecutable *)opener; gchar *cmd; GError *err = NULL; gboolean ret = TRUE; /* build command */ g_debug("Opening \"%s\" using \"%s\"", url, opener_exe->executable); if(opener_exe->arguments) { cmd = g_strdup_printf("\"%s\" %s \"%s\"", opener_exe->executable, opener_exe->arguments, url); } else { cmd = g_strdup_printf("\"%s\" \"%s\"", opener_exe->executable, url); } g_debug("Executing \"%s\"", cmd); /* execute command */ g_spawn_command_line_async(cmd, &err); if(err) { ret = FALSE; g_warning("%s", err->message); g_error_free(err); } /* free memory */ g_free(cmd); return ret; }
static void wckbuttons_configure_response (GtkWidget *dialog, gint response, WBPlugin *wb) { gboolean result; if (response == GTK_RESPONSE_HELP) { /* show help */ result = g_spawn_command_line_async ("exo-open --launch WebBrowser " PLUGIN_WEBSITE, NULL); if (G_UNLIKELY (result == FALSE)) g_warning (_("Unable to open the following url: %s"), PLUGIN_WEBSITE); } else { /* remove the dialog data from the plugin */ g_object_set_data (G_OBJECT (wb->plugin), "dialog", NULL); /* unlock the panel menu */ xfce_panel_plugin_unblock_menu (wb->plugin); /* save the plugin */ wckbuttons_save (wb->plugin, wb); /* destroy the properties dialog */ gtk_widget_destroy (dialog); } }
static void rendering_engine_callback(gpointer user_data) { if (user_data) {}; if (arg_rendering_engine) return; gchar *new_engine = g_strdup(rendering_engine); gxneur_config_read_str("rendering_engine", &new_engine); if (strcasecmp(new_engine, rendering_engine) == 0) return; for (int i = 0; i < MAX_LAYOUTS; i++) { if (tray->images[i] != NULL) g_free(tray->images[i]); } gtk_widget_destroy(GTK_WIDGET(tray->menu)); tray->menu = NULL; g_spawn_command_line_async(PACKAGE, NULL); gtk_main_quit(); }