in reply to Re^3: Capture::Tiny getting stuck on ldd /proc/self/fd/1
in thread Capture::Tiny getting stuck on ldd /proc/self/fd/1

I'll try to explain what I'm trying to achieve. I have a file of paths that define my tool (all the needed paths to run my tool). I want to create a Dockerfile/Podman-file/Sing-file based on those dependencies so the container will be able to run the tool inside it. I want to find all the RPM packages of those paths. For that I use:
rpm -qf --queryformat "[%{NAME}]" [path]
But this command does not give me all the packages I need. I noticed that if I use ldd [path] to get all shared libs and then for each lib, run the above RPM command, then I'll get all the needed packages.

So the my algorithm fow now is:
1. Run the above RPM command on the path and find related packages.
2. Run the ldd command on the path to find the shared libs.
3. For each shared lib path, repeat step 1 and step 2 (because shared lib can also have shared libs).
4. Keep track of all the paths that were already and stop once it's empty.

The algorithm works pretty well (until I came across with this special file). That way I will find all the related RPM packages. Now the problems:
1. I want to run step 2 only on dynamic files only (to prevent running ldd on all of the paths and it also solves /proc/self/fd/1).
2. I'm familiar with the file command. The problem with that command is that it's output is a syntax-based. Which means that I will have something like if ($output =~ /dynamically linked/) # do stuff and if some output prints "not dynamically linked", it will be wrong. In other words, what I'm trying to say is that it's syntax-dependent.

Do you think that I need to parse the output of file command? If so, what would be the best way to do it?
Also ldconfig -p does not help me here since it gives me all the libs and not that are really being used.

Replies are listed 'Best First'.
Re^5: Capture::Tiny getting stuck on ldd /proc/self/fd/1
by shmem (Chancellor) on Jun 22, 2021 at 15:08 UTC
    But this command does not give me all the packages I need.

    That's because you are not querying their dependencies. Run rpm -q --requires $pkg on the packages found. This will give you the packages they depend on. Add those packages, query their dependencies, repeat and you should end up with the complete set. No need for ldd.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
      Thanks again for your reply.
      So lets take an example /usr/bin/grep. In that case I get:
      rpm -qf --queryformat "[%{NAME}]" /usr/bin/grep grep
      After that, you suggested to run:
      rpm -q --requires grep info /bin/sh /bin/sh rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(CompressedFileNames) <= 3.0.4-1 libc.so.6()(64bit) libc.so.6(GLIBC_2.2.5)(64bit) libc.so.6(GLIBC_2.3)(64bit) libc.so.6(GLIBC_2.3.4)(64bit) libc.so.6(GLIBC_2.4)(64bit) rpmlib(PayloadIsLzma) <= 4.4.6-1
      How to handle this output? Which lines interest me? I guess to run rpm -q --requires info and get:
      bash zlib libzio /bin/sh /bin/sh rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(CompressedFileNames) <= 3.0.4-1 libbz2.so.1()(64bit) libc.so.6()(64bit) libc.so.6(GLIBC_2.2.5)(64bit) libc.so.6(GLIBC_2.3)(64bit) libc.so.6(GLIBC_2.3.4)(64bit) libc.so.6(GLIBC_2.4)(64bit) libncurses.so.5()(64bit) libz.so.1()(64bit) libzio.so.0()(64bit) rpmlib(PayloadIsLzma) <= 4.4.2-1
      What should I do with other lines?
        After that, you suggested to run:
        rpm -q --requires grep info /bin/sh /bin/sh rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(CompressedFileNames) <= 3.0.4-1 libc.so.6()(64bit) libc.so.6(GLIBC_2.2.5)(64bit) libc.so.6(GLIBC_2.3)(64bit) libc.so.6(GLIBC_2.3.4)(64bit) libc.so.6(GLIBC_2.4)(64bit) rpmlib(PayloadIsLzma) <= 4.4.6-1

        You can skip info, since this is a program to display manual pages. It provides no libraries. You can skip those rpmlib lines, too. The libc.so.6 package contains the standard C library, which is needed by all programs written in C. Include that. If in doubt, run rpm -ql $pkg | grep '\.so' to check whether a package provides shared libraries. If so, add that package. If not, you can skip it.

        perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'