-
Elvin Sindrilaru authored
This is just for maintaining compatibility with the current deployment
Elvin Sindrilaru authoredThis is just for maintaining compatibility with the current deployment
x2proc 1.45 KiB
#!/usr/bin/perl
##########################################################################
# This is a small helper script to modify xrootd proc entries on localhost
# Author: A.J.Peters - Andreas.Joachim.Peters@cern.ch
##########################################################################
use POSIX ":sys_wait_h";
use Time::HiRes qw( usleep );
sub usage {
printf STDERR "Usage: x2proc <key> <value>\n";
exit(-1);
}
my $rand = rand();
$SIG{'INT'} = 'CLEANUP';
sub CLEANUP {
if ( -e "/tmp/$rand" ) {
unlink "/tmp/$rand";
}
}
my $key = shift @ARGV;
my $val = shift @ARGV;
my $host = `hostname -s`;
chomp $host;
printf "[x2proc::$host] setting proc entry $key=$val\n";
if ( ($key eq "") || ($val eq "") ) { usage();}
my $procbase=`cat /etc/xrd.cf.server | grep -w xcastor2.proc | awk '{print \$2}'`;
my $port=`cat /etc/xrd.cf.server | grep -w xrd.port | awk '{print \$2}'`;
chomp $procbase;
chomp $port;
if ( $port eq "" ) { $port = "1094";}
system("echo $val > /tmp/$rand");
my $pid;
if (! ($pid=fork())) {
system("export LD_LIBRARY_PATH=/usr/lib64/; /usr/bin/xrdcp /tmp/$rand root://localhost:$port//proc/$key");
exit(0);
}
my $cnt=0;
my $ret=0;
for (;;) {
$kid = waitpid(-1, WNOHANG);
if ($kid >0) {last;}
if ($cnt >50) {printf STDERR "error: couldn't do proc modification within 5 seconds...\n"; kill 1, $pid; $ret=-1; system("pkill -f /tmp/$rand"); last;}
usleep(100000);
$cnt++;
}
unlink "/tmp/$rand";
exit($ret);