static gboolean pk_backend_spawn_helper_va_list (PkBackendSpawn *backend_spawn, PkBackendJob *job, const gchar *executable, va_list *args) { gboolean background; PkBackendSpawnPrivate *priv = backend_spawn->priv; PkSpawnArgvFlags flags = PK_SPAWN_ARGV_FLAGS_NONE; #if PK_BUILD_LOCAL const gchar *directory; #endif g_autoptr(GError) error = NULL; g_autofree gchar *filename = NULL; g_auto(GStrv) argv = NULL; g_auto(GStrv) envp = NULL; g_return_val_if_fail (PK_IS_BACKEND_SPAWN (backend_spawn), FALSE); /* convert to a argv */ argv = pk_backend_spawn_va_list_to_argv (executable, args); if (argv == NULL) { g_warning ("argv NULL"); return FALSE; } #if PK_BUILD_LOCAL /* prefer the local version */ directory = priv->name; if (g_str_has_prefix (directory, "test_")) directory = "test"; filename = g_build_filename ("..", "backends", directory, "helpers", argv[PK_BACKEND_SPAWN_ARGV0], NULL); if (g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE) { g_debug ("local helper not found '%s'", filename); g_free (filename); filename = g_build_filename ("..", "backends", directory, argv[PK_BACKEND_SPAWN_ARGV0], NULL); } if (g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE) { g_debug ("local helper not found '%s'", filename); g_free (filename); filename = g_build_filename (DATADIR, "PackageKit", "helpers", priv->name, argv[PK_BACKEND_SPAWN_ARGV0], NULL); } #else filename = g_build_filename (DATADIR, "PackageKit", "helpers", priv->name, argv[PK_BACKEND_SPAWN_ARGV0], NULL); #endif g_debug ("using spawn filename %s", filename); /* replace the filename with the full path */ g_free (argv[PK_BACKEND_SPAWN_ARGV0]); argv[PK_BACKEND_SPAWN_ARGV0] = g_strdup (filename); /* copy idle setting from backend to PkSpawn instance */ background = pk_backend_job_get_background (job); g_object_set (priv->spawn, "background", (background == TRUE), NULL); #ifdef ENABLE_STRACE /* we can't reuse when using strace */ flags |= PK_SPAWN_ARGV_FLAGS_NEVER_REUSE; #endif priv->finished = FALSE; envp = pk_backend_spawn_get_envp (backend_spawn); if (!pk_spawn_argv (priv->spawn, argv, envp, flags, &error)) { pk_backend_job_error_code (priv->job, PK_ERROR_ENUM_INTERNAL_ERROR, "Spawn of helper '%s' failed: %s", argv[PK_BACKEND_SPAWN_ARGV0], error->message); pk_backend_job_finished (priv->job); return FALSE; } return TRUE; }
/** * pk_backend_spawn_helper_va_list: **/ static gboolean pk_backend_spawn_helper_va_list (PkBackendSpawn *backend_spawn, PkBackendJob *job, const gchar *executable, va_list *args) { gboolean ret; gchar *filename; gchar **argv; gchar **envp; PkHintEnum background; GError *error = NULL; PkBackendSpawnPrivate *priv = backend_spawn->priv; #if PK_BUILD_LOCAL const gchar *directory; #endif g_return_val_if_fail (PK_IS_BACKEND_SPAWN (backend_spawn), FALSE); /* convert to a argv */ argv = pk_backend_spawn_va_list_to_argv (executable, args); if (argv == NULL) { g_warning ("argv NULL"); return FALSE; } #if PK_BUILD_LOCAL /* prefer the local version */ directory = priv->name; if (g_str_has_prefix (directory, "test_")) directory = "test"; filename = g_build_filename ("..", "backends", directory, "helpers", argv[0], NULL); if (g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE) { g_debug ("local helper not found '%s'", filename); g_free (filename); filename = g_build_filename ("..", "backends", directory, argv[0], NULL); } if (g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE) { g_debug ("local helper not found '%s'", filename); g_free (filename); filename = g_build_filename (DATADIR, "PackageKit", "helpers", priv->name, argv[0], NULL); } #else filename = g_build_filename (DATADIR, "PackageKit", "helpers", priv->name, argv[0], NULL); #endif g_debug ("using spawn filename %s", filename); /* replace the filename with the full path */ g_free (argv[0]); argv[0] = g_strdup (filename); /* copy idle setting from backend to PkSpawn instance */ background = pk_backend_job_get_background (job); g_object_set (priv->spawn, "background", (background == PK_HINT_ENUM_TRUE), NULL); priv->finished = FALSE; envp = pk_backend_spawn_get_envp (backend_spawn); ret = pk_spawn_argv (priv->spawn, argv, envp, &error); if (!ret) { pk_backend_job_error_code (priv->job, PK_ERROR_ENUM_INTERNAL_ERROR, "Spawn of helper '%s' failed", argv[0], error->message); g_error_free (error); pk_backend_job_finished (priv->job); } g_free (filename); g_strfreev (argv); g_strfreev (envp); return ret; }