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,
}
static gboolean
run (int argc,
char **argv,
GError **error)
run_ldconfig (char separator,
FILE *original_stdout,
GError **error)
{
g_autoptr(FILE) original_stdout = NULL;
g_autofree gchar *output = NULL;
gint wait_status = 0;
gsize i;
const gchar *ldconfig_argv[] =
{
"/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
* things like g_debug() pollute it. */
original_stdout = _srt_divert_stdout_to_stderr (error);
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 (original_stdout == NULL)
return FALSE;
if (wait_status != 0)
return glnx_throw (error, "Cannot run ldconfig: wait status %d", wait_status);
if (opt_print0)
separator = '\0';
if (output == NULL)
return glnx_throw (error, "ldconfig didn't produce anything in output");
if (opt_ldconfig)
{
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;
}
ldconfig_entries = g_strsplit (output, "\n", -1);
if (wait_status != 0)
return glnx_throw (error, "Cannot run ldconfig: wait status %d", wait_status);
if (ldconfig_entries == NULL)
return glnx_throw (error, "ldconfig didn't produce anything in output");
if (output == NULL)
return glnx_throw (error, "ldconfig didn't produce anything in output");
for (i = 0; ldconfig_entries[i] != NULL; i++)
{
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)
return glnx_throw (error, "ldconfig didn't produce anything in output");
colon = strchr (ldconfig_entries[i], ':');
for (i = 0; ldconfig_entries[i] != NULL; i++)
if (colon != NULL)
{
g_auto(GStrv) line_elements = NULL;
const gchar *library = NULL;
const gchar *colon = NULL;
g_autofree gchar *library_path = NULL;
g_clear_pointer (&library_prefix, g_free);
library_prefix = g_strndup (ldconfig_entries[i], colon - ldconfig_entries[i]);
continue;
}
/* skip empty lines */
if (ldconfig_entries[i][0] == '\0')
continue;
line_elements = g_strsplit (ldconfig_entries[i], " -> ", 2);
library = g_strstrip (line_elements[0]);
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)
{
g_clear_pointer (&library_prefix, g_free);
library_prefix = g_strndup (ldconfig_entries[i], colon - ldconfig_entries[i]);
continue;
}
return TRUE;
}
line_elements = g_strsplit (ldconfig_entries[i], " -> ", 2);
library = g_strstrip (line_elements[0]);
library_path = g_build_filename (library_prefix, library, NULL);
static gboolean
run (int argc,
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)
{
......
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