Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Capture::Tiny getting stuck on ldd /proc/self/fd/1

by shmem (Chancellor)
on Jun 21, 2021 at 21:58 UTC ( [id://11134135]=note: print w/replies, xml ) Need Help??


in reply to Capture::Tiny getting stuck on ldd /proc/self/fd/1

Before setting command: /proc/self/fd/1 Before running command

Why are you running ldd on STDOUT of your script? /proc/self pertains to the running process, the numbers 0, 1, 2 in the fd directory are STDIN, STDOUT and STDERR. These are not executables.

The standard file handles are redirected by Capture::Tiny. I have not looked deeply at what happens, but ldd tries to read from a file handle which doesn't deliver anything, and capture can't read since ldd doesn't deliver. Smells of deadlock. The Ctrl-C cancels the program invoked by capture, and the program continues.

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

Replies are listed 'Best First'.
Re^2: Capture::Tiny getting stuck on ldd /proc/self/fd/1
by ovedpo15 (Pilgrim) on Jun 22, 2021 at 10:06 UTC
    Hi!
    Thank you for your explanation. It makes sense. I'm running ldd on a list of paths I find to find the shared libs. Is there a way in perl to check if path is dynamic, before actually running ldd. Something like:
    if (-dy $path) { # Run ldd of path }
    where -dy checks if $path is dynamic. If it's not built in, is there a libraries or another way to do so?
      I'm running ldd on a list of paths I find to find the shared libs.

      There are no shared libs in /proc. If you find any in /dev, chances are that you were hacked.

      Is there a way in perl to check if path is dynamic

      You could use the linux file(1) utility to check the type and look for shared object and dynamically linked in its output. I'm not aware of a perl module which provides that information.

      You didn't answer the question: for what purpose? If you just want the dynamic libraries your system knows about, run ldconfig -p and parse the output. Note that most of the files it reports are symbolic links, which you might have to resolve, depending on purpose.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
        > I'm not aware of a perl module which provides that information.

        You can experiment with File::Type, File::LibMagic, File::MMagic, etc.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11134135]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-25 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found