On Tue, Jan 26, 2016 at 06:49:55PM +0100, Pino Toscano wrote:
Resolve the paths of the binaries we are looking in the guest to
identify the architecture. This way we can identify also busybox-based
guests such as Alpine Linux, where all the "base" binaries in /bin are
symlinks to busybox.
---
src/inspect-fs-unix.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index f915e86..75c76f8 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -1082,10 +1082,22 @@ check_architecture (guestfs_h *g, struct inspect_fs *fs)
char *arch;
for (i = 0; i < sizeof binaries / sizeof binaries[0]; ++i) {
- if (guestfs_is_file (g, binaries[i]) > 0) {
- /* Ignore errors from file_architecture call. */
+ /* Allow symlinks when checking the binaries:,so in case they are
+ * relative ones (which can be resolved within the same partition),
+ * then we can check the architecture of their target.
+ */
+ if (guestfs_is_file_opts (g, binaries[i],
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ CLEANUP_FREE char *resolved = NULL;
+
+ /* Ignore errors from realpath and file_architecture calls. */
guestfs_push_error_handler (g, NULL, NULL);
- arch = guestfs_file_architecture (g, binaries[i]);
+ resolved = guestfs_realpath (g, binaries[i]);
+ /* If is_file above succeeded realpath should too, but better
+ * be safe than sorry.
+ */
+ if (resolved)
+ arch = guestfs_file_architecture (g, resolved);
guestfs_pop_error_handler (g);
if (arch) {
Thanks - *Pushed*, *but* I changed the patch so that 'char *arch =
NULL', else there's a possibility of accessing an uninitialized
pointer.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/