gtester.c 1.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/* This file is part of gtester
 *
 * AUTHORS
 *     Sven Herzberg  <herzi@gnome-de.org>
 *
 * Copyright (C) 2007  Sven Herzberg
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

24 25 26 27 28 29 30 31 32 33 34 35
#include <glib.h>

static void
child_watch_cb (GPid     pid,
		gint     status,
		gpointer data)
{
	GMainLoop* loop = data;

	g_main_loop_quit (loop);
}

36 37 38 39
int
main (int   argc,
      char**argv)
{
40 41 42 43 44 45 46 47 48 49 50
  GMainLoop* loop;
  GError   * error = NULL;
  GPid       pid = 0;
  gchar    * working_folder;
  gchar    * child_argv[] = {
    "cat",
    "/proc/cpuinfo",
    NULL
  };

  working_folder = g_get_current_dir ();
51
  g_spawn_async_with_pipes (working_folder,
52 53 54 55
		 child_argv, NULL /* envp */,
		 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
		 NULL, NULL,
		 &pid,
56 57 58
		 NULL,
		 NULL,
		 NULL,
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
		 &error);
  g_free (working_folder);

  if (error)
    {
      g_error ("Couldn't execute child: %s", error->message);
      /* doesn't return */
    }

  loop = g_main_loop_new (NULL, FALSE);

  g_child_watch_add (pid,
		     child_watch_cb,
		     loop);

  g_main_loop_run (loop);
  g_main_loop_unref (loop);
  return 0;
77 78
}