[anjuta] libanjuta: use g_spawn_sync instead of fork() and waitpid()



commit 674bf6d2ca065701801eac7e6c941ec9cc678321
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date:   Sat Nov 17 10:19:40 2012 +0100

    libanjuta: use g_spawn_sync instead of fork() and waitpid()
    
    ...in anjuta_util_package_is_installed()
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688545

 libanjuta/anjuta-utils.c |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/libanjuta/anjuta-utils.c b/libanjuta/anjuta-utils.c
index 2967ca8..12bc92b 100644
--- a/libanjuta/anjuta-utils.c
+++ b/libanjuta/anjuta-utils.c
@@ -561,18 +561,25 @@ anjuta_util_install_files (const gchar * const names)
 gboolean
 anjuta_util_package_is_installed (const gchar * package, gboolean show)
 {
-	gboolean installed = FALSE;
-	int status;
+	const gchar* const argv[] = { "pkg-config", "--exists", package, NULL };
 	int exit_status;
-	pid_t pid;
+	GError *err = NULL;
+
+	if (!g_spawn_sync (NULL, (gchar**)argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
+	                   NULL, NULL, NULL, &exit_status, &err))
+	{
+		if (show)
+		{
+			anjuta_util_dialog_error (NULL,
+			                          _("Failed to run \"%s\". "
+			                            "The returned error was: \"%s\"."),
+									  "pkg-config --exists", err->message);
+		}
+		g_error_free (err);
+	}
 
-	if ((pid = fork()) == 0)
-		execlp ("pkg-config", "pkg-config", "--exists", package, NULL);
 
-	waitpid (pid, &status, 0);
-	exit_status = WEXITSTATUS (status);
-	installed = (exit_status == 0) ? TRUE : FALSE;
-	if (installed)
+	if (WIFEXITED (exit_status) && WEXITSTATUS (exit_status) == 0)
 		return TRUE;
 
 	if (show)



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