Richard W.M. Jones
2016-Jan-26 15:54 UTC
[Libguestfs] [PATCH] inspect: Get architecture of Alpine Linux from /bin/busybox.
All the files in /bin are links to busybox. guestfs_file_architecture doesn't follow symlinks so it fails. Therefore check /bin/busybox (not a symlink) to find the architecture. --- src/inspect-fs-unix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c index f915e86..6aaf5a1 100644 --- a/src/inspect-fs-unix.c +++ b/src/inspect-fs-unix.c @@ -1077,7 +1077,8 @@ static void check_architecture (guestfs_h *g, struct inspect_fs *fs) { const char *binaries[] - { "/bin/bash", "/bin/ls", "/bin/echo", "/bin/rm", "/bin/sh" }; + { "/bin/bash", "/bin/ls", "/bin/echo", "/bin/rm", "/bin/sh", + "/bin/busybox" }; size_t i; char *arch; -- 2.5.0
Pino Toscano
2016-Jan-26 17:45 UTC
Re: [Libguestfs] [PATCH] inspect: Get architecture of Alpine Linux from /bin/busybox.
On Tuesday 26 January 2016 15:54:46 Richard W.M. Jones wrote:> All the files in /bin are links to busybox. guestfs_file_architecture > doesn't follow symlinks so it fails. Therefore check /bin/busybox > (not a symlink) to find the architecture. > ---While this patch looks okay in principle, I think it would be better to just resolve the paths we are looking for: that is, do symlink resolution in is_file, and use realpath to get the actual path before passing it to file_architecture. If the file can be stat()ed, then it is a relative symlink whose target we can read. Patch coming in a minute. -- Pino Toscano
Pino Toscano
2016-Jan-26 17:49 UTC
[Libguestfs] [PATCH] inspect: resolve symlinks when detecting architecture
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) { -- 2.5.0
Reasonably Related Threads
- [PATCH] inspect: resolve symlinks when detecting architecture
- Re: [PATCH] inspect: Get architecture of Alpine Linux from /bin/busybox.
- busybox for centos
- CEBA-2011:0815 CentOS 5 x86_64 busybox FASTTRACK Update
- CEBA-2011:0815 CentOS 5 i386 busybox FASTTRACK Update