Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

perl lost its modules!

by seandarcy (Initiate)
on Apr 01, 2014 at 21:19 UTC ( #1080639=perlquestion: print w/ replies, xml ) Need Help??
seandarcy has asked for the wisdom of the Perl Monks concerning the following question:

I'm on Fedora 20. perl-5.18.2-289.fc20.x86_64 As a user:

$ perl -e 'use strict; print "ok"' Can't locate strict.pm: Permission denied at -e line 1. BEGIN failed--compilation aborted at -e line 1.

But:

$ ls -l /usr/share/perl5/strict.pm -rwxr-xr-x. 1 root root 3933 Jan 7 09:48 /usr/share/perl5/strict.pm

and

$ perl -e 'print join "\n", @INC' /root/perl5/lib/perl5/x86_64-linux-thread-multi /root/perl5/lib/perl5 /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5

and the user can read strict.pm:

$ cat /usr/share/perl5/strict.pm package strict; $strict::VERSION = "1.07"; ...............

As root this all works.

strict.pm is in @INC, and the user has read permission. There's not another strict.pm on the machine:

# locate strict.pm /usr/share/perl5/strict.pm #

What am I doing wrong?

FWIW,

$ perl -V Can't locate Config.pm: Permission denied.
sean

Comment on perl lost its modules!
Select or Download Code
Re: perl lost its modules!
by LanX (Canon) on Apr 01, 2014 at 21:40 UTC
    hmm shooting in the dark:

  • which permissions does the directory /usr/share/perl5 have?

  • does use lib '/usr/share/perl5' help?

  • could you try printing @INC within a BEGIN block to exclude weird settings which only apply afterwards?

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      ls -l /usr/share | grep perl5 drwxr-xr-x. 49 root root 4096 Mar 31 18:40 perl5

      I don't see how it's a system permissions issue. As user, I can cat the file

      made a small test script:

      $ cat perl-test.pl #!/usr/bin/perl use lib '/usr/share/perl5'; use strict; print "ok"; $ chmod +x perl-test.pl $ ./perl-test.pl Can't locate lib.pm: Permission denied at ./perl-test.pl line 2. BEGIN failed--compilation aborted at ./perl-test.pl line 2.

      Not sure what you mean by printing @INC in a BEGIN block, but I sure don't know how.

        > I don't see how it's a system permissions issue. As user, I can cat the file

        Directory permissions distinguish between accessing files and reading the directory. If Perl can't read the dir then it can't find the modules, while it's still possible to access the files by full path.

        Anyway it seems boftx already found the solution further down. :)

        Cheers Rolf

        ( addicted to the Perl Programming Language)

Re: perl lost its modules!
by hippo (Curate) on Apr 01, 2014 at 21:44 UTC

    Have you checked the audit log? It may simply be a case of incorrect contexts. For reference, my strict.pm is system_u:object_r:usr_t:s0

      Nothing in the audit log. I ran tail -f /var/log/audit/audit.log and then executed my little perl script. Nothing.

      And:

      grep ^SELINUX= /etc/selinux/config SELINUX=permissive

      And I thought this would be a winner!

Re: perl lost its modules!
by Laurent_R (Parson) on Apr 01, 2014 at 22:39 UTC
    No idea, but maybe changing file permissions to 755 or possibly even 775 for every file in the INC hierarchy might solve the issue.
       chmod -R 775 /usr/share/perl5

      no success. And I can already read the modules: for instance I can cat strict.pm. It doesn't appear to be a linux permissions issue.

      That's a bad idea.

      You shouldn't change the permissions on files in /usr directories except for the ones that you (the system administrator) own like in /usr/local.

      Furthermore, running a command like chmod -R is especially dangerous, if you do not understand what you are doing.

      The *.pm files in /usr are supposed to have 0644 permissions. They should not be set with execute. They are not executable files, after all.

      Having said all that, this particular change is most likely benign. But you should never change files in the /usr directory except your own. These files and their permissions are managed by the system and rpm(8) in the OP's case.

      Run the command rpm -V perl to see all the "damage" now.

Re: perl lost its modules!
by roboticus (Canon) on Apr 01, 2014 at 23:25 UTC

    seandarcy:

    Is it possibly finding them in a previous directory (e.g., /root/perl5/lib/perl5) where they exist but you *don't* have permission to read/execute them?

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      AFAICT there's only one strict.pm on the box:

      # locate strict.pm /usr/share/perl5/strict.pm

      And there's only one lib.pm in the @INC hierarchy:

      # locate /lib.pm /root/.cpan/build/local-lib-1.008004-GOPHT9/blib/lib/local/lib.pm /root/.cpan/build/local-lib-1.008004-GOPHT9/lib/local/lib.pm /usr/lib64/perl5/lib.pm

      The Fedora installation does set PERL5LIB to /root/perl5, but that folder does not exist,

      $ echo $PERL5LIB /root/perl5/lib/perl5/x86_64-linux-thread-multi:/root/perl5/lib/perl5 # ls -l /root/perl5 ls: cannot access /root/perl5: No such file or directory
      I'm really stumped.
Re: perl lost its modules!
by boftx (Chaplain) on Apr 01, 2014 at 23:51 UTC

    This is a long shot, but is it possible that one of the earlier dirs in @INC has permissions that prevent perl from looking in it and is causing perl to terminate the search early? That "permission denied" message might make that feasible.

    Edit: Another thought, do you know for sure what effective uid/gid perl is running under? Is it possible the SUID bit is set? Like I said, these are long shots at best.

    It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.
      This is a long shot, but is it possible that one of the earlier dirs in @INC has permissions that prevent perl from looking in it and is causing perl to terminate the search early?
      Actually that is almost certainly the issue. The OP has /root first in the path which normally isn't accessible, and perl 5.18.0 onwards stops and errs on failure:
      $ perl5180 -I/root -Mstrict -e 1 Can't locate strict.pm: Permission denied. BEGIN failed--compilation aborted. $

      Dave.

        OK, you're my new favorite solution. How do I change the INC path? Or do I create the /root/perl5 folders, and chmod 755?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1080639]
Approved by boftx
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2014-09-18 01:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (104 votes), past polls