Esempio n. 1
0
  void terminal::spawn_child(std::string i_command) {
    if ( m_terminal != NULL ) {
      GError *error = NULL;
      gchar **args = NULL;
      GSpawnFlags spawn_flags = G_SPAWN_SEARCH_PATH;

      if ( i_command.empty() ) {
        gchar *user_shell = vte_get_user_shell();

        g_shell_parse_argv(user_shell, 0, &args, 0);

        g_free(user_shell);
      } else {
        g_shell_parse_argv(i_command.c_str(), 0, &args, 0);
      }

      vte_terminal_spawn_sync(m_terminal, VTE_PTY_DEFAULT, NULL, args, NULL, spawn_flags, NULL, NULL, &m_child_pid, NULL, &error);

      if ( error != NULL ) {
        sterm::common::warning("sterm::terminal", "failed to spawn child process");
        sterm::common::debug("sterm::terminal", "VteTerminal error message: %s", error->message);

        g_error_free(error);
      }
      
      g_strfreev(args);
    }
  }
Esempio n. 2
0
static gboolean
locate_fortune_command (FishApplet   *fish,
			int          *argcp,
			char       ***argvp)
{
	char *prog = NULL;

	if (fish->command
	    && g_shell_parse_argv (fish->command, argcp, argvp, NULL)) {
		prog = g_find_program_in_path ((*argvp)[0]);
		if (prog) {
			g_free (prog);
			return TRUE;
		}

		g_strfreev (*argvp);
	}

	prog = g_find_program_in_path ("fortune");
	if (prog) {
		g_free (prog);
		if (g_shell_parse_argv ("fortune", argcp, argvp, NULL))
			return FALSE;
	}

	if (g_file_test ("/usr/games/fortune", G_FILE_TEST_IS_EXECUTABLE)
	    && g_shell_parse_argv ("/usr/games/fortune", argcp, argvp, NULL))
		return FALSE;

	something_fishy_going_on (fish,
				  _("Unable to locate the command to execute"));
	*argvp = NULL;
	return FALSE;
}
Esempio n. 3
0
RESULT
test_shell_argv3 ()
{
    GError *error;
    gint argc;
    gchar **argv;
    gboolean ret;

    argv = NULL;
    argc = 0;
    error = NULL;
    ret = g_shell_parse_argv ("hola      \"bola", &argc, &argv, &error);
    if (ret)
        return FAILED ("1. It should return FALSE");
    if (argc != 0)
        return FAILED ("2. argc was %d", argc);
    if (argv != NULL)
        return FAILED ("3. argv[0] was %s", argv [0]);
    if (error == NULL)
        return FAILED ("4. error is null");

    /* Text ended before matching quote was found for ". (The text was 'hola      "bola') */
    g_error_free (error);
    error = NULL;
    ret = g_shell_parse_argv ("hola      \\\"bola", &argc, &argv, &error);
    if (!ret)
        return FAILED ("5. It should return TRUE");
    if (argc != 2)
        return FAILED ("6. argc was %d", argc);
    if (strcmp (argv [0], "hola"))
        return FAILED ("18. argv[0] was %s", argv [0]);
    if (strcmp (argv [1], "\"bola"))
        return FAILED ("18. argv[1] was %s", argv [1]);
    if (error != NULL)
        return FAILED ("8. error is not null");

    g_strfreev (argv);
    argv = NULL;
    argc = 0;
    ret = g_shell_parse_argv ("hola      \"\n\\'bola\"", &argc, &argv, &error);
    if (!ret)
        return FAILED ("9. It should return TRUE. %s", error->message);
    if (argc != 2)
        return FAILED ("10. argc was %d", argc);
    if (strcmp (argv [0], "hola"))
        return FAILED ("11. argv[0] was %s", argv [0]);
    if (strcmp (argv [1], "\n\\'bola"))
        return FAILED ("12. argv[1] was %s", argv [1]);
    if (error != NULL)
        return FAILED ("13. error is not null");

    g_strfreev (argv);
    argv = NULL;
    argc = 0;
    return OK;
}
/* Only called for non-desktop files */
static char *
get_app_name (const char *commandline, GError **error)
{
    char *basename;
    char *unquoted;
    char **argv;
    int argc;

    if (!g_shell_parse_argv (commandline,
                             &argc, &argv, error))
    {
        return NULL;
    }

    unquoted = g_shell_unquote (argv[0], NULL);
    if (unquoted)
    {
        basename = g_path_get_basename (unquoted);
    }
    else
    {
        basename = g_strdup (argv[0]);
    }

    g_free (unquoted);
    g_strfreev (argv);

    return basename;
}
Esempio n. 5
0
/* Hacky conf file parsing to not write logic twice */
void parse_conf(void) {
  GIOChannel *f;

  gchar *conf = g_build_filename(g_get_user_config_dir(), PNAME, CONFIG_FNAME, NULL);
  if ((f = g_io_channel_new_file(conf, "r", NULL))) {
    char *line = NULL;
    GError *err = NULL;

    while (g_io_channel_read_line(f, &line, NULL, NULL, NULL) ==
        G_IO_STATUS_NORMAL) {
      char *temp = NULL, **argv = NULL;
      gint argc;

      /* strip newlines and comments */
      g_strdelimit(line, "\n#", '\0');
      temp = g_strdup_printf(PNAME " --%s", line);
      if (!g_shell_parse_argv(temp, &argc, &argv, &err) ||
          (argc != 2 && argc != 3) ||
          !g_option_context_parse(bm.context, &argc, &argv, &err)) {
        g_printerr("Error parsing config file arguments: %s (%s)\n",
            err?err->message:"Invalid number of params", line);
        exit(1);
      }
      g_strfreev(argv);
    }
    g_free(line);
    g_io_channel_shutdown(f, TRUE, &err);
    g_io_channel_unref(f);
  }
  g_free(conf);
}
Esempio n. 6
0
char *
ve_first_word (const char *s)
{
	int argc;
	char **argv;
	char *ret;

	if (s == NULL)
		return NULL;

	if ( ! g_shell_parse_argv (s, &argc, &argv, NULL)) {
		char *p;
		ret = g_strdup (s);
		p = strchr (ret, ' ');
		if (p != NULL)
			*p = '\0';
		return ret;
	}

	ret = g_strdup (argv[0]);

	g_strfreev (argv);

	return ret;
}
static void
xfce_xkb_configure_layout (GtkWidget *widget,
                           gpointer user_data)
{
    gchar *desktop_file = xfce_resource_lookup (XFCE_RESOURCE_DATA,
                                 "applications/xfce-keyboard-settings.desktop");

    GarconMenuItem *item = garcon_menu_item_new_for_path (desktop_file);
    if (item)
    {
          GError  *error = NULL;
          gchar  **argv;
          gboolean succeed;
          g_shell_parse_argv (garcon_menu_item_get_command (item), NULL, &argv, &error);
          succeed = xfce_spawn_on_screen (gtk_widget_get_screen (GTK_WIDGET (widget)),
                                garcon_menu_item_get_path (item),
                                argv, NULL, G_SPAWN_SEARCH_PATH,
                                garcon_menu_item_supports_startup_notification (item),
                                gtk_get_current_event_time (),
                                garcon_menu_item_get_icon_name (item),
                                &error);
          g_strfreev (argv);
          garcon_menu_item_unref (item);
          g_assert (succeed);

    }
    g_free (desktop_file);
}
Esempio n. 8
0
// This was the 2.8 showstopper error
RESULT
test_shell_argv4 ()
{
    GError *error;
    gint argc;
    gchar **argv;
    gboolean ret;
    char *str = "'/usr/bin/gnome-terminal' -e \"bash -c 'read -p \\\"Press any key to continue...\\\" -n1;'\"";

    argv = NULL;
    argc = 0;
    error = NULL;
    ret = g_shell_parse_argv (str, &argc, &argv, &error);
    if (!ret)
        return FAILED ("1. It should return TRUE");
    if (argc != 3)
        return FAILED ("2. argc was %d", argc);
    if (argv == NULL)
        return FAILED ("3. argv[0] was NULL");
    if (error != NULL)
        return FAILED ("4. error was set");

    if (strcmp (argv [0], "/usr/bin/gnome-terminal"))
        return FAILED ("5. Expected /usr/bin/gnome-terminal got %s", argv [0]);
    if (strcmp (argv [1], "-e"))
        return FAILED ("6. Expected -e, got: %s", argv [1]);
    if (strcmp (argv [2], "bash -c 'read -p \"Press any key to continue...\" -n1;'"))
        return FAILED ("7. Got unexpected result: %s\n", argv [2]);

    return OK;
}
Esempio n. 9
0
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;
}
Esempio n. 10
0
static void parse_line(char *line_read)
{
	gchar **argvp;
	int argcp;
	int i;

	if (line_read == NULL) {
		printf("\n");
		cmd_exit(0, NULL);
		return;
	}

	line_read = g_strstrip(line_read);

	if (*line_read == '\0')
		return;

	add_history(line_read);

	g_shell_parse_argv(line_read, &argcp, &argvp, NULL);

	for (i = 0; commands[i].cmd; i++)
		if (strcasecmp(commands[i].cmd, argvp[0]) == 0)
			break;

	if (commands[i].cmd)
		commands[i].func(argcp, argvp);
	else
		printf("%s: command not found\n", argvp[0]);

	g_strfreev(argvp);
}
Esempio n. 11
0
static void
run (const gchar *command)
{
  gchar buffer[2048];
  GError *error = NULL;
  gchar **argv;
  gint    argc;
  pid_t   pid;

  g_snprintf (buffer, 2048, "env DYLD_FORCE_FLAT_NAMESPACE= LD_BIND_NOW=true "
              "SESSION_MANAGER= %s", command);

  if (!g_shell_parse_argv (buffer, &argc, &argv, &error))
    {
      g_warning ("Unable to parse \"%s\": %s", buffer, error->message);
      g_error_free (error);
      return;
    }

  if (g_spawn_async (NULL, argv, NULL,
                     G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
                     NULL, NULL, &pid, &error))
    {
      guint id = g_timeout_add (300, run_timeout, &pid);
      gtk_main ();
      g_source_remove (id);
    }
  else
    {
      g_warning ("Unable to exec \"%s\": %s", buffer, error->message);
      g_error_free (error);
    }

  g_strfreev (argv);
}
bool
nsGNOMEShellService::HandlerMatchesAppName(const char* aHandler)
{
  bool matches = false;
  gint argc;
  gchar** argv;
  if (g_shell_parse_argv(aHandler, &argc, &argv, nullptr) && argc > 0) {
    gchar* command = nullptr;
    if (!mUseLocaleFilenames)
      command = g_find_program_in_path(argv[0]);
    else {
      gchar* nativeFile = g_filename_from_utf8(argv[0], -1,
                                               nullptr, nullptr, nullptr);
      if (nativeFile) {
        command = g_find_program_in_path(nativeFile);
        g_free(nativeFile);
      }
    }
    matches = command && mAppPath.Equals(command);
    g_free(command);
    g_strfreev(argv);
  }

  return matches;
}
Esempio n. 13
0
static gboolean
add_command(DBusMessageIter *iter, const gchar *command_line) {
  gint argc;
  gint x;
  char **argv;
  GError *err = NULL;
  DBusMessageIter array_iter;

  if (!g_shell_parse_argv(command_line, &argc, &argv, &err)) {
    HAL_ERROR (("Error parsing commandline '%s': %s", 
                 command_line, err->message));
    g_error_free (err);
    return FALSE;
  }
  if (!dbus_message_iter_open_container(iter, 
                                   DBUS_TYPE_ARRAY,
                                   DBUS_TYPE_STRING_AS_STRING,
                                   &array_iter))
    DIE (("No memory"));
  for (x = 0 ; argv[x] != NULL; x++) {
    dbus_message_iter_append_basic(&array_iter, DBUS_TYPE_STRING, &argv[x]);
  }
  dbus_message_iter_close_container(iter, &array_iter);

  g_strfreev(argv);
  return TRUE;
}
Esempio n. 14
0
int main (int argc, char *argv[])
{
    /* Make sure we exit cleanly (needed for profiling among other things) */
  g_shell_parse_argv(sphinx_command,&argc,&argv,NULL);
     gtk_init(&argc, &argv);
 
     scr = wnck_screen_get_default();
     while(gtk_events_pending()) gtk_main_iteration();
     win = wnck_screen_get_active_window(scr);
      tmp=wnck_screen_get_windows(wnck_window_get_screen(win));
     signal(SIGINT, &sighandler);

    fbs_init (argc, argv);
    
    if ((ad = ad_open_sps (SAMPLE_RATE)) == NULL)
	E_FATAL("ad_open_sps failed\n");

    // E_INFO("%s COMPILED ON: %s, AT: %s\n\n", argv[0], __DATE__, __TIME__);

    if (setjmp(jbuf) == 0) {
      utterance_loop (argc,argv);
    }

    fbs_end ();
    ad_close (ad);

    return 0;
}
Esempio n. 15
0
// This is https://bugzilla.novell.com/show_bug.cgi?id=655896
RESULT
test_shell_argv5 ()
{
	GError *error;
	gint argc;
	gchar **argv;
	gboolean ret;
	char *str = "echo \"foo\",\"bar\"";

	argv = NULL;
	argc = 0;
	error = NULL;
	ret = g_shell_parse_argv (str, &argc, &argv, &error);
	if (!ret)
		return FAILED ("1. It should return TRUE");
	if (argc != 2)
		return FAILED ("2. argc was %d expected 2", argc);
	if (argv == NULL)
		return FAILED ("3. argv[0] was NULL");
	if (error != NULL)
		return FAILED ("4. error was set");

	if (strcmp (argv [0], "echo"))
		return FAILED ("5. Expected echo got %s", argv [0]);
	if (strcmp (argv [1], "foo,bar"))
		return FAILED ("6. Expected foo,bar, got: %s", argv [1]);
	
	return OK;
}
Esempio n. 16
0
static void
custom_command_entry_changed_cb (GtkEntry *entry)
{
	const char *command;
	GError *error = NULL;

	command = gtk_entry_get_text (entry);

	if (g_shell_parse_argv (command, NULL, NULL, &error))
	{
		gtk_entry_set_icon_from_stock (entry, GTK_PACK_END, NULL);
	}
	else
	{
		char *tooltip;

		gtk_entry_set_icon_from_stock (entry, GTK_PACK_END, GTK_STOCK_DIALOG_WARNING);

		tooltip = g_strdup_printf (_("Error parsing command: %s"), error->message);
		gtk_entry_set_icon_tooltip_text (entry, GTK_PACK_END, tooltip);
		g_free (tooltip);

		g_error_free (error);
	}
}
Esempio n. 17
0
static void parse_line(char *line_read)
{
	gchar **argvp;
	int argcp;
	int i;

	line_read = g_strstrip(line_read);

	if (*line_read == '\0')
		goto done;

	g_shell_parse_argv(line_read, &argcp, &argvp, NULL);

	for (i = 0; commands[i].cmd; i++)
		if (strcasecmp(commands[i].cmd, argvp[0]) == 0)
			break;

	if (commands[i].cmd)
		commands[i].func(argcp, argvp);
	else
		resp_error(err_BAD_CMD);

	g_strfreev(argvp);

done:
	free(line_read);
}
Esempio n. 18
0
File: main.c Progetto: nzinfo/ibus
/**
 * execute_cmdline:
 * @cmdline: An absolute path of the executable and its parameters, e.g.  "/usr/lib/ibus/ibus-x11 --kill-daemon".
 * @returns: TRUE if both parsing cmdline and executing the command succeed.
 *
 * Execute cmdline. Child process's stdin, stdout, and stderr are attached to /dev/null.
 * You don't have to handle SIGCHLD from the child process since glib will do.
 */
static gboolean
execute_cmdline (const gchar *cmdline)
{
    g_assert (cmdline);

    gint argc = 0;
    gchar **argv = NULL;
    GError *error = NULL;
    if (!g_shell_parse_argv (cmdline, &argc, &argv, &error)) {
        g_warning ("Can not parse cmdline `%s` exec: %s", cmdline, error->message);
        g_error_free (error);
        return FALSE;
    }

    error = NULL;
    gboolean retval = g_spawn_async (NULL, argv, NULL,
                                     G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
                                     NULL, NULL,
                                     NULL, &error);
    g_strfreev (argv);

    if (!retval) {
        g_warning ("Can not execute cmdline `%s`: %s", cmdline, error->message);
        g_error_free (error);
        return FALSE;
    }

    return TRUE;
}
static void
retrieve_highres_icon (WebappMonitor *monitor, const gchar *desktop_file)
{
  GKeyFile *key_file;
  gchar *s;
  GError *error = NULL;

  /* Get URL to get icon for */
  key_file = g_key_file_new ();
  if (!g_key_file_load_from_data (key_file, desktop_file, strlen (desktop_file), 0, &error)) {
    g_warning ("Could not parse desktop file: %s", error->message);
    g_error_free (error);

    goto out;
  }

  if (get_icon_size (key_file) >= 64)
    goto out;

  s =  g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
  if (s != NULL) {
    gint n_args, i;
    gchar **args, *url = NULL;

    g_debug ("Parsing command line %s", s);

    if (!g_shell_parse_argv (s, &n_args, &args, &error)) {
      g_debug ("Failed parsing command line %s", s);
      goto out;
    }

    for (i = 0; i < n_args && args[i] != NULL; i++) {
      g_debug ("Processing argument %s", args[i]);
      if (g_str_has_prefix (args[i], "--app=")) {
	url = g_strdup (args[i] + 6);
	g_debug ("Found URL %s", url);
	break;
      }
    }

    if (url != NULL) {
      NPVariant url_varg, result;

      STRINGZ_TO_NPVARIANT(url, url_varg);
      NULL_TO_NPVARIANT(result);

      if (!NPN_InvokeDefault (monitor->instance, monitor->icon_loader_callback, &url_varg, 1, &result))
      	g_debug ("Failed calling JS callback");

      g_free (url);
      NPN_ReleaseVariantValue (&result);
    }

    g_strfreev (args);
    g_free (s);
  }

 out:
  g_key_file_free (key_file);
}
Esempio n. 20
0
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;
	}
}
Esempio n. 21
0
EphyWebApplication *
ephy_web_application_for_profile_directory (const char *profile_dir)
{
  EphyWebApplication *app;
  char *desktop_file_path;
  const char *id;
  GDesktopAppInfo *desktop_info;
  const char *exec;
  int argc;
  char **argv;
  GFile *file;
  GFileInfo *file_info;
  guint64 created;
  GDate *date;

  id = get_app_id_from_profile_directory (profile_dir);
  if (!id)
    return NULL;

  app = g_new0 (EphyWebApplication, 1);
  app->id = g_strdup (id);

  app->desktop_file = get_app_desktop_filename (id);
  desktop_file_path = g_build_filename (profile_dir, app->desktop_file, NULL);
  desktop_info = g_desktop_app_info_new_from_filename (desktop_file_path);
  if (!desktop_info) {
    ephy_web_application_free (app);
    g_free (desktop_file_path);
    return NULL;
  }

  app->name = g_strdup (g_app_info_get_name (G_APP_INFO (desktop_info)));
  app->icon_url = g_desktop_app_info_get_string (desktop_info, "Icon");
  exec = g_app_info_get_commandline (G_APP_INFO (desktop_info));
  if (g_shell_parse_argv (exec, &argc, &argv, NULL)) {
    app->url = g_strdup (argv[argc - 1]);
    g_strfreev (argv);
  }

  g_object_unref (desktop_info);

  file = g_file_new_for_path (desktop_file_path);

  /* FIXME: this should use TIME_CREATED but it does not seem to be working. */
  file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, 0, NULL, NULL);
  created = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);

  date = g_date_new ();
  g_date_set_time_t (date, (time_t)created);
  g_date_strftime (app->install_date, 127, "%x", date);

  g_date_free (date);
  g_object_unref (file);
  g_object_unref (file_info);
  g_free (desktop_file_path);

  return app;
}
Esempio n. 22
0
File: gedit.c Progetto: TCC-FEI/VC
guint32 run_app(gpointer data) {
    gint argc;
    gchar** argv;
    g_shell_parse_argv("/usr/bin/gedit", &argc, &argv, NULL);
    g_spawn_async(NULL, argv, NULL,
        G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL,
        NULL, NULL);
    g_strfreev(argv);
}
Esempio n. 23
0
void lxdm_get_tty(void)
{
	char *s = g_key_file_get_string(config, "server", "arg", 0);
	int arc;
	char **arg;
	int len;
	int gotvtarg = 0;
	gboolean plymouth;
    
	plymouth=plymouth_is_running();
	if(plymouth)
	{
		g_message("found plymouth running\n");
		plymouth_prepare_transition();
	}

	old_tty=get_active_vt();
	if( !s ) s = g_strdup("/usr/bin/X");
	g_shell_parse_argv(s, &arc, &arg, 0);
	g_free(s);
	for( len = 0; arg && arg[len]; len++ )
	{
		char *p = arg[len];
		if( !strncmp(p, "vt", 2) && isdigit(p[2]) &&
		( !p[3] || (isdigit(p[3]) && !p[4]) ) )
		{
			def_tty = atoi(p + 2);
			gotvtarg = 1;
		}
		else if(!strcmp(p,"-background") || !strcmp(p,"-nr"))
		{
			nr_tty=1;
		}
		else if(p[0]==':' && isdigit(p[1]))
		{
			def_display=atoi(p+1);
		}
	}
	if(!gotvtarg)
	{
		/* support plymouth */
		if(g_key_file_get_integer(config, "server", "active_vt", 0) )
			/* use the active vt */
			def_tty = old_tty;
		if(plymouth)
		{
			nr_tty=1;
			plymouth_quit_with_transition();
		}
	}
	else
	{
		if(plymouth) /* set tty and plymouth running */
			plymouth_quit_without_transition();
	}
	g_strfreev(arg);
}
static GPtrArray *
parse_sendmail_args (const gchar *binary,
                     const gchar *args,
                     const gchar *from_addr,
                     CamelAddress *recipients)
{
	GPtrArray *args_arr;
	gint ii, len, argc = 0;
	gchar **argv = NULL;

	g_return_val_if_fail (binary != NULL, NULL);
	g_return_val_if_fail (args != NULL, NULL);
	g_return_val_if_fail (from_addr != NULL, NULL);

	len = camel_address_length (recipients);

	args_arr = g_ptr_array_new_full (5, g_free);
	g_ptr_array_add (args_arr, g_strdup (binary));

	if (args && g_shell_parse_argv (args, &argc, &argv, NULL) && argc > 0 && argv) {
		for (ii = 0; ii < argc; ii++) {
			const gchar *arg = argv[ii];

			if (g_strcmp0 (arg, "%F") == 0) {
				g_ptr_array_add (args_arr, g_strdup (from_addr));
			} else if (g_strcmp0 (arg, "%R") == 0) {
				gint jj;

				for (jj = 0; jj < len; jj++) {
					const gchar *addr = NULL;

					if (!camel_internet_address_get (
						CAMEL_INTERNET_ADDRESS (recipients), jj, NULL, &addr)) {

						/* should not happen, as the array is checked beforehand */

						g_ptr_array_free (args_arr, TRUE);
						g_strfreev (argv);

						return NULL;
					}

					g_ptr_array_add (args_arr, g_strdup (addr));
				}
			} else {
				g_ptr_array_add (args_arr, g_strdup (arg));
			}
		}

		g_strfreev (argv);
	}

	g_ptr_array_add (args_arr, NULL);

	return args_arr;
}
/* An application is valid if:
 *
 * 1) The file exists
 * 2) The user has permissions to run the file
 */
static gboolean
check_application (CajaOpenWithDialog *dialog)
{
    char *command;
    char *path = NULL;
    char **argv = NULL;
    int argc;
    GError *error = NULL;
    gint retval = TRUE;

    command = NULL;
    if (dialog->details->selected_app_info != NULL)
    {
        command = g_strdup (g_app_info_get_executable (dialog->details->selected_app_info));
    }

    if (command == NULL)
    {
        command = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->details->entry)));
    }

    g_shell_parse_argv (command, &argc, &argv, &error);
    if (error)
    {
        eel_show_error_dialog (_("Could not run application"),
                               error->message,
                               GTK_WINDOW (dialog));
        g_error_free (error);
        retval = FALSE;
        goto cleanup;
    }

    path = g_find_program_in_path (argv[0]);
    if (!path)
    {
        char *error_message;

        error_message = g_strdup_printf (_("Could not find '%s'"),
                                         argv[0]);

        eel_show_error_dialog (_("Could not find application"),
                               error_message,
                               GTK_WINDOW (dialog));
        g_free (error_message);
        retval = FALSE;
        goto cleanup;
    }

cleanup:
    g_strfreev (argv);
    g_free (path);
    g_free (command);

    return retval;
}
Esempio n. 26
0
int helper_parse_setup ( char * string, char ***output, int *length, ... )
{
    GError     *error = NULL;
    GHashTable *h;
    h = g_hash_table_new ( g_str_hash, g_str_equal );
    // By default, we insert terminal and ssh-client
    g_hash_table_insert ( h, "{terminal}", config.terminal_emulator );
    g_hash_table_insert ( h, "{ssh-client}", config.ssh_client );
    // Add list from variable arguments.
    va_list ap;
    va_start ( ap, length );
    while ( 1 ) {
        char * key = va_arg ( ap, char * );
        if ( key == NULL ) {
            break;
        }
        char *value = va_arg ( ap, char * );
        if ( value == NULL ) {
            break;
        }
        g_hash_table_insert ( h, key, value );
    }
    va_end ( ap );

    // Replace hits within {-\w+}.
    GRegex *reg = g_regex_new ( "{[-\\w]+}", 0, 0, NULL );
    char   *res = g_regex_replace_eval ( reg,
                                         string, -1,
                                         0, 0, helper_eval_cb, h,
                                         NULL );
    // Free regex.
    g_regex_unref ( reg );
    // Destroy key-value storage.
    g_hash_table_destroy ( h );
    // Parse the string into shell arguments.
    if ( g_shell_parse_argv ( res, length, output, &error ) ) {
        g_free ( res );
        return TRUE;
    }
    g_free ( res );
    // Throw error if shell parsing fails.
    if ( error ) {
        char *msg = g_strdup_printf ( "Failed to parse: '%s'\nError: '%s'", string,
                                      error->message );
#ifdef error_dialog
        error_dialog ( msg );
#else
        fputs ( msg, stderr );
#endif
        g_free ( msg );
        // print error.
        g_error_free ( error );
    }
    return FALSE;
}
Esempio n. 27
0
static gboolean
launch_previewer (void)
{
	GString *cmd_str;
	gchar   *cmd;
	gint     argc;
	gchar  **argv;
	gboolean retval = FALSE;
	GError  *error = NULL;

	/* Rebuild the command line, ignoring options
	 * not supported by the previewer and taking only
	 * the first path given
	 */
	cmd_str = g_string_new ("atril-previewer");
		
	if (print_settings) {
		gchar *quoted;

		quoted = g_shell_quote (print_settings);
		g_string_append_printf (cmd_str, " --print-settings %s", quoted);
		g_free (quoted);
	}

	if (unlink_temp_file)
		g_string_append (cmd_str, " --unlink-tempfile");

	if (file_arguments) {
		gchar *quoted;
		
		quoted = g_shell_quote (file_arguments[0]);
		g_string_append_printf (cmd_str, " %s", quoted);
		g_free (quoted);
	}

	cmd = g_string_free (cmd_str, FALSE);
	g_shell_parse_argv (cmd, &argc, &argv, &error);
	g_free (cmd);
	
	if (!error) {
		retval = gdk_spawn_on_screen (gdk_screen_get_default (),
					      NULL, argv, NULL,
					      G_SPAWN_SEARCH_PATH,
					      NULL, NULL, NULL,
					      &error);
		g_strfreev (argv);
	}

	if (error) {
		g_warning ("Error launching previewer: %s\n", error->message);
		g_error_free (error);
	}

	return retval;
}
Esempio n. 28
0
NS_IMETHODIMP
nsGNOMEShellService::OpenApplication(PRInt32 aApplication)
{
  nsCAutoString scheme;
  if (aApplication == APPLICATION_MAIL)
    scheme.Assign("mailto");
  else if (aApplication == APPLICATION_NEWS)
    scheme.Assign("news");
  else
    return NS_ERROR_NOT_AVAILABLE;

  nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);

  PRBool enabled;
  nsCAutoString appCommand;
  gconf->GetAppForProtocol(scheme, &enabled, appCommand);

  if (!enabled)
    return NS_ERROR_FAILURE;

  // XXX we don't currently handle launching a terminal window.
  // If the handler requires a terminal, bail.
  PRBool requiresTerminal;
  gconf->HandlerRequiresTerminal(scheme, &requiresTerminal);
  if (requiresTerminal)
    return NS_ERROR_FAILURE;

  // Perform shell argument expansion
  int argc;
  char **argv;
  if (!g_shell_parse_argv(appCommand.get(), &argc, &argv, NULL))
    return NS_ERROR_FAILURE;

  char **newArgv = new char*[argc + 1];
  int newArgc = 0;

  // Run through the list of arguments.  Copy all of them to the new
  // argv except for %s, which we skip.
  for (int i = 0; i < argc; ++i) {
    if (strcmp(argv[i], "%s") != 0)
      newArgv[newArgc++] = argv[i];
  }

  newArgv[newArgc] = nsnull;

  gboolean err = g_spawn_async(NULL, newArgv, NULL, G_SPAWN_SEARCH_PATH,
                               NULL, NULL, NULL, NULL);

  g_strfreev(argv);
  delete[] newArgv;

  return err ? NS_OK : NS_ERROR_FAILURE;
}
Esempio n. 29
0
static VALUE
shell_parse(VALUE self, VALUE command_line)
{
    gint argc;
    gchar **argv;
    GError *error = NULL;

    if (!g_shell_parse_argv(RVAL2CSTR(command_line), &argc, &argv, &error))
        RAISE_GERROR(error);

    return STRV2RVAL_FREE(argv);
}
Esempio n. 30
0
/* An application is valid if:
 *
 * 1) The file exists
 * 2) The user has permissions to run the file
 */
static gboolean
check_application (GtkAppChooserDialog  *self,
                   GAppInfo            **app_out)
{
  const char *command;
  char *path = NULL;
  char **argv = NULL;
  int argc;
  GError *error = NULL;
  gint retval = TRUE;
  GAppInfo *info;

  command = NULL;

  info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->priv->app_chooser_widget));
  command = g_app_info_get_executable (info);

  g_shell_parse_argv (command, &argc, &argv, &error);

  if (error)
    {
      show_error_dialog (_("Could not run application"),
                         error->message,
                         GTK_WINDOW (self));
      g_error_free (error);
      retval = FALSE;
      goto cleanup;
    }

  path = g_find_program_in_path (argv[0]);
  if (!path)
    {
      char *error_message;

      error_message = g_strdup_printf (_("Could not find '%s'"),
                                       argv[0]);

      show_error_dialog (_("Could not find application"),
                         error_message,
                         GTK_WINDOW (self));
      g_free (error_message);
      retval = FALSE;
      goto cleanup;
    }

  *app_out = info;

 cleanup:
  g_strfreev (argv);
  g_free (path);

  return retval;
}