Ubuntu 12.04 Precise Pangolin

01 Jul 2012


...

Разное

crontabs permissions

Кронтабы должны быть доступны на запись только root’у

Иначе игнорируются, в syslog’е сообщения cron[1710]: (*system*...) INSECURE MODE (group/other writable) (/etc/cron.d/...)

man crontab:
> /etc/crontab and the files in /etc/cron.d must be owned by root, and must not be group- or other-writable.

+Обсуждение с цитатами changelog'а есть здесь: [https://bugs.launchpad.net/ubuntu/+source/cron/+bug/741979](https://bugs.launchpad.net/ubuntu/+source/cron/+bug/741979)

svn (subversion)

subversion 1.7 в поставке нет

https://bugs.launchpad.net/ubuntu/+source/subversion/+bug/949143 – обсуждение

http://askubuntu.com/questions/65468/where-can-i-find-a-subversion-1-7-binary – ссылаются на репозиторий, откуда можно ставить

https://launchpad.net/~dominik-stadler/+archive/subversion-1.7 – про этот репозиторий

http://swherdman.com/2011/10/subversion-1-7-debian/ – собирают из исходников, на debian

Thrift

Хорошо собирается pbuilder’ом, см. thrift packaging и http://birchroad.wordpress.com/2011/03/15/installing-apache-thrift-in-ubuntu/

Perl

defined %hash

в 5.14 так делать нельзя

> perl -le 'use strict; my %d; print defined %d; print "OK";'
defined(%hash) is deprecated at -e line 1.
        (Maybe you should just omit the defined()?)

OK

экзотические варианты delete

Было:

> perl -v|grep built
This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi

> perl -le 'use strict; my $h = {aa => 1, cc=>3};  delete @{%$h}{qw/aa bb/}; print join "-", keys %$h'
cc

Стало:

> perl -v|grep built
This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux-gnu-thread-multi

> perl -le 'use strict; my $h = {aa => 1, cc=>3};  delete @{%$h}{qw/aa bb/}; print join "-", keys %$h'
Can't use string ("2/8") as a HASH ref while "strict refs" in use at -e line 1.

срезы хешей по ссылке

Было:

> perl -v|grep built
This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi

> perl -le 'use strict; my $h = {a=>1, b=>2}; my ($v1, $v2) = @{%$h}{qw/a b/}; print "$v1, $v2";'
1, 2

Стало:

> perl -v|grep built
This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux-gnu-thread-multi

> perl -le 'use strict; my $h = {a=>1, b=>2}; my ($v1, $v2) = @{%$h}{qw/a b/}; print "$v1, $v2";'
Can't use string ("2/8") as a HASH ref while "strict refs" in use at -e line 1.

Надо исправить на @{$h}{qw/a b/}

модификатор /r в s_/

Работает!

> perl -le '$s = "aab"; $t = $s =~ s/b/c/r; print "\$s = $s, \$t = $t";'
$s = aab, $t = aac

tr/0-9/a-j/d

Useless use of /d modifier in transliteration operator

(W misc) You have used the /d modifier where the searchlist has the same length as the replacelist. See perlop for more information about the /d modifier.

упаковка CPAN’овских дистирибутивов в .deb

Впечатление такое, что dh-make-perl перестал понимать параметр-каталог, и теперь работает только с ./

На 8.04 hardy было явно по-другому

> wget 'http://search.cpan.org/CPAN/authors/id/L/LO/LONERR/Pid-File-Flock-0.08.tar.gz'
> cp Pid-File-Flock-0.08.tar.gz libpid-file-flock-perl_0.08.orig.tar.gz
> tar -xzf Pid-File-Flock-0.08.tar.gz
> cd Pid-File-Flock-0.08
> dh-make-perl
> dpkg-buildpackage
> ls -l ../libpid-file-flock-perl_0.08-1*

Encode::decode_utf8

Было

> perl -v |grep built
This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi
> perl -MData::Dumper -MEncode -Mutf8 -le '$s = "ру"; print Dumper($s); $s = decode_utf8($s); print Dumper($s);'
$VAR1 = "\x{440}\x{443}";

Cannot decode string with wide characters at /usr/lib/perl/5.8/Encode.pm line 166.

Стало

> perl -v |grep built
This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux-gnu-thread-multi
> perl -MData::Dumper -MEncode -Mutf8 -le '$s = "ру"; print Dumper($s); $s = decode_utf8($s); print Dumper($s);'
$VAR1 = "\x{440}\x{443}";

$VAR1 = "\x{440}\x{443}";

Старая decode_utf8 была очень прозрачным алиасом для decode(“utf8”, …):

> grep -A 9 'sub decode_utf8' /usr/lib/perl/5.8.8/Encode.pm
sub decode_utf8($;$)
{
    my ($str, $check) = @_;
    if ($check){
        return decode("utf8", $str, $check);
    }else{
        return decode("utf8", $str);
        return $str;
    }
}

Новая имеет дополнительную логику, проверяет is_utf8:

> grep -A 10 '^sub decode_utf8' /usr/lib/perl/5.14.2/Encode.pm
sub decode_utf8($;$) {
    my ( $octets, $check ) = @_;
    return $octets if is_utf8($octets);
    return undef unless defined $octets;
    $octets .= '' if ref $octets;
    $check   ||= 0;
    $utf8enc ||= find_encoding('utf8');
    my $string = $utf8enc->decode( $octets, $check );
    $_[0] = $octets if $check and !ref $check and !( $check & LEAVE_SRC() );
    return $string;
}

экзотические варианты с utf8

Было:

> perl -v |grep built
This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi

> perl -MEncode -MJSON -Mutf8 -le 'sub p{print $_[0]."\nis_utf8: ".Encode::is_utf8($_[0])."\n";} $s =q!{"a":"русский текст"}!; $s = encode_utf8(encode_utf8($s));p $s;$j = JSON::from_json($s); p $j->{a}; $t = Encode::decode_utf8($j->{a}); p $t;'
{"a":"ÑÑÑÑкий ÑекÑÑ"}
is_utf8: 

ÑÑÑÑкий ÑекÑÑ
is_utf8: 1

русский текст
is_utf8: 1

(в результате имеем русский текст)

Стало:

> perl -v |grep built
This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux-gnu-thread-multi

> perl -MEncode -MJSON -Mutf8 -le 'sub p{print $_[0]."\nis_utf8: ".Encode::is_utf8($_[0])."\n";} $s =q!{"a":"русский текст"}!; $s = encode_utf8(encode_utf8($s));p $s;$j = JSON::from_json($s); p $j->{a}; $t = Encode::decode_utf8($j->{a}); p $t;'
{"a":"ÑÑÑÑкий ÑекÑÑ"}
is_utf8: 

ÑÑÑÑкий ÑекÑÑ
is_utf8: 1

ÑÑÑÑкий ÑекÑÑ
is_utf8: 1

(в результате имеем кракозябры)

LWP::Parallel::UserAgent

http://search.cpan.org/~marclang/ParallelUserAgent-2.57/

не работает :( последний апдейт – февраль 2004 (8 лет назад)

из собственной документации: >This library only supports libwww up to version 5.76

http://www.perlmonks.org/?node_id=758739 : >LWP::Parallel::UserAgent appears to work with libwww-perl versions up libwww-perl-5.814 (Jul 24, 2008)

https://rt.cpan.org/Public/Bug/Display.html?id=40261 : >Looks bad… Makes lots of errors, gobbles up all RAM and CPU… >Definitely doesn’t work with perl 5.12.1.

Альтернативы

http://www.perlmonks.org/?node_id=758739 :

  • WWW::Curl::Simple – requiring arcane things like “Moose”
  • AnyEvent::HTTP - it looks super duper!
  • Also WWW::Curl::Multi may be useful
  • Parallel::Forkmanager may be helpful.
  • Mojo::Client might be helpful.
  • POE::Component::Client::HTTP and the whole POE family IMHO is worth learning.
  • Possibly IO::Lambda would be able to help you. One needs to invest in learning the syntax though.

SSL в LWP, SOAP::Lite с сертификатами

http://tech.groups.yahoo.com/group/soaplite/message/6619

Re: Failing to connect with webservice when using SSL with ClientAuth 

Thanks to Mark Allen on the LWP mailing list, the answer can be found here:

http://www.mail-archive.com/libwww@perl.org/msg06964.html

(In case that link doesn't work for any reason, the brief answer is: I had to
include "use Net::SSL;" in my Perl program to make it work. Apparently, the
newer LWP module uses the IO::Socket::SSL module instead of the older Net::SSL,
which ignores the environment variables in the program pointing to my digital
certificates. By forcing the program to use Net::SSL, it picks up the variables
and works fine).

http://www.mail-archive.com/libwww@perl.org/msg06964.html

The basic issue is that there are two different implementations of the
SSL guts that LWP may use. One old one based on Net:SSL (which comes
from a virtually unmaintained module called Crypt::SSLeay) and a modern
one based on IO::Socket::SSL. By default, LWP chooses IO::Socket::SSL,
and IO::Socket::SSL does not honor the environment variable settings
you're specifying in your script - only Net::SSL uses those.

The easiest fix is probably to specify explicitly that you want LWP to
use the Net::SSL implementation. You can do this by adding

use Net::SSL ();

somewhere after your environment variable declarations near the top of
your program.

DateTime – роняет apache

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=649090 – описание проблемы.
В том числе упоминается особенность: PerlModule DateTime срабатывает нормально, но use DateTime в каком-нибудь внутреннем модуле – падение.
Также “apache crashes without an error”.

http://www.gossamer-threads.com/lists/modperl/modperl/103950?do=post_view_threaded#103950 – описание и указание, что проблема – в динамической библиотеке от Params::Classify:

It may be nothing, but I spent 2 months (off and on) with a crashing mod_perl/Apache to discover that in my case it was the DateTime that was the cause.

Hans (on the list) confirmed this and said “The latest DateTime and DateTime-TimeZone modules that work with mod_perl are DateTime 0.70 and DateTime-TimeZone 1.34.”

The root cause appears to be the Params::Classify module which loads Classify.dll - it is Classify.dll that is the problem. SInce P::C has a pure Perl implementation as well as the dll, I simplex moved the dll, and everything started working consistently. Hans reverted to the earlier DateTime, which worked for him.

Если удалить эти файлы – apache падать перестает: ls /usr/lib/perl5/auto/Params/Classify Classify.bs Classify.so

http://comments.gmane.org/gmane.comp.apache.mod-perl/35333 – контекст предыдущего письма

Хорошее решение – обновление Module::Runtime

libopenca-openssl-perl

При упаковке в .deb тесты разнообразно падают, но впечатление, что проблема в тестах, а не в коде/окружении (??как подтвердить)

Если игнорируя тесты упаковать и установить – роняет apache в момент загрузки OpenCA::OpenSSL, segmentation fault

Варианты:

  • не пользоваться OpenCA::OpenSSL, работать с программой openssl напрямую;
  • вместо apache использовать Starman

Starman

Хорош. На precise ставится из стандартного репозитория, на hardy сам по себе в репозитории есть, но надо еще доупаковать несколько модулей с CPAN’а. Запускается и подхватывает psgi-приложения “на раз”.

Wide character in syswrite at /usr/share/perl5/Starman/Server.pm line 468.
По спецификации PSGI весь вывод уже должен быть закодиован в нужную кодировку
Комментарии Миягавы:
https://groups.google.com/forum/#!topic/psgi-plack/J0IiUanfgeU
http://groups.google.com/group/psgi-plack/browse_thread/thread/27422251a9df81e5

timelocal

Обработка дат после 2038 года

Было:

> perl -v |grep built
This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi
> perl -MTime::Local -le 'print timelocal( 0, 0, 0, 1, 1, 2040-1900 );'
Day too big - 25598 > 24855
Sec too small - 25598 < 83752
Cannot handle date (0, 0, 0, 1, 1, 2040) at -e line 1

Стало:

> perl -v |grep version
This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux-gnu-thread-multi
> perl -MTime::Local -le 'print timelocal( 0, 0, 0, 1, 1, 2040-1900 );'
2211652800

AnyEvent::HTTP, кириллические url’ы

Url’ы с кириллическими доменами надо явно кодировать в utf8.

Было:

> perl -v |grep built
This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi
> perl -MAnyEvent::HTTP -Mutf8 -le 'http_get("http://кондиционер.рф", sub {}); print "Done";'
Done

Стало:

> perl -v|grep version
This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux-gnu-thread-multi
> perl -MAnyEvent::HTTP -Mutf8 -le 'http_get("http://кондиционер.рф", sub { }); print "Done";' 
Wide character in send at /usr/lib/perl5/AnyEvent/DNS.pm line 1198.
> perl -MAnyEvent::HTTP -MEncode -Mutf8 -le 'http_get(Encode::encode_utf8("http://кондиционер.рф"), sub { }); print "Done";'
Done