diff options
author | Colin Walters <walters@verbum.org> | 2012-05-23 16:13:45 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2012-07-25 16:58:56 -0400 |
commit | 301c072e1bf2c16713ee501f75a75be3db392003 (patch) | |
tree | ac07a5e5fdbab96b68cc439276a05f01ad97a60d | |
parent | 090cf3cee2e4f29293529f8f9c48c14053a405ec (diff) | |
download | glib-wip/gsubprocess-ostreams.tar.gz |
glib-compile-resources: Port to GSubprocesswip/gsubprocess-ostreams
https://bugzilla.gnome.org/show_bug.cgi?id=672102
-rw-r--r-- | gio/glib-compile-resources.c | 98 |
1 files changed, 46 insertions, 52 deletions
diff --git a/gio/glib-compile-resources.c b/gio/glib-compile-resources.c index fbe2c73c1..8225a9db5 100644 --- a/gio/glib-compile-resources.c +++ b/gio/glib-compile-resources.c @@ -269,7 +269,6 @@ end_element (GMarkupParseContext *context, if (state->preproc_options) { gchar **options; - gchar *stderr_child = NULL; guint i; gboolean xml_stripblanks = FALSE; gboolean to_pixdata = FALSE; @@ -294,8 +293,9 @@ end_element (GMarkupParseContext *context, if (xml_stripblanks && xmllint != NULL) { - gchar *argv[8]; - int status, fd, argc; + int fd; + GSubprocess *proc; + GPtrArray *args; tmp_file = g_strdup ("resource-XXXXXXXX"); if ((fd = g_mkstemp (tmp_file)) == -1) @@ -311,42 +311,38 @@ end_element (GMarkupParseContext *context, } close (fd); - argc = 0; - argv[argc++] = (gchar *) xmllint; - argv[argc++] = "--nonet"; - argv[argc++] = "--noblanks"; - argv[argc++] = "--output"; - argv[argc++] = tmp_file; - argv[argc++] = real_file; - argv[argc++] = NULL; - g_assert (argc <= G_N_ELEMENTS (argv)); - - if (!g_spawn_sync (NULL /* cwd */, argv, NULL /* envv */, - G_SPAWN_STDOUT_TO_DEV_NULL, - NULL, NULL, NULL, &stderr_child, &status, &my_error)) - { - g_propagate_error (error, my_error); - goto cleanup; - } - - /* Ugly...we shoud probably just let stderr be inherited */ - if (!g_spawn_check_exit_status (status, NULL)) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - _("Error processing input file with xmllint:\n%s"), stderr_child); + args = g_ptr_array_new (); + g_ptr_array_addv (args, xmllint, "--nonet", "--noblanks", "--output", + tmp_file, real_file, NULL); + g_ptr_array_add (args, NULL); + proc = g_subprocess_new ((gchar**)args->pdata, NULL, NULL, 0, NULL, NULL, + g_subprocess_stream_devnull (), + g_subprocess_stream_inherit (), + g_subprocess_stream_inherit (), + error); + g_ptr_array_free (args, TRUE); + g_free (real_file); + real_file = NULL; + + if (!proc) + goto cleanup; + + if (!g_subprocess_wait_sync_check (proc, NULL, error)) + { + g_object_unref (proc); goto cleanup; } - g_free (stderr_child); - g_free (real_file); + g_object_unref (proc); + real_file = g_strdup (tmp_file); } if (to_pixdata) { - gchar *argv[4]; - gchar *stderr_child = NULL; - int status, fd, argc; + int fd; + GSubprocess *proc; + GPtrArray *args; if (gdk_pixbuf_pixdata == NULL) { @@ -370,30 +366,28 @@ end_element (GMarkupParseContext *context, } close (fd); - argc = 0; - argv[argc++] = (gchar *) gdk_pixbuf_pixdata; - argv[argc++] = real_file; - argv[argc++] = tmp_file2; - argv[argc++] = NULL; - g_assert (argc <= G_N_ELEMENTS (argv)); + args = g_ptr_array_new (); + g_ptr_array_addv (args, gdk_pixbuf_pixdata, real_file, tmp_file2, NULL); + g_ptr_array_add (args, NULL); + proc = g_subprocess_new ((gchar**)args->pdata, NULL, NULL, 0, NULL, NULL, + g_subprocess_stream_devnull (), + g_subprocess_stream_inherit (), + g_subprocess_stream_inherit (), + error); + g_ptr_array_free (args, TRUE); + g_free (real_file); - if (!g_spawn_sync (NULL /* cwd */, argv, NULL /* envv */, - G_SPAWN_STDOUT_TO_DEV_NULL, - NULL, NULL, NULL, &stderr_child, &status, &my_error)) - { - g_propagate_error (error, my_error); - goto cleanup; - } - - if (!g_spawn_check_exit_status (status, NULL)) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - _("Error processing input file with to-pixdata:\n%s"), stderr_child); + if (!proc) + goto cleanup; + + if (!g_subprocess_wait_sync_check (proc, NULL, error)) + { + g_object_unref (proc); goto cleanup; - } + } + + g_object_unref (proc); - g_free (stderr_child); - g_free (real_file); real_file = g_strdup (tmp_file2); } } |