構文 |
|
chroot ルート・ディレクトリにするディレクトリ名 |
返り値 |
|
実行結果 |
説明
- 指定したディレクトリをルート・ディレクトリとして扱う。使用できるのはスーパー・ユーザのみです。
使用例
#!/usr/bin/perl
use strict;
use warnings;
my $root_dir = '/home/user1';
my $search_dir = '/';
chroot $root_dir or die $!;
opendir my $dh, $search_dir or die "$!";
foreach my $file (readdir $dh) {
print $search_dir, $file, "\n";
}
closedir $dh;
#!/usr/bin/perl
use strict;
use warnings;
my $dir = '/home/user1';
my $pid;
if ($pid = fork()) {
wait();
print "----- parent process -----\n";
show_files();
} elsif (defined $pid) {
chroot $dir or die $!;
print "----- child process -----\n";
show_files();
} else {
print "Error:$!\n";
}
print "End.\n";
sub show_files {
my $search_dir = '/';
opendir my $dh, $search_dir or die "$!";
foreach my $file (readdir $dh) {
print $search_dir, $file, "\n";
}
closedir $dh;
}