Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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

Replies are listed 'Best First'.
Re: perl lost its modules!
by boftx (Deacon) 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?

Re: perl lost its modules!
by roboticus (Chancellor) 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 LanX (Chancellor) 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 (Prior) 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 (Abbot) 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.

      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.

       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.

Re: perl lost its modules!
by Anonymous Monk on Sep 07, 2015 at 18:10 UTC
    Hi, Thanks to this thread I found out why my script was failing with a similar error. All was fine with the root and user account, but failed when I sudo -u myser in root crontab. The @INC included (last, well hidden) the '.' which was actually... /root of course. So just a cd in the launching shell script and voila, but it took me too much effort and wasted time over this (stupid) new perl behaviour. I do not give a damn if @INC (or PATH, or LD_LIBRARY_PATH or WHATEVER PATH) includes a sometimes non-readable directory. My special thanks for the wasted time (and VERY unhappy clients of mine) to all the morons who coded this new perl behavior.

      I agree that it's really frustrating when upgrading your Perl breaks stuff.

      In this case, the error message that Perl spits out when it cannot compile for this reason (missing permissions on a directory in @INC) should include a warning about the fact that it has stopped searching @INC. It does emit a message (with brevity, and still without specifically saying that the directory permissions were missing, and stating the full path of the file even if it doesn't know whether the file exists), starting in Perl 5.21.7:

      $ perl5217 -I/root -Mstrict -e 1 Can't locate strict.pm: /root/strict.pm: Permission denied. BEGIN failed--compilation aborted.
      There is a currently open bug discussing this, with the reporter calling for the change to be rolled back. You can also read the bug issue report that prompted the change in the first place.

      Note that the directory must be executable, and the file readable. Having the directory readable if it's not executable doesn't help, on my machine at least. Using Perl 5.22:

      [14:14][nick:~]$ sudo ls -la /var/noperms total 0 dr--r--r-- 3 root wheel 102 Sep 7 14:06 . drwxr-xr-x 28 root wheel 952 Sep 7 13:38 .. -r--r--r-- 1 root wheel 0 Sep 7 14:06 strict.pm [14:14][nick:~]$ perl -I/var/noperms/ -Mstrict -e 1 Can't locate strict.pm: /var/noperms/strict.pm: Permission denied. BEGIN failed--compilation aborted.
      . . . the directory doesn't have to be readable at all, as long as it's executable:
      [14:17][nick:~]$ sudo ls -la /var/noperms total 0 d--x--x--x 3 root wheel 102 Sep 7 14:06 . drwxr-xr-x 28 root wheel 952 Sep 7 13:38 .. -r--r--r-- 1 root wheel 0 Sep 7 14:06 strict.pm [14:17][nick:~]$ perl -I/var/noperms/ -Mstrict -e 1 strict.pm did not return a true value. BEGIN failed--compilation aborted.
      And it definitely prints the full path of the file it's looking for, even if it can't read the directory, making for a very confusing error message:
      [14:19][nick:~]$ sudo ls -la /var/noperms total 0 d--------- 2 root wheel 68 Sep 7 14:19 . drwxr-xr-x 28 root wheel 952 Sep 7 13:38 .. [14:19][nick:~]$ perl -I/var/noperms/ -Mstrict -e 1 Can't locate strict.pm: /var/noperms/strict.pm: Permission denied. BEGIN failed--compilation aborted.

      The way forward always starts with a minimal test.

      Hi, Thanks to this thread I found out why my script was failing with a similar error. All was fine with the root and user account, but failed when I sudo -u myser in root crontab. The @INC included (last, well hidden) the '.' which was actually... /root of course. So just a cd in the launching shell script and voila, but it took me too much effort and wasted time over this (stupid) new perl behaviour. I do not give a damn if @INC (or PATH, or LD_LIBRARY_PATH or WHATEVER PATH) includes a sometimes non-readable directory. My special thanks for the wasted time (and VERY unhappy clients of mine) to all the morons who coded this new perl behavior.

      :)

      Why did you make an upgrade without testing first?

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: (6)
As of 2016-07-29 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (259 votes). Check out past polls.