Skip to content
Snippets Groups Projects
Commit 287cac67 authored by Simon McVittie's avatar Simon McVittie
Browse files

identify-library-abi: Factor out a single run of ldconfig


No functional change intended.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent 8969cc52
No related branches found
No related tags found
1 merge request!586identify-library-api: On Exherbo, run both versions of ldconfig
...@@ -106,86 +106,98 @@ print_library_details (const gchar *library_path, ...@@ -106,86 +106,98 @@ print_library_details (const gchar *library_path,
} }
static gboolean static gboolean
run (int argc, run_ldconfig (char separator,
char **argv, FILE *original_stdout,
GError **error) GError **error)
{ {
g_autoptr(FILE) original_stdout = NULL;
g_autofree gchar *output = NULL;
gint wait_status = 0;
gsize i;
const gchar *ldconfig_argv[] = const gchar *ldconfig_argv[] =
{ {
"/sbin/ldconfig", "-XNv", NULL, "/sbin/ldconfig", "-XNv", NULL,
}; };
char separator = '\n'; g_auto(GStrv) ldconfig_entries = NULL;
g_autofree gchar *library_prefix = NULL;
g_autofree gchar *output = NULL;
gint wait_status = 0;
gsize i;
/* stdout is reserved for machine-readable output, so avoid having if (!g_spawn_sync (NULL, /* working directory */
* things like g_debug() pollute it. */ (gchar **) ldconfig_argv,
original_stdout = _srt_divert_stdout_to_stderr (error); NULL, /* envp */
G_SPAWN_SEARCH_PATH,
NULL, /* child setup */
NULL, /* user data */
&output, /* stdout */
NULL, /* stderr */
&wait_status,
error))
{
return FALSE;
}
if (original_stdout == NULL) if (wait_status != 0)
return FALSE; return glnx_throw (error, "Cannot run ldconfig: wait status %d", wait_status);
if (opt_print0) if (output == NULL)
separator = '\0'; return glnx_throw (error, "ldconfig didn't produce anything in output");
if (opt_ldconfig) ldconfig_entries = g_strsplit (output, "\n", -1);
{
g_auto(GStrv) ldconfig_entries = NULL;
g_autofree gchar *library_prefix = NULL;
if (!g_spawn_sync (NULL, /* working directory */
(gchar **) ldconfig_argv,
NULL, /* envp */
G_SPAWN_SEARCH_PATH,
NULL, /* child setup */
NULL, /* user data */
&output, /* stdout */
NULL, /* stderr */
&wait_status,
error))
{
return FALSE;
}
if (wait_status != 0) if (ldconfig_entries == NULL)
return glnx_throw (error, "Cannot run ldconfig: wait status %d", wait_status); return glnx_throw (error, "ldconfig didn't produce anything in output");
if (output == NULL) for (i = 0; ldconfig_entries[i] != NULL; i++)
return glnx_throw (error, "ldconfig didn't produce anything in output"); {
g_auto(GStrv) line_elements = NULL;
const gchar *library = NULL;
const gchar *colon = NULL;
g_autofree gchar *library_path = NULL;
ldconfig_entries = g_strsplit (output, "\n", -1); /* skip empty lines */
if (ldconfig_entries[i][0] == '\0')
continue;
if (ldconfig_entries == NULL) colon = strchr (ldconfig_entries[i], ':');
return glnx_throw (error, "ldconfig didn't produce anything in output");
for (i = 0; ldconfig_entries[i] != NULL; i++) if (colon != NULL)
{ {
g_auto(GStrv) line_elements = NULL; g_clear_pointer (&library_prefix, g_free);
const gchar *library = NULL; library_prefix = g_strndup (ldconfig_entries[i], colon - ldconfig_entries[i]);
const gchar *colon = NULL; continue;
g_autofree gchar *library_path = NULL; }
/* skip empty lines */ line_elements = g_strsplit (ldconfig_entries[i], " -> ", 2);
if (ldconfig_entries[i][0] == '\0') library = g_strstrip (line_elements[0]);
continue; library_path = g_build_filename (library_prefix, library, NULL);
colon = strchr (ldconfig_entries[i], ':'); print_library_details (library_path, separator, original_stdout);
}
if (colon != NULL) return TRUE;
{ }
g_clear_pointer (&library_prefix, g_free);
library_prefix = g_strndup (ldconfig_entries[i], colon - ldconfig_entries[i]);
continue;
}
line_elements = g_strsplit (ldconfig_entries[i], " -> ", 2); static gboolean
library = g_strstrip (line_elements[0]); run (int argc,
library_path = g_build_filename (library_prefix, library, NULL); char **argv,
GError **error)
{
g_autoptr(FILE) original_stdout = NULL;
gsize i;
char separator = '\n';
print_library_details (library_path, separator, original_stdout); /* stdout is reserved for machine-readable output, so avoid having
} * things like g_debug() pollute it. */
original_stdout = _srt_divert_stdout_to_stderr (error);
if (original_stdout == NULL)
return FALSE;
if (opt_print0)
separator = '\0';
if (opt_ldconfig)
{
if (!run_ldconfig (separator, original_stdout, error))
return FALSE;
} }
else if (opt_directory != NULL) else if (opt_directory != NULL)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment