[gnome-color-manager] Do not use g_spawn_command_line_sync() when spawning executables



commit a8ee35723d20f966981b07454968109f1dd8455b
Author: Richard Hughes <richard hughsie com>
Date:   Tue Jul 30 10:07:12 2013 +0100

    Do not use g_spawn_command_line_sync() when spawning executables
    
    Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=958093

 src/gcm-calibrate-argyll.c |   29 +++++++++++++++++++++--------
 src/gcm-calibrate-main.c   |   29 ++++++++++++++++++++++-------
 src/gcm-exif.c             |   16 ++++++++++++----
 3 files changed, 55 insertions(+), 19 deletions(-)
---
diff --git a/src/gcm-calibrate-argyll.c b/src/gcm-calibrate-argyll.c
index 2bb402c..52a4b64 100644
--- a/src/gcm-calibrate-argyll.c
+++ b/src/gcm-calibrate-argyll.c
@@ -166,6 +166,7 @@ gcm_calibrate_argyll_get_display (const gchar *output_name,
        gint exit_status;
        guint display = G_MAXUINT;
        guint i;
+       const gchar *argv[] = { "dispcal", NULL };
 
        /* get correct name of the command */
        command = gcm_calibrate_argyll_get_tool_filename ("dispcal", error);
@@ -173,11 +174,16 @@ gcm_calibrate_argyll_get_display (const gchar *output_name,
                goto out;
 
        /* execute it and capture stderr */
-       ret = g_spawn_command_line_sync (command,
-                                        NULL,
-                                        &data,
-                                        &exit_status,
-                                        error);
+       argv[0] = command;
+       ret = g_spawn_sync (NULL,
+                           (gchar **) argv,
+                           NULL,
+                           G_SPAWN_STDERR_TO_DEV_NULL,
+                           NULL, NULL,
+                           &data,
+                           NULL,
+                           &exit_status,
+                           error);
        if (!ret)
                goto out;
 
@@ -1736,6 +1742,7 @@ gcm_calibrate_argyll_printer (GcmCalibrate *calibrate,
 
        /* page setup, and then we're done */
        if (print_kind == GCM_CALIBRATE_PRINT_KIND_GENERATE) {
+               const gchar *argv[] = { BINDIR "/nautilus", "", NULL };
 
                /* get the paper size */
                paper_size = gcm_calibrate_argyll_get_paper_size (calibrate, window);
@@ -1756,9 +1763,15 @@ gcm_calibrate_argyll_printer (GcmCalibrate *calibrate,
                if (!ret)
                        goto out;
 
-               cmdline = g_strdup_printf ("nautilus \"%s\"", working_path);
-               g_debug ("we need to open the directory we're using: %s", cmdline);
-               ret = g_spawn_command_line_async (cmdline, error);
+               g_debug ("we need to open the directory we're using: %s", working_path);
+               argv[1] = working_path;
+               ret = g_spawn_async (NULL,
+                                    (gchar **) argv,
+                                    NULL,
+                                    0,
+                                    NULL, NULL,
+                                    NULL,
+                                    error);
                goto out;
        }
 
diff --git a/src/gcm-calibrate-main.c b/src/gcm-calibrate-main.c
index 1043327..56bd884 100644
--- a/src/gcm-calibrate-main.c
+++ b/src/gcm-calibrate-main.c
@@ -655,7 +655,16 @@ gcm_calib_label_activate_link_cb (GtkLabel *label,
 {
        gboolean ret;
        GError *error = NULL;
-       ret = g_spawn_command_line_async (BINDIR "/gnome-control-center color", &error);
+       const gchar *argv[] = { BINDIR "/gnome-control-center color",
+                               "color",
+                               NULL };
+       ret = g_spawn_async (NULL,
+                            (gchar **) argv,
+                            NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error);
        if (!ret) {
                g_warning ("failed to launch the control center: %s",
                           error->message);
@@ -800,22 +809,28 @@ static void
 gcm_calib_show_profile_button_clicked_cb (GtkButton *button,
                                          GcmCalibratePriv *priv)
 {
+       const gchar *argv[] = { BINDIR "/nautilus", "", NULL };
        gboolean ret;
-       gchar *command_line;
+       gchar *path;
        GError *error = NULL;
 
        /* just hardcode nautilus to open the folder */
-       command_line = g_strdup_printf ("nautilus %s/%s",
-                                       g_get_user_data_dir (),
-                                       "icc");
-       ret = g_spawn_command_line_async (command_line, &error);
+       path = g_build_filename (g_get_user_data_dir (), "icc", NULL);
+       argv[1] = path;
+       ret = g_spawn_async (NULL,
+                            (gchar **) argv,
+                            NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error);
        if (!ret) {
                g_warning ("failed to show profile: %s", error->message);
                g_error_free (error);
                goto out;
        }
 out:
-       g_free (command_line);
+       g_free (path);
 }
 
 /**
diff --git a/src/gcm-exif.c b/src/gcm-exif.c
index ce268fe..1fd152e 100644
--- a/src/gcm-exif.c
+++ b/src/gcm-exif.c
@@ -198,14 +198,23 @@ static gboolean
 gcm_exif_parse_exiv (GcmExif *exif, const gchar *filename, GError **error)
 {
        gboolean ret;
-       gchar *command_line;
        gint exit_status = 0;
        gchar *standard_output = NULL;
        gchar **split = NULL;
        GcmExifPrivate *priv = exif->priv;
-
-       command_line = g_strdup_printf (LIBEXECDIR "/gcm-helper-exiv \"%s\"", filename);
-       ret = g_spawn_command_line_sync (command_line, &standard_output, NULL, &exit_status, error);
+       const gchar *argv[] = { LIBEXECDIR "/gcm-helper-exiv",
+                         filename,
+                         NULL };
+
+       ret = g_spawn_sync (NULL,
+                           (gchar **) argv,
+                           NULL,
+                           G_SPAWN_STDERR_TO_DEV_NULL,
+                           NULL, NULL,
+                           &standard_output,
+                           NULL,
+                           &exit_status,
+                           error);
        if (!ret)
                goto out;
 
@@ -248,7 +257,6 @@ gcm_exif_parse_exiv (GcmExif *exif, const gchar *filename, GError **error)
 
 out:
        g_free (standard_output);
-       g_free (command_line);
        g_strfreev (split);
        return ret;
 }


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