コード例 #1
0
int
main (int argc, char *argv[])
{
#ifdef G_OS_WIN32
  argv0 = argv[0];
  if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'c')
    {
      int ttl = atoi (argv[1] + 2);
      Sleep (ttl * 1000);
      /* Exit on purpose with STILL_ACTIVE (which isn't a very common
       * exit status) to verify that g_child_watch_check() in gmain.c
       * doesn't believe a child still to be active if it happens to
       * exit with that status.
       */
      exit (STILL_ACTIVE);
    }
#endif
  /* Only run the test, if threads are enabled and a default thread
   * implementation is available.
   */
#if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE)
#ifdef TEST_THREAD
  g_thread_init (NULL);
#else
  GPid pid;
#endif
  main_loop = g_main_loop_new (NULL, FALSE);

#ifdef G_OS_WIN32
  system ("ipconfig /all");
#else
  system ("/bin/true");
#endif

  alive = 2;
  g_timeout_add (30000, quit_loop, main_loop);

#ifdef TEST_THREAD
  g_thread_create (test_thread, GINT_TO_POINTER (10), FALSE, NULL);
  g_thread_create (test_thread, GINT_TO_POINTER (20), FALSE, NULL);
#else
  pid = get_a_child (10);
  g_child_watch_add (pid, (GChildWatchFunc) child_watch_callback,
		     GINT_TO_POINTER (10));
  pid = get_a_child (20);
  g_child_watch_add (pid, (GChildWatchFunc) child_watch_callback,
		     GINT_TO_POINTER (20));
#endif
  
  g_main_loop_run (main_loop);

  if (alive > 0)
    {
      g_warning ("%d children still alive\n", alive);
      return 1;
    }
    
#endif
   return 0;
}
コード例 #2
0
/* Run the I6 compiler. This function is called from a child process watch, so
 the GDK lock is not held and must be acquired for any GUI calls. */
static void
start_i6_compiler(CompilerData *data)
{
    I7_STORY_USE_PRIVATE(data->story, priv);

    GFile *i6_compiler = i7_app_get_binary_file(i7_app_get(), INFORM6_COMPILER_NAME);
    char *i6out = g_strconcat("output.", i7_story_get_extension(data->story), NULL);
    GFile *i6_output = g_file_get_child(data->builddir_file, i6out);
    g_free(i6out);

    /* Build the command line */
    gchar **commandline = g_new(gchar *, 6);
    commandline[0] = g_file_get_path(i6_compiler);
    commandline[1] = get_i6_compiler_switches(data->use_debug_flags, i7_story_get_story_format(data->story));
    commandline[2] = g_strdup("$huge");
    commandline[3] = g_strdup("auto.inf");
    commandline[4] = g_file_get_path(i6_output);
    commandline[5] = NULL;

    g_object_unref(i6_compiler);
    g_object_unref(i6_output);

    GPid child_pid = run_command_hook(data->builddir_file, commandline,
                                      priv->progress, (IOHookFunc *)display_i6_status, data->story, TRUE, TRUE);
    /* set up a watch for the exit status */
    g_child_watch_add(child_pid, (GChildWatchFunc)finish_i6_compiler, data);

    g_strfreev(commandline);
}
コード例 #3
0
ファイル: panel-run-dialog.c プロジェクト: braikar/mate-panel
static gboolean
panel_run_dialog_launch_command (PanelRunDialog *dialog,
				 const char     *command,
				 const char     *locale_command)
{
	GdkScreen  *screen;
	gboolean    result;
	GError     *error = NULL;
	char      **argv;
	int         argc;
	GPid        pid;

	if (!command_is_executable (locale_command, &argc, &argv))
		return FALSE;

	screen = gtk_window_get_screen (GTK_WINDOW (dialog->run_dialog));

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->terminal_checkbox)))
		mate_desktop_prepend_terminal_to_vector (&argc, &argv);

#if GTK_CHECK_VERSION (3, 0, 0)
	result = g_spawn_async (NULL, /* working directory */
				argv,
				NULL, /* envp */
				G_SPAWN_SEARCH_PATH,
				NULL,
				NULL,
				&pid,
				&error);
#else
	result = gdk_spawn_on_screen (screen,
				      NULL, /* working directory */
				      argv,
				      NULL, /* envp */
				      G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
				      NULL, /* child setup func */
				      NULL, /* user data */
				      &pid, /* child pid */
				      &error);
#endif

	if (!result) {
		char *primary;

		primary = g_markup_printf_escaped (_("Could not run command '%s'"),
						   command);
		panel_error_dialog (GTK_WINDOW (dialog->run_dialog), NULL,
				    "cannot_spawn_command", TRUE,
				    primary, error->message);
		g_free (primary);

		g_error_free (error);
	} else {
		g_child_watch_add (pid, dummy_child_watch, NULL);
	}

	g_strfreev (argv);

	return result;
}
コード例 #4
0
ファイル: gutachter-suite.c プロジェクト: herzi/gutachter
static void
finalize (GObject* object)
{
  if (PRIV (object)->error)
    {
      g_error_free (PRIV (object)->error);
    }

  if (PRIV (object)->io_watch)
    {
      g_source_remove (PRIV (object)->io_watch);
    }
  if (PRIV (object)->child_watch)
    {
      g_source_remove (PRIV (object)->child_watch);
      g_child_watch_add (PRIV (object)->pid, cleanup_func, NULL);
    }

  g_object_unref (PRIV (object)->hierarchy);
  g_object_unref (PRIV (object)->file_monitor);
  g_object_unref (PRIV (object)->file);
  g_test_log_buffer_free (PRIV (object)->buffer);

  G_OBJECT_CLASS (gutachter_suite_parent_class)->finalize (object);
}
コード例 #5
0
ファイル: babel.c プロジェクト: gdt/viking
/**
 * babel_general_convert:
 * @args: The command line arguments passed to GPSBabel
 * @cb: callback that is run for each line of GPSBabel output and at completion of the run
 *      callback may be NULL
 * @user_data: passed along to cb
 *
 * The function to actually invoke the GPSBabel external command
 *
 * Returns: %TRUE on successful invocation of GPSBabel command
 */
static gboolean babel_general_convert( BabelStatusFunc cb, gchar **args, gpointer user_data )
{
  gboolean ret = FALSE;
  GPid pid;
  GError *error = NULL;
  gint babel_stdout;

  if (!g_spawn_async_with_pipes (NULL, args, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL, &babel_stdout, NULL, &error)) {
    g_warning ("Async command failed: %s", error->message);
    g_error_free(error);
    ret = FALSE;
  } else {

    gchar line[512];
    FILE *diag;
    diag = fdopen(babel_stdout, "r");
    setvbuf(diag, NULL, _IONBF, 0);

    while (fgets(line, sizeof(line), diag)) {
      if ( cb )
        cb(BABEL_DIAG_OUTPUT, line, user_data);
    }
    if ( cb )
      cb(BABEL_DONE, NULL, user_data);
    fclose(diag);
    diag = NULL;

    g_child_watch_add ( pid, (GChildWatchFunc) babel_watch, NULL );

    ret = TRUE;
  }
    
  return ret;
}
コード例 #6
0
ファイル: filesystem.c プロジェクト: hmallat/obexd
static void *capability_open(const char *name, int oflag, mode_t mode,
					void *context, size_t *size, int *err)
{
	struct capability_object *object = NULL;
	char *buf;
	const char *argv[2];

	if (oflag != O_RDONLY)
		goto fail;

	if (access_check(FTP_TARGET, FTP_TARGET_SIZE, ACCESS_OP_READ, name) < 0)
		goto fail;

	object = g_new0(struct capability_object, 1);
	object->pid = -1;
	object->output = -1;
	object->err = -1;

	if (name[0] != '!') {
		GError *gerr = NULL;
		gboolean ret;

		ret = g_file_get_contents(name, &buf, NULL, &gerr);
		if (ret == FALSE) {
			error("%s", gerr->message);
			g_error_free(gerr);
			goto fail;
		}

		object->buffer = g_string_new(buf);

		if (size)
			*size = object->buffer->len;

		goto done;
	}

	argv[0] = &name[1];
	argv[1] = NULL;

	object->pid = capability_exec(argv, &object->output, &object->err);
	if (object->pid < 0)
		goto fail;

	/* Watch cannot be removed while the process is still running */
	g_child_watch_add(object->pid, script_exited, object);

done:
	if (err)
		*err = 0;

	return object;

fail:
	if (err)
		*err = -EPERM;

	g_free(object);
	return NULL;
}
コード例 #7
0
ファイル: timedatex.c プロジェクト: AdamWill/timedatex
static void start_hwclock_call(gboolean hctosys, gboolean local, gboolean utc,
			       GDBusMethodInvocation *invocation, hwclock_call_handler handler,
			       struct method_call_data *handler_data) {
	char *argv[6] = { 0 };
	int argc = 0;
	GPid pid;
	GError *error = NULL;
	struct hwclock_call *hwclock_call;

	argv[argc++] = HWCLOCK_PATH;
	argv[argc++] = hctosys ? "--hctosys" : "--systohc";
	if (local)
		argv[argc++] = "--local";
	if (utc)
		argv[argc++] = "--utc";

	if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL |
			   G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, &pid, &error)) {
		g_printerr("%s\n", error->message);
		if (invocation)
			return_error(invocation, G_DBUS_ERROR_FAILED, "%s", error->message);
		g_error_free(error);
		return;
	}

	hwclock_call = g_new(struct hwclock_call, 1);
	hwclock_call->invocation = invocation;
	hwclock_call->handler = handler;
	hwclock_call->handler_data = (struct method_call_data *)g_memdup(handler_data, sizeof *handler_data);

	g_child_watch_add(pid, finish_hwclock_call, hwclock_call);
}
コード例 #8
0
GtkWidget *terminal_create (GError **error)
{
  GtkWidget *self = vte_terminal_new();

  VtePty *self_pty = vte_pty_new(0, error);
  
  if (!self_pty){
    g_free(self);
    return NULL;
  } else {
    GPid c_pid = 0;
    char *c_argv[] = { "dmesg", NULL };
    
    vte_terminal_set_pty_object(VTE_TERMINAL(self), self_pty);
    
    c_argv[0] = getenv("SHELL");
    
    if(g_spawn_async(getenv("HOME"), c_argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
		     (GSpawnChildSetupFunc) vte_pty_child_setup,
		     (void *) self_pty, &c_pid, error)){
      g_child_watch_add(c_pid, terminal_child_exited, self);
    } else {
      vte_pty_close(self_pty);
      g_object_unref(self_pty);
      g_object_unref(self);
      return NULL;
    }
  }

  vte_terminal_set_opacity(VTE_TERMINAL(self), 0);

  vte_terminal_set_scrollback_lines(VTE_TERMINAL(self), 255);

  return self;
}
コード例 #9
0
static void
gather_pid_callback (GDesktopAppInfo   *gapp,
		     GPid               pid,
		     gpointer           data)
{
	g_child_watch_add (pid, dummy_child_watch, NULL);
}
コード例 #10
0
ファイル: 4s-server.c プロジェクト: CloCkWeRX/4store
gboolean accept_fn (GIOChannel *source, GIOCondition condition, gpointer data)
{
  fsp_backend *backend = (fsp_backend *) data;
  int conn = accept(g_io_channel_unix_get_fd(source), NULL, NULL);

  if (conn == -1) {
    if (errno != EINTR) kb_error(LOG_ERR, "accept: %s", strerror(errno));
    return TRUE; /* try again */
  }

  pid_t pid = fork();
  if (pid == -1) {
    kb_error(LOG_ERR, "fork: %s", strerror(errno));
    close(conn);
  } else if (pid > 0) {
    /* parent process */
    g_child_watch_add(pid, child_exited, data);
    close(conn);
  } else {
    /* child process */
    fs_backend *be = backend->open(global_kb_name, 0);
    if (be) {
      fs_backend_set_min_free(be, global_disk_limit);
      child(conn, backend, be);
      backend->close(be);
    }
    close(conn);
    exit(0);
  }

  return TRUE;
}
コード例 #11
0
ファイル: pnat.c プロジェクト: 520lly/bluez
static gboolean start_pnatd(struct dun_server *server)
{
	struct dun_client *client = &server->client;
	GSpawnFlags flags = G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH;
	char *argv[] = { PNATD, client->tty_name, NULL };
	GError *err = NULL;
	GPid pid;

	g_spawn_async(NULL, argv, NULL, flags, NULL, NULL, &pid, &err);
	if (err != NULL) {
		error("Unable to spawn pnatd: %s", err->message);
		g_error_free(err);
		return FALSE;
	}

	DBG("pnatd started for %s with pid %d", client->tty_name, pid);

	client->pnatd_pid = pid;

	/* We do not store the GSource id since g_remove_source doesn't
	 * make sense for a child watch. If the callback gets removed
	 * waitpid won't be called and the child remains as a zombie)
	 */
	g_child_watch_add(pid, pnatd_exit, server);

	return TRUE;
}
コード例 #12
0
ファイル: gntmain.c プロジェクト: Lilitana/Pidgin
gboolean gnt_giveup_console(const char *wd, char **argv, char **envp,
		gint *stin, gint *stout, gint *sterr,
		void (*callback)(int status, gpointer data), gpointer data)
{
#if GLIB_CHECK_VERSION(2,4,0)
	GPid pid = 0;
	ChildProcess *cp = NULL;

	if (!g_spawn_async_with_pipes(wd, argv, envp,
			G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
			(GSpawnChildSetupFunc)endwin, NULL,
			&pid, stin, stout, sterr, NULL))
		return FALSE;

	cp = g_new0(ChildProcess, 1);
	cp->callback = callback;
	cp->data = data;
	g_source_remove(channel_read_callback);
	wm->mode = GNT_KP_MODE_WAIT_ON_CHILD;
	g_child_watch_add(pid, reap_child, cp);

	return TRUE;
#else
	return FALSE;
#endif
}
コード例 #13
0
ファイル: install-plugins.c プロジェクト: PeterXu/gst-mobile
GstInstallPluginsReturn
gst_install_plugins_async (gchar ** details, GstInstallPluginsContext * ctx,
    GstInstallPluginsResultFunc func, gpointer user_data)
{
  GstInstallPluginsAsyncHelper *helper;
  GPid pid;

  g_return_val_if_fail (details != NULL, GST_INSTALL_PLUGINS_INTERNAL_FAILURE);
  g_return_val_if_fail (func != NULL, GST_INSTALL_PLUGINS_INTERNAL_FAILURE);

  if (install_in_progress)
    return GST_INSTALL_PLUGINS_INSTALL_IN_PROGRESS;

  /* if we can't access our helper, don't bother */
  if (!g_file_test (gst_install_plugins_get_helper (),
          G_FILE_TEST_IS_EXECUTABLE))
    return GST_INSTALL_PLUGINS_HELPER_MISSING;

  if (!gst_install_plugins_spawn_child (details, ctx, &pid, NULL))
    return GST_INSTALL_PLUGINS_INTERNAL_FAILURE;

  helper = g_new (GstInstallPluginsAsyncHelper, 1);
  helper->func = func;
  helper->user_data = user_data;

  g_child_watch_add (pid, gst_install_plugins_installer_exited, helper);

  return GST_INSTALL_PLUGINS_STARTED_OK;
}
コード例 #14
0
ファイル: async_task.c プロジェクト: dthaluru/clr-cloud-init
bool async_task_exec(const gchar* command) {
	GPid pid = 0;
	GError *error = NULL;
	gchar* command_line = g_strescape(command, NULL);
	gchar* argvp[] = {SHELL_PATH, "-c", command_line, NULL };

	g_spawn_async(NULL, argvp, NULL,
	              G_SPAWN_DO_NOT_REAP_CHILD,
				  NULL, NULL, &pid, &error);

	if (error) {
		LOG(MOD "Error running async command: %s\n", error->message);
		g_error_free(error);
		g_free(command_line);
		return false;
	}

	g_child_watch_add(pid, async_task_callback, NULL);

	LOG(MOD "Executing [%d]: %s -c \"%s\"\n", pid, SHELL_PATH, command_line);

	g_free(command_line);

	G_LOCK(tasks);
	++tasks;
	G_UNLOCK(tasks);

	return true;
}
コード例 #15
0
ファイル: remminanxsession.c プロジェクト: 4myPAL/Remmina
gboolean
remmina_nx_session_invoke_proxy (RemminaNXSession *nx, gint display,
    GChildWatchFunc exit_func, gpointer user_data)
{
    gchar *argv[50];
    gint argc;
    GError *error = NULL;
    gboolean ret;
    gchar **envp;
    gchar *s;
    gint i;

    /* Copy all current environment variable, but change DISPLAY. Assume we should always have DISPLAY... */
    if (display >= 0)
    {
        envp = g_listenv ();
        for (i = 0; envp[i]; i++)
        {
            if (g_strcmp0 (envp[i], "DISPLAY") == 0)
            {
                s = g_strdup_printf ("DISPLAY=:%i", display);
            }
            else
            {
                s = g_strdup_printf ("%s=%s", envp[i], g_getenv (envp[i]));
            }
            g_free (envp[i]);
            envp[i] = s;
        }
    }
    else
    {
        envp = NULL;
    }

    argc = 0;
    argv[argc++] = g_strdup ("nxproxy");
    argv[argc++] = g_strdup ("-S");
    argv[argc++] = remmina_nx_session_get_proxy_option (nx);
    argv[argc++] = NULL;

    ret = g_spawn_async (NULL, argv, envp, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
        NULL, NULL, &nx->proxy_pid, &error);
    g_strfreev (envp);
    for (i = 0; i < argc; i++) g_free (argv[i]);

    if (!ret)
    {
        remmina_nx_session_set_application_error (nx, "%s", error->message);
        return FALSE;
    }

    if (exit_func)
    {
        nx->proxy_watch_source = g_child_watch_add (nx->proxy_pid, exit_func, user_data);
    }

    return TRUE;
}
コード例 #16
0
static void
start_next_task (System *system)
{
  unsigned task_index = system->n_finished_tasks + system->n_running_tasks;
  int stderr_pipe[2], stdout_pipe[2], stdin_pipe[2];
  int pid;
  Task *task = system->tasks->pdata[task_index];
  g_assert (task->state == TASK_WAITING);

  do_pipe (stdin_pipe);
  do_pipe (stdout_pipe);
  do_pipe (stderr_pipe);

retry_fork:
  pid = fork ();
  if (pid < 0)
    {
      if (errno == EINTR)
        goto retry_fork;
      else
        g_error ("error forking");
    }
  else if (pid == 0)
    {
      /* child process */
      dup2 (stdin_pipe[0], STDIN_FILENO);
      dup2 (stdout_pipe[1], STDOUT_FILENO);
      dup2 (stderr_pipe[1], STDERR_FILENO);
      do_exec (task->str);
      _exit (127);
    }

  /* parent process */
  close (stdin_pipe[0]);
  close (stdout_pipe[1]);
  close (stderr_pipe[1]);
  task->state = TASK_RUNNING;
  system->n_unstarted_tasks--;
  system->n_running_tasks++;
  task->info.running.pid = pid;
  task->info.running.stdin_fd = stdin_pipe[1];
  task->info.running.stdin_source = NULL;
  task->info.running.stdout_fd = stdout_pipe[0];
  task->info.running.stdout_source = NULL;
  task->info.running.stderr_fd = stderr_pipe[0];
  task->info.running.stderr_source = NULL;
  task->info.running.stdin_output_buffer = g_byte_array_new ();
  task->info.running.stdout_input_buffer = g_byte_array_new ();
  task->info.running.stderr_input_buffer = g_byte_array_new ();
  task->info.running.stdout_source = g_source_fd_new (task->info.running.stdout_fd, G_IO_IN, handle_stdout_readable, task);
  task->info.running.stderr_source = g_source_fd_new (task->info.running.stderr_fd, G_IO_IN, handle_stderr_readable, task);
  g_child_watch_add (pid, handle_child_watch_terminated, task);
  GTimeVal cur_time;
  g_get_current_time (&cur_time);
  SystemTrap *trap;
  for (trap = task->system->trap_list; trap; trap = trap->next)
    if (trap->funcs->handle_started)
      trap->funcs->handle_started (task, &cur_time, task->str, trap->trap_data);
}
コード例 #17
0
ファイル: msgproxy.c プロジェクト: wuruxu/golc
static void launch_thunderbird_async() {
  GPid pid;
  gchar *env[]  = {"TB3_HIDEUI_STARTUP=true", NULL};
  gchar *argv[] = {"/usr/bin/TB3-locale", "/opt/thunderbird-3.0.1/lib/thunderbird-3.0.1/thunderbird -UILocale %s", NULL};
  if(launch_app_async(argv, NULL, &pid, G_SPAWN_DO_NOT_REAP_CHILD)) {
    g_child_watch_add(pid, _app_watch_cb, NULL);
  }
}
コード例 #18
0
ファイル: nettool.c プロジェクト: GNOME/gnome-nettool
void
netinfo_text_buffer_insert (Netinfo * netinfo)
{
	gchar *dir = g_get_current_dir ();
	gint child_pid, pout;
	GIOChannel *channel;
	const gchar *charset;
	GIOStatus status;
	GError *err = NULL;

	g_return_if_fail (netinfo != NULL);
	g_return_if_fail (netinfo->command_line != NULL);

	if (g_spawn_async_with_pipes (dir, netinfo->command_line, NULL,
				      G_SPAWN_FILE_AND_ARGV_ZERO |
				      G_SPAWN_DO_NOT_REAP_CHILD, NULL,
				      NULL, &child_pid, NULL, &pout,
				      NULL,
				      &err)) {

		netinfo->child_pid = child_pid;
		netinfo->pipe_out = pout;
		fcntl (pout, F_SETFL, O_NONBLOCK);
		fcntl (pout, F_SETFL, O_NONBLOCK);
		netinfo->command_output = NULL;

		g_child_watch_add (child_pid, netinfo_reap_child, netinfo);

		g_get_charset(&charset);
		channel = g_io_channel_unix_new (pout);
		status = g_io_channel_set_encoding(channel,
						   charset,
						   &err);
		if (G_IO_STATUS_NORMAL == status) {
			g_io_add_watch (channel,
					G_IO_IN | G_IO_HUP |
					G_IO_ERR | G_IO_NVAL,
					netinfo_io_text_buffer_dialog, netinfo);
			g_io_channel_unref (channel);
		} else {
			g_warning ("Error: %s\n", err->message);
			g_error_free (err);
		}
	} else {
		gint len = strlen (err->message);

		if (netinfo->process_line != NULL) {
			(netinfo->process_line) ((gpointer) netinfo,
						 err->message, len, NULL);
		}
		netinfo_toggle_state (netinfo, ACTIVE, NULL);

		g_warning ("Error: %s\n", err->message);
		g_error_free (err);
	}

	g_free (dir);
}
コード例 #19
0
ファイル: msgproxy.c プロジェクト: wuruxu/golc
static GPid launch_davmail_async(gchar *filename) {
  GPid pid;
  gchar *argv[] = {"/usr/bin/davmail", NULL, NULL};
  argv[1] = filename;
  if(launch_app_async(argv, NULL, &pid, G_SPAWN_DO_NOT_REAP_CHILD)) {
    g_child_watch_add(pid, _app_watch_cb, NULL);
  }
  DEBUG("davmail %s pid = %d\n", filename, pid);
  return pid;
}
コード例 #20
0
/**
 * nm_arping_manager_start_probe:
 * @self: a #NMArpingManager
 * @timeout: maximum probe duration in milliseconds
 * @error: location to store error, or %NULL
 *
 * Start probing IP addresses for duplicates; when the probe terminates a
 * PROBE_TERMINATED signal is emitted.
 *
 * Returns: %TRUE on success, %FALSE on failure
 */
gboolean
nm_arping_manager_start_probe (NMArpingManager *self, guint timeout, GError **error)
{
    const char *argv[] = { NULL, "-D", "-q", "-I", NULL, "-c", NULL, "-w", NULL, NULL, NULL };
    NMArpingManagerPrivate *priv;
    GHashTableIter iter;
    AddressInfo *info;
    gs_free char *timeout_str = NULL;

    g_return_val_if_fail (NM_IS_ARPING_MANAGER (self), FALSE);
    g_return_val_if_fail (!error || !*error, FALSE);
    g_return_val_if_fail (timeout, FALSE);

    priv = NM_ARPING_MANAGER_GET_PRIVATE (self);
    g_return_val_if_fail (priv->state == STATE_INIT, FALSE);

    argv[4] = nm_platform_link_get_name (NM_PLATFORM_GET, priv->ifindex);
    g_return_val_if_fail (argv[4], FALSE);

    priv->completed = 0;

    argv[0] = nm_utils_find_helper ("arping", NULL, NULL);
    if (!argv[0]) {
        g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
                             "arping could not be found");
        return FALSE;
    }

    timeout_str = g_strdup_printf ("%u", timeout / 1000 + 2);
    argv[6] = timeout_str;
    argv[8] = timeout_str;

    g_hash_table_iter_init (&iter, priv->addresses);

    while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &info)) {
        gs_free char *tmp_str = NULL;
        gboolean success;

        argv[9] = nm_utils_inet4_ntop (info->address, NULL);
        _LOGD ("run %s", (tmp_str = g_strjoinv (" ", (char **) argv)));

        success = g_spawn_async (NULL, (char **) argv, NULL,
                                 G_SPAWN_STDOUT_TO_DEV_NULL |
                                 G_SPAWN_STDERR_TO_DEV_NULL |
                                 G_SPAWN_DO_NOT_REAP_CHILD,
                                 NULL, NULL, &info->pid, NULL);

        info->watch = g_child_watch_add (info->pid, arping_watch_cb, info);
    }

    priv->timer = g_timeout_add (timeout, arping_timeout_cb, self);
    priv->state = STATE_PROBING;

    return TRUE;
}
コード例 #21
0
ファイル: buttons.c プロジェクト: marc2100/odt2pdf
///unoconv_pid_watch wird aufgerufen sobald der unoconv-Prozess beendet ist
void unoconv_child_watch_func (GPid unoconv_pid,gint status,gpointer user_data){
	GError *error = NULL;

	//Status abfragen
	g_spawn_check_exit_status (status,&error);
	if (error!=NULL){
		g_warning("%s",error->message);
		g_error_free(error);
		error = NULL;
	}
	//Pid schließen (ist unter UNIX nicht nötig)
	g_spawn_close_pid(unoconv_pid);

	//pdftk aufruf bauen
	GPtrArray *pdftk_argv= g_ptr_array_new ();
	//Funktion zum aufräumen setzten
	g_ptr_array_set_free_func(pdftk_argv,ptr_array_clean);

	GPid pdftk_pid=0;
	fill_g_ptr_array (pdftk_argv,"pdftk");

	//den ListStore durchlaufen lassen, und pfad bauen
	gtk_tree_model_foreach(gtk_tree_view_get_model(gui_get_gtk_tree_viewer()),treemodel_ausgabe_pdftk,(gpointer)pdftk_argv);
	fill_g_ptr_array (pdftk_argv,"output");
	//speichert den Pfad
	g_ptr_array_add(pdftk_argv,(gpointer)keyfile_get_pdf_full_path());
	g_ptr_array_add(pdftk_argv,(gpointer)NULL);

	//PDF zusammenfügen
	g_spawn_async_with_pipes (NULL,
														(gchar**)pdftk_argv->pdata,
														NULL,
														G_SPAWN_SEARCH_PATH|G_SPAWN_DO_NOT_REAP_CHILD,
														NULL,
														NULL,
														&pdftk_pid,
														NULL,
														NULL,
														NULL,
														&error);
	if (error!=NULL){
		g_warning("%s",error->message);
		g_error_free(error);
		error = NULL;
	}

	//g_child_watch einrichten, um über Programmende(pdftk) informiert zu werden
	g_child_watch_add(pdftk_pid,pdftk_child_watch_func,NULL);
	//aufräumen
	g_ptr_array_free(pdftk_argv,TRUE);
	//g_print("das PDF \"%s\" wurde unter \"%s\" erstellt\n",keyfile_get_pdf_name(),keyfile_get_outputdir());
	//Buttons wieder aktivieren
		interface_ausgrauen(TRUE);
}
コード例 #22
0
static gboolean log_spawn (TghLogDialog *dialog, gchar **files, GPid *pid)
{
  GError *error = NULL;
  gint fd_out, fd_err;
  GIOChannel *chan_out, *chan_err;
  TghOutputParser *parser;
  gsize length;
  gint i;
  gchar **argv;

  length = 10;
  if(files)
    length += g_strv_length(files);

  argv = g_new(gchar*, length);

  argv[0] = "git";
  argv[1] = "--no-pager";
  argv[2] = "log";
  argv[3] = "--numstat";
  argv[4] = "--parents";
  argv[5] = "--pretty=fuller";
  argv[6] = "--boundary";
  argv[7] = "--date-order";
  argv[8] = "--";
  argv[length-1] = NULL;

  i = 9;
  if(files)
    while(*files)
      argv[i++] = *files++;

  if(!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, &fd_out, &fd_err, &error))
  {
    g_free (argv);
    return FALSE;
  }
  g_free (argv);

  parser = tgh_error_parser_new(GTK_WIDGET(dialog));

  g_child_watch_add(*pid, (GChildWatchFunc)tgh_child_exit, parser);

  chan_out = g_io_channel_unix_new(fd_out);
  chan_err = g_io_channel_unix_new(fd_err);
  g_io_add_watch(chan_out, G_IO_IN|G_IO_HUP, (GIOFunc)tgh_parse_output_func, tgh_log_parser_new(GTK_WIDGET(dialog)));
  g_io_add_watch(chan_err, G_IO_IN|G_IO_HUP, (GIOFunc)tgh_parse_output_func, parser);

  return TRUE;
}
コード例 #23
0
/**
 * Spawn a new process
 *
 * @param archive Should contain AM_Archive type of data
 * @param command Command, which we want to execute
 * @param input TRUE If we want to use our standard input, oterwise will be used /dev/null
 *
 */
void SpawnAsyncProcess(AM_Archive *archive, gchar *command, gboolean input, gboolean output_flag)
{
	GIOChannel *ioc , *err_ioc, *out_ioc;
	GError *error = NULL;
	gchar **argv;
	gint argcp, response;

	g_shell_parse_argv ( command , &argcp , &argv , NULL);
	if ( ! g_spawn_async_with_pipes (
		NULL,
		argv,
		NULL,
		G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
		NULL,
		NULL,
		&archive->child_pid,
		input ? &input_fd : NULL,
		&output_fd,
		&error_fd,
		&error) )
	{
		response = ShowGtkMessageDialog (NULL,GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK, "Can't run the archiver executable:",error->message);
		g_error_free (error);
		g_strfreev ( argv );
		archive->child_pid = 0;
		return;
	}
	g_strfreev ( argv );

	if ( archive->parse_output )
	{
		ioc = g_io_channel_unix_new ( output_fd );
		g_io_channel_set_encoding (ioc, locale , NULL);
		g_io_channel_set_flags ( ioc , G_IO_FLAG_NONBLOCK , NULL );
		g_io_add_watch (ioc, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL, archive->parse_output, archive);
		g_child_watch_add ( archive->child_pid, (GChildWatchFunc)am_a_watch_child, archive);
	}
	if (output_flag)
	{
		out_ioc = g_io_channel_unix_new ( output_fd );
		g_io_channel_set_encoding (out_ioc, locale , NULL);
		g_io_channel_set_flags ( out_ioc , G_IO_FLAG_NONBLOCK , NULL );
		g_io_add_watch (out_ioc, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL, am_a_report_child_stderr, NULL);
	}

	err_ioc = g_io_channel_unix_new ( error_fd );
	g_io_channel_set_encoding (err_ioc, locale , NULL);
	g_io_channel_set_flags ( err_ioc , G_IO_FLAG_NONBLOCK , NULL );
	g_io_add_watch (err_ioc, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL, am_a_report_child_stderr, NULL);
}
コード例 #24
0
static void
start_monitor (NMDHCPClient *self)
{
	NMDHCPClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE (self);

	g_return_if_fail (priv->pid > 0);

	/* Set up a timeout on the transaction to kill it after the timeout */
	priv->timeout_id = g_timeout_add_seconds (priv->timeout,
	                                          daemon_timeout,
	                                          self);
	priv->watch_id = g_child_watch_add (priv->pid,
	                                    (GChildWatchFunc) daemon_watch_cb,
	                                    self);
}
コード例 #25
0
static gboolean
nm_l2tp_start_l2tpd_binary (NML2tpPlugin *plugin,
                            NMSettingVPN *s_vpn,
                            GError **error)
{
	NML2tpPluginPrivate *priv = NM_L2TP_PLUGIN_GET_PRIVATE (plugin);
	GPid pid;
	const char *l2tpd_binary;
	GPtrArray *l2tpd_argv;
	pid_t my_pid = getpid ();

	l2tpd_binary = nm_find_l2tpd ();
	if (!l2tpd_binary) {
		g_set_error (error,
		             NM_VPN_PLUGIN_ERROR,
		             NM_VPN_PLUGIN_ERROR_LAUNCH_FAILED,
		             "%s",
		             _("Could not find the xl2tpd binary."));
		return FALSE;
	}

	l2tpd_argv = g_ptr_array_new ();
	g_ptr_array_add (l2tpd_argv, (gpointer) g_strdup (l2tpd_binary));
	g_ptr_array_add (l2tpd_argv, (gpointer) g_strdup ("-D"));
	g_ptr_array_add (l2tpd_argv, (gpointer) g_strdup ("-c"));
	g_ptr_array_add (l2tpd_argv, (gpointer) g_strdup_printf ("/var/run/nm-xl2tpd.conf.%d", my_pid));
	g_ptr_array_add (l2tpd_argv, (gpointer) g_strdup ("-C"));
	g_ptr_array_add (l2tpd_argv, (gpointer) g_strdup_printf ("/var/run/nm-xl2tpd_l2tp-control.%d", my_pid));
	g_ptr_array_add (l2tpd_argv, (gpointer) g_strdup ("-p")); /* pid file named using pid? */
	g_ptr_array_add (l2tpd_argv, (gpointer) g_strdup_printf ("/var/run/nm-xl2tpd_pid.%d", my_pid));
	g_ptr_array_add (l2tpd_argv, NULL);

	if (!g_spawn_async (NULL, (char **) l2tpd_argv->pdata, NULL,
	                    G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, error)) {
		free_args (l2tpd_argv);
		return FALSE;
	}
	free_args (l2tpd_argv);

	g_message(_("xl2tpd started with pid %d"), pid);

	NM_L2TP_PLUGIN_GET_PRIVATE (plugin)->pid_l2tpd = pid;
	g_child_watch_add (pid, l2tpd_watch_cb, plugin);

	priv->ppp_timeout_handler = g_timeout_add (NM_L2TP_WAIT_PPPD, pppd_timed_out, plugin);

	return TRUE;
}
コード例 #26
0
GPid
nm_dns_plugin_child_spawn (NMDnsPlugin *self,
                           const char **argv,
                           const char *pidfile,
                           const char *kill_match)
{
	NMDnsPluginPrivate *priv = NM_DNS_PLUGIN_GET_PRIVATE (self);
	GError *error = NULL;
	char *cmdline;

	g_return_val_if_fail (argv != NULL, 0);
	g_return_val_if_fail (argv[0] != NULL, 0);

	g_warn_if_fail (priv->progname == NULL);
	g_free (priv->progname);
	priv->progname = g_path_get_basename (argv[0]);

	if (pidfile) {
		g_return_val_if_fail (kill_match != NULL, 0);
		kill_existing (priv->progname, pidfile, kill_match);

		g_free (priv->pidfile);
		priv->pidfile = g_strdup (pidfile);
	}

	nm_log_info (LOGD_DNS, "DNS: starting %s...", priv->progname);
	cmdline = g_strjoinv (" ", (char **) argv);
	nm_log_dbg (LOGD_DNS, "DNS: command line: %s", cmdline);
	g_free (cmdline);

	priv->pid = 0;
	if (g_spawn_async (NULL, (char **) argv, NULL,
	                   G_SPAWN_DO_NOT_REAP_CHILD,
	                   child_setup,
	                   NULL, &priv->pid,
	                   &error)) {
		nm_log_dbg (LOGD_DNS, "%s started with pid %d", priv->progname, priv->pid);
		priv->watch_id = g_child_watch_add (priv->pid, (GChildWatchFunc) watch_cb, self);
	} else {
		nm_log_warn (LOGD_DNS, "Failed to spawn %s: (%d) %s",
		             priv->progname, error ? error->code : -1,
		             error && error->message ? error->message : "(unknown)");
		g_clear_error (&error);
	}

	return priv->pid;
}
コード例 #27
0
ファイル: gstreamill.c プロジェクト: bbshocking/gstreamill
static guint64 create_job_process (Job *job)
{
        GError *error = NULL;
        gchar *argv[16], *p;
        GPid pid;
        gint i, j;

        i = 0;
        argv[i++] = g_strdup (job->exe_path);
        argv[i++] = g_strdup ("-l");
        argv[i++] = g_strdup (job->log_dir);
        argv[i++] = g_strdup ("-n");
        argv[i++] = unicode_file_name_2_shm_name (job->name);
        argv[i++] = g_strdup ("-q");
        argv[i++] = g_strdup_printf ("%ld", strlen (job->description));
        p = jobdesc_get_debug (job->description);
        if (p != NULL) {
                argv[i++] = g_strdup_printf ("--gst-debug=%s", p);
                g_free (p);
        }
        argv[i++] = NULL;
        if (!g_spawn_async (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, &error)) {
                GST_ERROR ("Start job %s error, reason: %s.", job->name, error->message);
                for (j = 0; j < i; j++) {
                        if (argv[j] != NULL) {
                                g_free (argv[j]);
                        }
                }
                g_error_free (error);
                return JOB_STATE_START_FAILURE;
        }

        for (j = 0; j < i; j++) {
                if (argv[j] != NULL) {
                        g_free (argv[j]);
                }
        }
        job->worker_pid = pid;
        g_child_watch_add (pid, (GChildWatchFunc)child_watch_cb, job);

        while ((*(job->output->state) == JOB_STATE_READY) || (*(job->output->state) == JOB_STATE_VOID_PENDING)) {
                GST_WARNING ("waiting job process creating ... state: %s", job_state_get_name (*(job->output->state)));
                g_usleep (50000);
        }

        return *(job->output->state);
}
コード例 #28
0
gboolean
nm_dnsmasq_manager_start (NMDnsMasqManager *manager,
                          NMIP4Config *ip4_config,
                          GError **error)
{
	NMDnsMasqManagerPrivate *priv;
	NMCmdLine *dm_cmd;
	char *cmd_str;

	g_return_val_if_fail (NM_IS_DNSMASQ_MANAGER (manager), FALSE);
	if (error)
		g_return_val_if_fail (*error == NULL, FALSE);

	priv = NM_DNSMASQ_MANAGER_GET_PRIVATE (manager);

	kill_existing_for_iface (priv->iface, priv->pidfile);

	dm_cmd = create_dm_cmd_line (priv->iface, ip4_config, priv->pidfile, error);
	if (!dm_cmd)
		return FALSE;

	g_ptr_array_add (dm_cmd->array, NULL);

	nm_info ("Starting dnsmasq...");

	cmd_str = nm_cmd_line_to_str (dm_cmd);
	nm_debug ("Command line: %s", cmd_str);
	g_free (cmd_str);

	priv->pid = 0;
	if (!g_spawn_async (NULL, (char **) dm_cmd->array->pdata, NULL,
					G_SPAWN_DO_NOT_REAP_CHILD,
					dm_child_setup,
					NULL, &priv->pid, error)) {
		goto out;
	}

	nm_debug ("dnsmasq started with pid %d", priv->pid);

	priv->dm_watch_id = g_child_watch_add (priv->pid, (GChildWatchFunc) dm_watch_cb, manager);

 out:
	if (dm_cmd)
		nm_cmd_line_destroy (dm_cmd);

	return priv->pid > 0;
}
コード例 #29
0
ファイル: delete.c プロジェクト: FrodeSolheim/marco
static void
delete_ping_timeout_func (MetaDisplay *display,
                          Window       xwindow,
                          guint32      timestamp,
                          void        *user_data)
{
  MetaWindow *window = user_data;
  char *window_title;
  gchar *window_content, *tmp;
  GPid dialog_pid;

  meta_topic (META_DEBUG_PING,
              "Got delete ping timeout for %s\n",
              window->desc);

  if (window->dialog_pid >= 0)
    {
      meta_window_present_delete_dialog (window, timestamp);
      return;
    }

  window_title = g_locale_from_utf8 (window->title, -1, NULL, NULL, NULL);

  /* Translators: %s is a window title */
  tmp = g_strdup_printf (_("<tt>%s</tt> is not responding."),
                         window_title);
  window_content = g_strdup_printf (
      "<big><b>%s</b></big>\n\n<i>%s</i>",
      tmp,
      _("You may choose to wait a short while for it to "
        "continue or force the application to quit entirely."));

  g_free (window_title);

  dialog_pid =
    meta_show_dialog ("--question",
                      window_content, 0,
                      window->screen->number,
                      _("_Wait"), _("_Force Quit"), window->xwindow,
                      NULL, NULL);

  g_free (window_content);
  g_free (tmp);

  window->dialog_pid = dialog_pid;
  g_child_watch_add (dialog_pid, dialog_exited, window);
}
コード例 #30
0
ファイル: gstreamill.c プロジェクト: g522342435/gstreamill
static gchar * create_job_process (Job *job)
{
        GError *error = NULL;
        gchar *argv[16], path[512], *p;
        GPid pid;
        gint i, j;

        memset (path, '\0', sizeof (path));
        if (readlink ("/proc/self/exe", path, sizeof (path)) == -1) {
                GST_ERROR ("Read /proc/self/exe error.");
                return g_strdup ("create live job failure");
        }
        i = 0;
        argv[i++] = g_strdup (path);
        argv[i++] = g_strdup ("-l");
        argv[i++] = g_strdup (job->log_dir);
        argv[i++] = g_strdup ("-n");
        argv[i++] = g_strdup_printf ("%s", job->name);
        argv[i++] = g_strdup ("-q");
        argv[i++] = g_strdup_printf ("%ld", strlen (job->description));
        p = jobdesc_get_debug (job->description);
        if (p != NULL) {
                argv[i++] = g_strdup_printf ("--gst-debug=%s", p);
                g_free (p);
        }
        argv[i++] = NULL;
        if (!g_spawn_async (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, &error)) {
                GST_ERROR ("Start job %s error, reason: %s.", job->name, error->message);
                for (j = 0; j < i; j++) {
                        if (argv[j] != NULL) {
                                g_free (argv[j]);
                        }
                }
                g_error_free (error);
                return g_strdup ("create live job process failure");
        }

        for (j = 0; j < i; j++) {
                if (argv[j] != NULL) {
                        g_free (argv[j]);
                }
        }
        job->worker_pid = pid;
        g_child_watch_add (pid, (GChildWatchFunc)child_watch_cb, job);

        return g_strdup ("create live job process success");
}