Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
tw_cli/tw_cli.pl
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
35 lines (27 sloc)
925 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl | |
use strict; | |
use warnings; | |
sub sort_host { | |
my ($n1,$n2); | |
($n1)=$a=~/^host(\d+)$/ and ($n2)=$b=~/^host(\d+)$/ and return $n1 <=> $n2; | |
return $a cmp $b; | |
} | |
our $SYS_unshare=272; # /usr/include/asm/unistd_64.h | |
our $CLONE_NEWNS=0x20000; # /usr/include/linux/sched.h | |
my $pid=fork; | |
defined $pid or die "$!\n"; | |
unless ($pid) { | |
opendir my $d,"/sys/class/scsi_host"; | |
my @names=sort sort_host grep !/^\.\.?$/,readdir $d; | |
syscall($SYS_unshare,$CLONE_NEWNS) and die "$!\n"; | |
-d '/tmp/sysfs' or mkdir("/tmp/sysfs") or die "/tmp/sysfs: $!\n"; | |
system 'mount','-tsysfs','BLA','/tmp/sysfs' and exit 1; | |
system 'mount','-ttmpfs','BLA','/sys/class/scsi_host' and exit 1; | |
for my $name (reverse @names) { | |
symlink("/tmp/sysfs/class/scsi_host/$name","/sys/class/scsi_host/$name") or die "/sys/class/scsi_host/$name: $!\n"; | |
} | |
exec '/home/buczek/tw_cli/tw_cli.orig',@ARGV; | |
die "$!\n"; | |
} | |
wait; | |
$? and exit 1; | |