vsespb has asked for the wisdom of the Perl Monks concerning the following question:
This code just hangs if path to perl program contain UTF-8 characters (like 'perl тест/poc.pl').#!/usr/bin/env perl use strict; use warnings; $SIG{__DIE__} = sub { if ($^S == 0) { for my $s (0..$#_) { dcs($_[$s]); }; } }; sub dcs { my ($p1, $p2) = @_; my $cs=''; for (my $i=1; $i<3; $i++) { my ($package, $filename, $line, $subroutine) = caller($i); last if ( ! defined($package) ); print STDERR $filename; } print STDERR $p1; } sub mysub { die; } binmode STDERR, ":encoding(koi8-r)"; mysub(); 1;
It can reproduce it on two linux boxes (perl 10 and perl 12). Both have UTF-8 locale, UTF-8 filenames.
I hangs with different single-byte encodings (i tried koi-8 and cp1251). It hangs only when STDERR used and only when die is inside mysub.
The reason why I am trying to debug such a weird code in these weird circumstances - I have another script with similar code and a user with similar problem, however I cannot reproduce his problem in full. So I came to this PoC - I think maybe it's related.
Also this user does not do fancy things like using non-ASCII characters in filenames or using encoding different from locale encoding. However he runs FreeBSD and his locale is koi8-r (and my program sets STDERR encoding to KOI-8 too)
UPD: Perl hangs with 100% CPU usage and strace hangs with:UPD: Shortest PoC:open("/usr/lib/perl/5.10/auto/Encode/Byte/Byte.so", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240\\\3\0\0\0\ +0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0644, st_size=375048, ...}) = 0 mmap(NULL, 2470176, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, + 0) = 0x7fcef2b27000 mprotect(0x7fcef2b62000, 2093056, PROT_NONE) = 0 mmap(0x7fcef2d61000, 139264, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIX +ED|MAP_DENYWRITE, 3, 0x3a000) = 0x7fcef2d61000 close(3) = 0 mprotect(0x7fcef2d61000, 135168, PROT_READ) = 0
Again, should be ran as 'perl тест/poc.pl'. In this version die() does not reproduce problem - only 'croak'. Also cp1251 works without problem.#!/usr/bin/env perl use strict; use warnings; use Carp; $SIG{__DIE__} = sub { print STDERR $_ for (@_); }; binmode STDERR, ":encoding(koi8-r)"; sub mysub { croak; } mysub(); 1;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Weird STDERR/SIGDIE/Encodings issue
by McA (Priest) on Mar 28, 2013 at 22:54 UTC | |
by vsespb (Chaplain) on Mar 28, 2013 at 23:10 UTC | |
by McA (Priest) on Mar 28, 2013 at 23:51 UTC | |
by vsespb (Chaplain) on Mar 29, 2013 at 10:30 UTC |