};
static char *debug_help (const char *subcmd, int argc, char *const *const argv);
+static char *debug_binaries (const char *subcmd, int argc, char *const *const argv);
static char *debug_core_pattern (const char *subcmd, int argc, char *const *const argv);
static char *debug_env (const char *subcmd, int argc, char *const *const argv);
static char *debug_fds (const char *subcmd, int argc, char *const *const argv);
+static char *debug_ldd (const char *subcmd, int argc, char *const *const argv);
static char *debug_ls (const char *subcmd, int argc, char *const *const argv);
static char *debug_ll (const char *subcmd, int argc, char *const *const argv);
static char *debug_progress (const char *subcmd, int argc, char *const *const argv);
static struct cmd cmds[] = {
{ "help", debug_help },
+ { "binaries", debug_binaries },
{ "core_pattern", debug_core_pattern },
{ "env", debug_env },
{ "fds", debug_fds },
+ { "ldd", debug_ldd },
{ "ls", debug_ls },
{ "ll", debug_ll },
{ "progress", debug_progress },
return out;
}
+/* Return binaries in the appliance. See regressions/rhbz727178.sh */
+static char *
+debug_binaries (const char *subcmd, int argc, char *const *const argv)
+{
+ int r;
+ char *out, *err;
+
+ const char cmd[] =
+ "find / -xdev -type f -executable "
+ "| xargs file -i "
+ "| grep application/x-executable "
+ "| gawk -F: '{print $1}'";
+
+ r = command (&out, &err, "sh", "-c", cmd, NULL);
+ if (r == -1) {
+ reply_with_error ("find: %s", err);
+ free (out);
+ free (err);
+ return NULL;
+ }
+
+ free (err);
+
+ return out;
+}
+
+/* Run 'ldd' on a file from the appliance. See regressions/rhbz727178.sh */
+static char *
+debug_ldd (const char *subcmd, int argc, char *const *const argv)
+{
+ int r;
+ char *out, *err, *ret;
+
+ if (argc != 1) {
+ reply_with_error ("ldd: no file argument");
+ return NULL;
+ }
+
+ /* Note that 'ldd' doesn't fail if it finds errors. We have to grep
+ * for errors in the regression test instead. 'ldd' only fails here
+ * if the binary is not a binary at all (eg. for shell scripts).
+ * Also 'ldd' randomly sends messages to stderr and errors to stdout
+ * depending on the phase of the moon.
+ */
+ r = command (&out, &err, "ldd", "-r", argv[0], NULL);
+ if (r == -1) {
+ reply_with_error ("ldd: %s: %s", argv[0], err);
+ free (out);
+ free (err);
+ return NULL;
+ }
+
+ /* Concatenate stdout and stderr in the result. */
+ ret = realloc (out, strlen (out) + strlen (err) + 1);
+ if (ret == NULL) {
+ reply_with_perror ("realloc");
+ free (out);
+ free (err);
+ return NULL;
+ }
+
+ strcat (ret, err);
+ free (err);
+
+ return ret;
+}
+
/* List files in the appliance. */
static char *
debug_ls (const char *subcmd, int argc, char *const *const argv)
--- /dev/null
+#!/bin/bash -
+# libguestfs
+# Copyright (C) 2011 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+# https://bugzilla.redhat.com/show_bug.cgi?id=727178
+# Check that all binaries that we ship in the appliance contain
+# corresponding libraries.
+
+set -e
+export LANG=C
+
+guestfish=../fish/guestfish
+output=rhbz727178.output
+
+rm -f binaries.tmp $output
+
+eval `$guestfish -a /dev/null --listen`
+
+$guestfish --remote -- run
+$guestfish --remote -- debug binaries "" |
+ grep -E '^/(bin|sbin|usr/bin|usr/sbin|usr/libexec)/' > binaries.tmp
+
+while read ex; do
+ echo ldd $ex
+ $guestfish --remote -- -debug ldd $ex
+done < binaries.tmp > $output
+
+if grep -E '\bnot found\b|undefined symbol' $output; then
+ echo "Error: some libraries are missing from the appliance."
+ echo "See" $(pwd)/$output
+ echo "for the complete output."
+ exit 1
+fi
+
+rm binaries.tmp $output