develooper Front page | perl.perl5.porters | Postings from January 2019

[perl #133765] [PATCH] 5.28.1: $^X is undefined on Linux without/proc

Thread Previous
January 12, 2019 21:19
[perl #133765] [PATCH] 5.28.1: $^X is undefined on Linux without/proc
Message ID:
# New Ticket Created by 
# Please include the string:  [perl #133765]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.40 running under perl 5.22.3.

On normal system
$ perl -le 'use warnings; print $^X'

In a chroot without /proc or just with sudo umount /proc
$ perl -le 'use warnings; print $^X'
Use of uninitialized value ...

Current implementation of $^X assumes that /proc/self/exe
is always available and accessible on Linux.
It is not true; For example, in ALT Linux 
secure chroot build environment does not mount /proc
by default. 
Other example is early stages of system initialization
or system boot failure where /proc is not yet mounted
or failed to mount. 

In that case, $^X should be PL_origargv[0].
Instead, it is undefined.

As a result, perl tools can fail or change its behaviour.

for example, now ExtUtils::MakeMaker fails without /proc:
+ /usr/bin/perl Makefile.PL PREFIX=/usr INSTALLDIRS=vendor
Use of uninitialized value $_[0] in substitution (s///) at /usr/share/perl5/File/ line 341.
fileparse(): need a valid pathname at /usr/share/perl5/ExtUtils/ line 1128.
and perl modules can not be built in chroot without /proc.
It is regression compared to perl 5.26.

Proposed patch (tested)

diff --git a/caretx.c b/caretx.c
index d758f73..aa069cc 100644
--- a/caretx.c
+++ b/caretx.c
@@ -97,7 +97,15 @@ Perl_set_caret_X(pTHX) {
 #elif defined(HAS_PROCSELFEXE)
     char buf[MAXPATHLEN];
-    SSize_t len = readlink(PROCSELFEXE_PATH, buf, sizeof(buf) - 1);
+    SSize_t len;
+    /* NOTE: it is possible for /proc to be unmounted
+     * or for perl to be run in a chroot environment without /proc . */
+    if (access(PROCSELFEXE_PATH, R_OK) != 0) {
+	/* Fallback */
+	sv_setpv(caret_x, PL_origargv[0]);
+	return;
+    }
+    len = readlink(PROCSELFEXE_PATH, buf, sizeof(buf) - 1);
     /* NOTE: if the length returned by readlink() is sizeof(buf) - 1,
      * it is impossible to know whether the result was truncated. */
Site configuration information for perl 5.22.3:

Configured by ALT Linux Team at Wed Feb  1 13:44:57 UTC 2017.

Summary of my perl5 (revision 5 version 22 subversion 3) configuration:
    osname=linux, osvers=4.4.42-std-def-alt1.1, archname=x86_64-linux-thread-multi
    uname='linux localhost.localdomain 4.4.42-std-def-alt1.1 #1 smp fri jan 13 06:15:14 utc 2017 x86_64 gnulinux '
    config_args='-ders -Dusethreads -Duseithreads -Duselargefiles -Duseshrplib -Dcc=gcc -Doptimize=-pipe -Wall -g -O2 -DDEBUGGING=maybe -Dprefix=/usr -Dprivlib=/usr/share/perl5 -Darchlib=/usr/lib64/perl5 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib64/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.22 -Dsitearch=/usr/local/lib64/perl/5.22 -Dotherlibdirs=/etc/perl5:/usr/lib/perl5/vendor_perl -Dinc_version_list=none -Dpager=/usr/bin/less -isR -Dman1dir=/usr/share/man/man1 -Dman3dir=none -Dcf_by=ALT Linux Team -Dcf_email=Perl Maintainers Team <> -Dmyhostname=localhost -Dperladmin=root@localhost'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-pipe -Wall -g -O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion='', gccversion='5.3.1 20151207 (ALT Linux 5.3.1-alt3)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib /lib64 /usr/lib64 /lib /usr/local/lib64
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc, so=so, useshrplib=true,
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -pipe -Wall -g -O2 -L/usr/local/lib -fstack-protector-strong'

@INC for perl 5.22.3:

Environment for perl 5.22.3:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About