Хочу запустить perl скрипт (веб сервер) в chroot окружении.
Скопировал bash, perl, его модули и всё нужное для работаы в каталог /home/bunny. Но приложение отказывается работать правильно. Вот мои действия$ sudo chroot /home/bunny
bash-3.2# ls
bin dev etc lib root usr
bash-3.2# cd root
bash-3.2# ls
index.html server.pl server.pl~
bash-3.2# cat server.pl
#!/usr/bin/perl
use IO::Socket::INET;my $port = 8888;
my $ident = 'server';my $serv = IO::Socket::INET->new(
Proto => 'tcp',
LocalPort => $port,
Listen => SOMAXCONN,
Reuse => 1,
) or die "Can't start server: $!";print "[Server $0 accepting clients at http://localhot:$port/]\n";
sub sendfile {
my $client = shift;
my $file = shift;
open(FILE, $file);
while (<FILE>) { print $client $_ };
close FILE;
}while (my $client = $serv->accept()) {
$client->autoflush(1);
my $request = <$client>;
if ($request =~ m|^GET /(.*) HTTP/1.[01]|) {
if ($1 eq 'index.html' or $1 eq '') { sendfile($client, 'index.html'); next }
if (-e $1) {
print $client "HTTP/1.0 200 OK\nServer: $ident\nContent-type: text/html\n\n";
sendfile($client, $1);
} else {
print $client "HTTP/1.0 404 Not Found\nServer: $ident\n";
print $client "Content-type: text/html\n\n";
print $client "file $1 not found\n";
}
} else {
print $client "HTTP/1.0 400 Bad Request\nServer: $ident\n";
print $client "Conten-type: text/html\n\n";
print $client "Bad request\n";
}
close $client;
}bash-3.2# perl server.pl
Can't start server: No such file or directory at server.pl line 7.
bash-3.2#
Без chroot`a всё работает хорошо. Пробовал дописывать в начало скрипта
chroot('/home/bunny');
но появляется всё та же ошибка
Can't start server: No such file or directory at server.pl line 11.
Почему Perl останавливается на этой строке?
my $serv = IO::Socket::INET->new(
Запустите обоими способами и сравните вывод
strace perl server.pl 2>&1 | perl -ne '/open\("(.+)"/;print $1,"\n"' | sort |uniq | xargs ls
Могет быть поможет
>Запустите обоими способами и сравните вывод
>strace perl server.pl 2>&1 | perl -ne '/open\("(.+)"/;print $1,"\n"' | sort |uniq | xargs ls
>Могет быть поможетЭто результат при запуске с chroot():
$ strace perl server.pl 2>&1 | perl -ne '/open\("(.+)"/;print $1,"\n"' | sort |uniq | xargs ls
ls: /usr/lib/locale/locale-archive: No such file or directory
ls: /usr/lib/locale/ru_UA.UTF-8/LC_ADDRESS: No such file or directory
ls: /usr/lib/locale/ru_UA.UTF-8/LC_COLLATE: No such file or directory
ls: /usr/lib/locale/ru_UA.UTF-8/LC_CTYPE: No such file or directory
ls: /usr/lib/locale/ru_UA.UTF-8/LC_IDENTIFICATION: No such file or directory
ls: /usr/lib/locale/ru_UA.UTF-8/LC_MEASUREMENT: No such file or directory
ls: /usr/lib/locale/ru_UA.UTF-8/LC_MESSAGES: No such file or directory
ls: /usr/lib/locale/ru_UA.UTF-8/LC_MONETARY: No such file or directory
ls: /usr/lib/locale/ru_UA.UTF-8/LC_NAME: No such file or directory
ls: /usr/lib/locale/ru_UA.UTF-8/LC_NUMERIC: No such file or directory
ls: /usr/lib/locale/ru_UA.UTF-8/LC_PAPER: No such file or directory
ls: /usr/lib/locale/ru_UA.UTF-8/LC_TELEPHONE: No such file or directory
ls: /usr/lib/locale/ru_UA.UTF-8/LC_TIME: No such file or directory
ls: /usr/share/locale-langpack/ru/LC_MESSAGES/libc.mo: No such file or directory
ls: /usr/share/locale-langpack/ru_UA/LC_MESSAGES/libc.mo: No such file or directory
ls: /usr/share/locale-langpack/ru_UA.utf8/LC_MESSAGES/libc.mo: No such file or directory
ls: /usr/share/locale-langpack/ru_UA.UTF-8/LC_MESSAGES/libc.mo: No such file or directory
ls: /usr/share/locale-langpack/ru.utf8/LC_MESSAGES/libc.mo: No such file or directory
ls: /usr/share/locale-langpack/ru.UTF-8/LC_MESSAGES/libc.mo: No such file or directory
ls: /usr/share/locale/ru/LC_MESSAGES/libc.mo: No such file or directory
ls: /usr/share/locale/ru_UA/LC_MESSAGES/libc.mo: No such file or directory
ls: /usr/share/locale/ru_UA.utf8/LC_MESSAGES/libc.mo: No such file or directory
ls: /usr/share/locale/ru_UA.UTF-8/LC_MESSAGES/libc.mo: No such file or directory
ls: /usr/share/locale/ru.utf8/LC_MESSAGES/libc.mo: No such file or directory
ls: /usr/share/locale/ru.UTF-8/LC_MESSAGES/libc.mo: No such file or directory
/dev/urandom /usr/lib/locale/ru_UA.utf8/LC_MESSAGES/SYS_LC_MESSAGES /usr/lib/perl/5.8/IO/Socket/UNIX.pm
/etc/ld.so.cache /usr/lib/locale/ru_UA.utf8/LC_MONETARY /usr/lib/perl/5.8/Socket.pm
/lib/tls/i686/cmov/libcrypt.so.1 /usr/lib/locale/ru_UA.utf8/LC_NAME /usr/lib/perl/5.8/XSLoader.pm
/lib/tls/i686/cmov/libc.so.6 /usr/lib/locale/ru_UA.utf8/LC_NUMERIC /usr/share/locale/locale.alias
/lib/tls/i686/cmov/libdl.so.2 /usr/lib/locale/ru_UA.utf8/LC_PAPER /usr/share/perl/5.8/Carp.pm
/lib/tls/i686/cmov/libm.so.6 /usr/lib/locale/ru_UA.utf8/LC_TELEPHONE /usr/share/perl/5.8/Exporter/Heavy.pm
/lib/tls/i686/cmov/libpthread.so.0 /usr/lib/locale/ru_UA.utf8/LC_TIME /usr/share/perl/5.8/Exporter.pm
server.pl /usr/lib/perl/5.8/auto/IO/IO.so /usr/share/perl/5.8/SelectSaver.pm
/usr/lib/gconv/gconv-modules.cache /usr/lib/perl/5.8/auto/Socket/Socket.so /usr/share/perl/5.8/strict.pm
/usr/lib/locale/ru_UA.utf8/LC_ADDRESS /usr/lib/perl/5.8/Errno.pm /usr/share/perl/5.8/Symbol.pm
/usr/lib/locale/ru_UA.utf8/LC_COLLATE /usr/lib/perl/5.8/IO/Handle.pm /usr/share/perl/5.8/warnings.pm
/usr/lib/locale/ru_UA.utf8/LC_CTYPE /usr/lib/perl/5.8/IO.pm /usr/share/perl/5.8/warnings/register.pm
/usr/lib/locale/ru_UA.utf8/LC_IDENTIFICATION /usr/lib/perl/5.8/IO/Socket/INET.pm
/usr/lib/locale/ru_UA.utf8/LC_MEASUREMENT /usr/lib/perl/5.8/IO/Socket.pm/usr/lib/locale/ru_UA.utf8/LC_MESSAGES:
SYS_LC_MESSAGESи к чему эти файлы для работы chroot?
Ну посмотри исходный код perl и всех используемых им либ, может узнаешь. Если неохота смотреть, то на всякий случай напоминаю что ряд встроенных функций работает с локалью