[glib/wip/gsubprocess: 4/6] glib-compile-resources: Port to GSubprocess



commit c39b089b937bf7ed5d27e3e43928b698591a5f97
Author: Colin Walters <walters verbum org>
Date:   Wed May 23 16:13:45 2012 -0400

    glib-compile-resources: Port to GSubprocess
    
    https://bugzilla.gnome.org/show_bug.cgi?id=672102

 gio/glib-compile-resources.c |   69 ++++++++++++-----------------------------
 1 files changed, 20 insertions(+), 49 deletions(-)
---
diff --git a/gio/glib-compile-resources.c b/gio/glib-compile-resources.c
index 31e5624..51e32b9 100644
--- a/gio/glib-compile-resources.c
+++ b/gio/glib-compile-resources.c
@@ -296,8 +296,8 @@ end_element (GMarkupParseContext  *context,
 
           if (xml_stripblanks && xmllint != NULL)
             {
-              gchar *argv[8];
-              int status, fd, argc;
+              int fd;
+	      GSubprocess *proc;
 
               tmp_file = g_strdup ("resource-XXXXXXXX");
               if ((fd = g_mkstemp (tmp_file)) == -1)
@@ -313,32 +313,16 @@ 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 |
-                                 G_SPAWN_STDERR_TO_DEV_NULL,
-                                 NULL, NULL, NULL, NULL, &status, &my_error))
-                {
+	      proc = g_subprocess_new_with_args (xmllint, "--nonet", "--noblanks", "--output",
+						 tmp_file, real_file, NULL);
+	      g_subprocess_set_standard_output_to_devnull (proc, TRUE);
+	      g_subprocess_set_standard_error_to_devnull (proc, TRUE);
+
+	      if (!g_subprocess_run_sync (proc, NULL, &my_error))
+		{
                   g_propagate_error (error, my_error);
                   goto cleanup;
-                }
-#ifdef HAVE_SYS_WAIT_H
-              if (!WIFEXITED (status) || WEXITSTATUS (status) != 0)
-                {
-                  g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                                      _("Error processing input file with xmllint"));
-                  goto cleanup;
-                }
-#endif
+		}
 
               g_free (real_file);
               real_file = g_strdup (tmp_file);
@@ -346,8 +330,8 @@ end_element (GMarkupParseContext  *context,
 
           if (to_pixdata)
             {
-              gchar *argv[4];
-              int status, fd, argc;
+              int fd;
+	      GSubprocess *proc;
 
               if (gdk_pixbuf_pixdata == NULL)
                 {
@@ -371,29 +355,16 @@ 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));
-
-              if (!g_spawn_sync (NULL /* cwd */, argv, NULL /* envv */,
-                                 G_SPAWN_STDOUT_TO_DEV_NULL |
-                                 G_SPAWN_STDERR_TO_DEV_NULL,
-                                 NULL, NULL, NULL, NULL, &status, &my_error))
-                {
+	      proc = g_subprocess_new_with_args (gdk_pixbuf_pixdata,
+						 real_file, tmp_file2, NULL);
+	      g_subprocess_set_standard_output_to_devnull (proc, TRUE);
+	      g_subprocess_set_standard_error_to_devnull (proc, TRUE);
+
+	      if (!g_subprocess_run_sync (proc, NULL, &my_error))
+		{
                   g_propagate_error (error, my_error);
                   goto cleanup;
-                }
-#ifdef HAVE_SYS_WAIT_H
-              if (!WIFEXITED (status) || WEXITSTATUS (status) != 0)
-                {
-                  g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-				       _("Error processing input file with to-pixdata"));
-                  goto cleanup;
-                }
-#endif
+		}
 
               g_free (real_file);
               real_file = g_strdup (tmp_file2);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]