Discussion:
[libvirt] [sandbox PATCH 1/2] builder: Use prefix '=> /' to identify lib path
Radostin Stoyanov
2018-11-20 19:10:19 UTC
Permalink
The output of ldd might contain a fully qualified path on the left
hand side of the '=>'. For example:

(glibc 2.28)
$ ldd /usr/libexec/libvirt-sandbox-init-common | grep ld
/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007fcdceb96000)

(glibc 2.27)
$ ldd /usr/libexec/libvirt-sandbox-init-common | grep ld
/lib64/ld-linux-x86-64.so.2 (0x00007f18135eb000)

Signed-off-by: Radostin Stoyanov <***@gmail.com>
---
libvirt-sandbox/libvirt-sandbox-builder.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-builder.c b/libvirt-sandbox/libvirt-sandbox-builder.c
index 8cfc2f4..7058112 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder.c
@@ -297,7 +297,7 @@ static gboolean gvir_sandbox_builder_copy_program(const char *program,
/* Loop over the output lines to get the path to the libraries to copy */
line = out;
while ((tmp = strchr(line, '\n'))) {
- gchar *start, *end;
+ gchar *start, *end, *tmp2;
*tmp = '\0';

/* Search the line for the library path */
@@ -308,22 +308,20 @@ static gboolean gvir_sandbox_builder_copy_program(const char *program,
const gchar *newname = NULL;
*end = '\0';

+ if ((tmp2 = strstr(start, "=> ")))
+ start = tmp2 + 3;
+
/* There are countless different naming schemes for
* the ld-linux.so library across architectures. Pretty
* much the only thing in common is they start with
- * the two letters 'ld'. The LDD program prints it
- * out differently too - it doesn't include " => "
- * as this library is special - its actually a static
- * linked executable not a library.
+ * the two letters 'ld'.
*
* To make life easier for libvirt-sandbox-init-{qemu,lxc}
* we just call the file 'ld.so' when we copy it into our
* scratch dir, no matter what it was called on the host.
*/
- if (!strstr(line, " => ") &&
- strstr(start, "/ld")) {
+ if (strstr(start, "/ld"))
newname = "ld.so";
- }

if (!gvir_sandbox_builder_copy_file(start, dest, newname, error))
goto cleanup;
--
2.17.1
Radostin Stoyanov
2018-11-20 19:10:20 UTC
Permalink
On some linux distributions "/boot/vmlinuz-linux" is set as default
kernel path. If this file does not exist we fallback to the value
"/boot/vmlinuz-$KERNEL-VERSION"

Signed-off-by: Radostin Stoyanov <***@gmail.com>
---
bin/virt-sandbox.c | 5 +++--
libvirt-sandbox/libvirt-sandbox-builder-machine.c | 4 ++++
2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/bin/virt-sandbox.c b/bin/virt-sandbox.c
index 6032562..930b85e 100644
--- a/bin/virt-sandbox.c
+++ b/bin/virt-sandbox.c
@@ -553,8 +553,9 @@ omitted, defaults to match the current running host version.

=item B<--kernpath=FILE-PATH>

-Specify the path to the kernel binary. If omitted, defaults
-to C</boot/vmlinuz-$KERNEL-VERSION>.
+Specify the path to the kernel binary. If omitted, defaults to
+C</boot/vmlinuz-linux> if exists, otherwise
+C</boot/vmlinuz-$KERNEL-VERSION> will be used.

=item B<--kmodpath=DIR-PATH>

diff --git a/libvirt-sandbox/libvirt-sandbox-builder-machine.c b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
index a4a5dcd..2c305a7 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder-machine.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
@@ -133,11 +133,15 @@ static gchar *gvir_sandbox_builder_machine_get_kernrelease(GVirSandboxConfig *co
static gchar *gvir_sandbox_builder_machine_get_kernpath(GVirSandboxConfig *config)
{
const gchar *kernpath = gvir_sandbox_config_get_kernpath(config);
+ const gchar *default_kernpath = "/boot/vmlinuz-linux";
gchar *kver;
gchar *ret;
if (kernpath)
return g_strdup(kernpath);

+ if (access(default_kernpath, F_OK ) != -1)
+ return g_strdup(default_kernpath);
+
kver = gvir_sandbox_builder_machine_get_kernrelease(config);
ret = g_strdup_printf("/boot/vmlinuz-%s", kver);
g_free(kver);
--
2.17.1
Daniel P. Berrangé
2018-11-21 09:27:42 UTC
Permalink
Post by Radostin Stoyanov
On some linux distributions "/boot/vmlinuz-linux" is set as default
kernel path. If this file does not exist we fallback to the value
"/boot/vmlinuz-$KERNEL-VERSION"
---
bin/virt-sandbox.c | 5 +++--
libvirt-sandbox/libvirt-sandbox-builder-machine.c | 4 ++++
2 files changed, 7 insertions(+), 2 deletions(-)
Reviewed-by: Daniel P. Berrangé <***@redhat.com>


Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Daniel P. Berrangé
2018-11-21 09:25:36 UTC
Permalink
Post by Radostin Stoyanov
The output of ldd might contain a fully qualified path on the left
(glibc 2.28)
$ ldd /usr/libexec/libvirt-sandbox-init-common | grep ld
/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007fcdceb96000)
(glibc 2.27)
$ ldd /usr/libexec/libvirt-sandbox-init-common | grep ld
/lib64/ld-linux-x86-64.so.2 (0x00007f18135eb000)
---
libvirt-sandbox/libvirt-sandbox-builder.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/libvirt-sandbox/libvirt-sandbox-builder.c b/libvirt-sandbox/libvirt-sandbox-builder.c
index 8cfc2f4..7058112 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder.c
@@ -297,7 +297,7 @@ static gboolean gvir_sandbox_builder_copy_program(const char *program,
/* Loop over the output lines to get the path to the libraries to copy */
line = out;
while ((tmp = strchr(line, '\n'))) {
- gchar *start, *end;
+ gchar *start, *end, *tmp2;
*tmp = '\0';
/* Search the line for the library path */
@@ -308,22 +308,20 @@ static gboolean gvir_sandbox_builder_copy_program(const char *program,
const gchar *newname = NULL;
*end = '\0';
+ if ((tmp2 = strstr(start, "=> ")))
+ start = tmp2 + 3;
+
/* There are countless different naming schemes for
* the ld-linux.so library across architectures. Pretty
* much the only thing in common is they start with
- * the two letters 'ld'. The LDD program prints it
- * out differently too - it doesn't include " => "
- * as this library is special - its actually a static
- * linked executable not a library.
+ * the two letters 'ld'.
*
* To make life easier for libvirt-sandbox-init-{qemu,lxc}
* we just call the file 'ld.so' when we copy it into our
* scratch dir, no matter what it was called on the host.
*/
- if (!strstr(line, " => ") &&
- strstr(start, "/ld")) {
+ if (strstr(start, "/ld"))
newname = "ld.so";
- }
if (!gvir_sandbox_builder_copy_file(start, dest, newname, error))
goto cleanup;
Reviewed-by: Daniel P. Berrangé <***@redhat.com>


Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Loading...