1*cdf0e10cSrcweir: 2*cdf0e10cSrcweireval 'exec perl -S $0 ${1+"$@"}' 3*cdf0e10cSrcweir if 0; 4*cdf0e10cSrcweir#************************************************************************* 5*cdf0e10cSrcweir# 6*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7*cdf0e10cSrcweir# 8*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates. 9*cdf0e10cSrcweir# 10*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite 11*cdf0e10cSrcweir# 12*cdf0e10cSrcweir# This file is part of OpenOffice.org. 13*cdf0e10cSrcweir# 14*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify 15*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3 16*cdf0e10cSrcweir# only, as published by the Free Software Foundation. 17*cdf0e10cSrcweir# 18*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful, 19*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of 20*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details 22*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code). 23*cdf0e10cSrcweir# 24*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License 25*cdf0e10cSrcweir# version 3 along with OpenOffice.org. If not, see 26*cdf0e10cSrcweir# <http://www.openoffice.org/license.html> 27*cdf0e10cSrcweir# for a copy of the LGPLv3 License. 28*cdf0e10cSrcweir# 29*cdf0e10cSrcweir#************************************************************************* 30*cdf0e10cSrcweir# 31*cdf0e10cSrcweir# build_client - client for the build tool in server mode 32*cdf0e10cSrcweir# 33*cdf0e10cSrcweir 34*cdf0e10cSrcweiruse strict; 35*cdf0e10cSrcweiruse Socket; 36*cdf0e10cSrcweiruse Sys::Hostname; 37*cdf0e10cSrcweiruse File::Temp qw(tmpnam); 38*cdf0e10cSrcweiruse POSIX; 39*cdf0e10cSrcweiruse Cwd qw (cwd); 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir$SIG{KILL} = \&handle_temp_files; 42*cdf0e10cSrcweir$SIG{INT} = \&handle_temp_files; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir### main ### 45*cdf0e10cSrcweirmy $enable_multiprocessing = 1; 46*cdf0e10cSrcweirmy $server_list_file; 47*cdf0e10cSrcweirmy $server_list_time_stamp = 0; 48*cdf0e10cSrcweirmy %ENV_BACKUP; 49*cdf0e10cSrcweir$ENV_BACKUP{$_} = $ENV{$_} foreach (keys %ENV); 50*cdf0e10cSrcweir 51*cdf0e10cSrcweirif ($^O eq 'MSWin32') { 52*cdf0e10cSrcweir eval { require Win32::Process; import Win32::Process; }; 53*cdf0e10cSrcweir $enable_multiprocessing = 0 if ($@); 54*cdf0e10cSrcweir} else { 55*cdf0e10cSrcweir use Cwd 'chdir'; 56*cdf0e10cSrcweir}; 57*cdf0e10cSrcweirmy $processes_to_run = 1; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweirmy %hosts_ports = (); 60*cdf0e10cSrcweirmy $default_port = 7890; 61*cdf0e10cSrcweirmy @ARGV_COPY = @ARGV; # @ARGV BACKUP 62*cdf0e10cSrcweir#$ARGV_COPY{$_}++ foreach (@ARGV); 63*cdf0e10cSrcweirprint "arguments: @ARGV\n"; 64*cdf0e10cSrcweirget_options(); 65*cdf0e10cSrcweir 66*cdf0e10cSrcweirmy $proto = getprotobyname('tcp'); 67*cdf0e10cSrcweirmy $paddr; 68*cdf0e10cSrcweirmy $host = hostname(); 69*cdf0e10cSrcweirmy $current_server = ''; 70*cdf0e10cSrcweirmy $got_job = 0; 71*cdf0e10cSrcweirmy %job_temp_files = (); 72*cdf0e10cSrcweirmy %environments = (); # hash containing all environments 73*cdf0e10cSrcweirmy $env_alias; 74*cdf0e10cSrcweirmy %platform_rejects = (); # hash containing paddr of server, that replied "Wrong platform" 75*cdf0e10cSrcweir 76*cdf0e10cSrcweirmy $child = 0; 77*cdf0e10cSrcweirif ($processes_to_run > 1) { 78*cdf0e10cSrcweir my $started_processes = 1; 79*cdf0e10cSrcweir if ($^O eq 'MSWin32') { 80*cdf0e10cSrcweir my $process_obj = undef; 81*cdf0e10cSrcweir my $child_args = "perl $0"; 82*cdf0e10cSrcweir foreach (@ARGV_COPY) { 83*cdf0e10cSrcweir /^-P(\d+)$/ and next; 84*cdf0e10cSrcweir /^-P$/ and shift @ARGV_COPY and next; 85*cdf0e10cSrcweir $child_args .= " $_"; 86*cdf0e10cSrcweir }; 87*cdf0e10cSrcweir do { 88*cdf0e10cSrcweir my $rc = Win32::Process::Create($process_obj, $^X, 89*cdf0e10cSrcweir $child_args, 90*cdf0e10cSrcweir 0, 0, #NORMAL_PRIORITY_CLASS, 91*cdf0e10cSrcweir "."); 92*cdf0e10cSrcweir print_error("Cannot start child process") if (!$rc); 93*cdf0e10cSrcweir $started_processes++; 94*cdf0e10cSrcweir } while ($started_processes < $processes_to_run); 95*cdf0e10cSrcweir } else { 96*cdf0e10cSrcweir my $pid; 97*cdf0e10cSrcweir do { 98*cdf0e10cSrcweir if ($pid = fork) { # parent 99*cdf0e10cSrcweir $started_processes++; 100*cdf0e10cSrcweir print $started_processes . "\n"; 101*cdf0e10cSrcweir } elsif (defined $pid) { # child 102*cdf0e10cSrcweir $child++; 103*cdf0e10cSrcweir }; 104*cdf0e10cSrcweir } while (($started_processes < $processes_to_run) && !$child); 105*cdf0e10cSrcweir }; 106*cdf0e10cSrcweir}; 107*cdf0e10cSrcweir 108*cdf0e10cSrcweirrun_client(); 109*cdf0e10cSrcweir### end of main procedure ### 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir######################### 112*cdf0e10cSrcweir# # 113*cdf0e10cSrcweir# Procedures # 114*cdf0e10cSrcweir# # 115*cdf0e10cSrcweir######################### 116*cdf0e10cSrcweirsub handle_temp_files { 117*cdf0e10cSrcweir print STDERR "Got signal - clearing up...\n"; 118*cdf0e10cSrcweir foreach (keys %job_temp_files) { 119*cdf0e10cSrcweir if ($job_temp_files{$_}) { 120*cdf0e10cSrcweir rename($_, $job_temp_files{$_}) or system("mv", $_, $job_temp_files{$_}); 121*cdf0e10cSrcweir print STDERR "Could not rename $_ to $job_temp_files{$_}\n" if (-e $_); 122*cdf0e10cSrcweir } else { 123*cdf0e10cSrcweir unlink $_ or system("rm -rf $_"); 124*cdf0e10cSrcweir print STDERR "Could not remove $_\n" if (-e $_); 125*cdf0e10cSrcweir }; 126*cdf0e10cSrcweir }; 127*cdf0e10cSrcweir exit($?); 128*cdf0e10cSrcweir}; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweirsub run_client { 131*cdf0e10cSrcweir# initialize host and port 132*cdf0e10cSrcweir if (!scalar keys %hosts_ports) { 133*cdf0e10cSrcweir $hosts_ports{localhost} = $default_port; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir print "Started client with PID $$, hostname $host\n"; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir my $message = ''; 139*cdf0e10cSrcweir my $current_port = ''; 140*cdf0e10cSrcweir my %active_servers = (); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir do { 143*cdf0e10cSrcweir $got_job = 0; 144*cdf0e10cSrcweir foreach $current_server (keys %hosts_ports) { 145*cdf0e10cSrcweir foreach $current_port (keys %{$hosts_ports{$current_server}}) { 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir #before each "inactive" server/port connect - connect to each "active" server/port 148*cdf0e10cSrcweir next if (defined ${$active_servers{$current_server}}{$current_port}); 149*cdf0e10cSrcweir # "active" cycle 150*cdf0e10cSrcweir foreach my $active_server (keys %active_servers) { 151*cdf0e10cSrcweir foreach my $active_port (keys %{$active_servers{$active_server}}) { 152*cdf0e10cSrcweir# print "Active: $active_server:$active_port\n"; 153*cdf0e10cSrcweir my $iaddr = inet_aton($active_server); 154*cdf0e10cSrcweir $paddr = sockaddr_in($active_port, $iaddr); 155*cdf0e10cSrcweir do { 156*cdf0e10cSrcweir my $server_is_active = 0; 157*cdf0e10cSrcweir $message = request_job($message, $active_server, $active_port); 158*cdf0e10cSrcweir $server_is_active++ if ($message); 159*cdf0e10cSrcweir if (!$server_is_active) { 160*cdf0e10cSrcweir delete ${$active_servers{$active_server}}{$active_port}; 161*cdf0e10cSrcweir # throw away obsolete environments 162*cdf0e10cSrcweir foreach (keys %environments) { 163*cdf0e10cSrcweir /^\d+@/; 164*cdf0e10cSrcweir if ($' eq "$active_server:$active_port") { 165*cdf0e10cSrcweir delete $environments{$_}; 166*cdf0e10cSrcweir }; 167*cdf0e10cSrcweir }; 168*cdf0e10cSrcweir }; 169*cdf0e10cSrcweir $message = '' if ($message eq 'No job'); 170*cdf0e10cSrcweir } while ($message); 171*cdf0e10cSrcweir }; 172*cdf0e10cSrcweir }; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir # "inactive" cycle 175*cdf0e10cSrcweir# print "Inactive: $current_server:$current_port\n"; 176*cdf0e10cSrcweir my $iaddr = inet_aton($current_server); 177*cdf0e10cSrcweir $paddr = sockaddr_in($current_port, $iaddr); 178*cdf0e10cSrcweir do { 179*cdf0e10cSrcweir $message = request_job($message, $current_server, $current_port); 180*cdf0e10cSrcweir if ($message) { 181*cdf0e10cSrcweir if (!defined $active_servers{$current_server}) { 182*cdf0e10cSrcweir my %ports; 183*cdf0e10cSrcweir $active_servers{$current_server} = \%ports; 184*cdf0e10cSrcweir }; 185*cdf0e10cSrcweir ${$active_servers{$current_server}}{$current_port}++; 186*cdf0e10cSrcweir }; 187*cdf0e10cSrcweir $message = '' if ($message eq 'No job'); 188*cdf0e10cSrcweir } while ($message); 189*cdf0e10cSrcweir }; 190*cdf0e10cSrcweir }; 191*cdf0e10cSrcweir sleep 5 if (!$got_job); 192*cdf0e10cSrcweir read_server_list(); 193*cdf0e10cSrcweir } while(1); 194*cdf0e10cSrcweir}; 195*cdf0e10cSrcweir 196*cdf0e10cSrcweirsub usage { 197*cdf0e10cSrcweir my $error = shift; 198*cdf0e10cSrcweir print STDERR "\nbuild_client\n"; 199*cdf0e10cSrcweir print STDERR "Syntax: build_client [-PN] host1[:port1:...:portN] [host2[:port1:...:portN] ... hostN[:port1:...:portN]]|\@server_list_file\n"; 200*cdf0e10cSrcweir print STDERR " -P - start multiprocessing build, with number of processes passed\n"; 201*cdf0e10cSrcweir print STDERR "Example1: build_client myserver1 myserver2:7891:7892\n"; 202*cdf0e10cSrcweir print STDERR " the client will be asking for jobs on myserver1's default ports (7890-7894)\n"; 203*cdf0e10cSrcweir print STDERR " and on myserver2's ports 7891 and 7892\n"; 204*cdf0e10cSrcweir print STDERR "Example2: build_client -P2 myserver1:7990 myserver2\n"; 205*cdf0e10cSrcweir print STDERR " start 2 clients which will be asking for jobs myserver1's port 7990\n"; 206*cdf0e10cSrcweir print STDERR " and myserver2's default ports (7890-7894)\n"; 207*cdf0e10cSrcweir exit ($error); 208*cdf0e10cSrcweir}; 209*cdf0e10cSrcweir 210*cdf0e10cSrcweirsub get_options { 211*cdf0e10cSrcweir my $arg; 212*cdf0e10cSrcweir usage(1) if (!scalar @ARGV); 213*cdf0e10cSrcweir while ($arg = shift @ARGV) { 214*cdf0e10cSrcweir usage(0) if /^--help$/; 215*cdf0e10cSrcweir usage(0) if /^-h$/; 216*cdf0e10cSrcweir $arg =~ /^-P(\d+)$/ and $processes_to_run = $1 and next; 217*cdf0e10cSrcweir $arg =~ /^-P$/ and $processes_to_run = shift @ARGV and next; 218*cdf0e10cSrcweir $arg =~ /^@(\S+)$/ and $server_list_file = $1 and next; 219*cdf0e10cSrcweir store_server($arg); 220*cdf0e10cSrcweir }; 221*cdf0e10cSrcweir if (($processes_to_run > 1) && (!$enable_multiprocessing)) { 222*cdf0e10cSrcweir print_error("Cannot load Win32::Process module for multiple client start"); 223*cdf0e10cSrcweir }; 224*cdf0e10cSrcweir if ($server_list_file) { 225*cdf0e10cSrcweir print_error("$server_list_file is not a regular file!!") if (!-f $server_list_file); 226*cdf0e10cSrcweir read_server_list(); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir print_error("No server info") if (!scalar %hosts_ports); 229*cdf0e10cSrcweir}; 230*cdf0e10cSrcweir 231*cdf0e10cSrcweirsub store_server { 232*cdf0e10cSrcweir my $server_string = shift; 233*cdf0e10cSrcweir my @server_params = (); 234*cdf0e10cSrcweir @server_params = split (/:/, $server_string); 235*cdf0e10cSrcweir my $host = shift @server_params; 236*cdf0e10cSrcweir my @names = gethostbyname($host); 237*cdf0e10cSrcweir my $host_full_name = $names[0]; 238*cdf0e10cSrcweir my %ports = (); 239*cdf0e10cSrcweir if (defined $hosts_ports{$host_full_name}) { 240*cdf0e10cSrcweir %ports = %{$hosts_ports{$host_full_name}}; 241*cdf0e10cSrcweir }; 242*cdf0e10cSrcweir # To do: implement keys in form server:port -> priority 243*cdf0e10cSrcweir if (defined $hosts_ports{$host_full_name}) { 244*cdf0e10cSrcweir if (!$server_list_time_stamp) { 245*cdf0e10cSrcweir print "The $host with ip address " . inet_ntoa(inet_aton($host)) . " is at least two times in the server list\n"; 246*cdf0e10cSrcweir }; 247*cdf0e10cSrcweir } else { 248*cdf0e10cSrcweir print "Added server $host as $host_full_name\n"; 249*cdf0e10cSrcweir }; 250*cdf0e10cSrcweir if (scalar @server_params) { 251*cdf0e10cSrcweir $ports{$_}++ foreach (@server_params); 252*cdf0e10cSrcweir } else { 253*cdf0e10cSrcweir $ports{$_}++ foreach ($default_port .. $default_port + 4); 254*cdf0e10cSrcweir }; 255*cdf0e10cSrcweir $hosts_ports{$host_full_name} = \%ports; 256*cdf0e10cSrcweir}; 257*cdf0e10cSrcweir 258*cdf0e10cSrcweirsub read_server_list { 259*cdf0e10cSrcweir open(SERVER_LIST, "<$server_list_file") or return; 260*cdf0e10cSrcweir my $current_time_stamp = (stat($server_list_file))[9]; 261*cdf0e10cSrcweir return if ($server_list_time_stamp >= $current_time_stamp); 262*cdf0e10cSrcweir my @server_array = (); 263*cdf0e10cSrcweir foreach my $file_string(<SERVER_LIST>) { 264*cdf0e10cSrcweir while ($file_string =~ /(\S+)/) { 265*cdf0e10cSrcweir $file_string = $'; 266*cdf0e10cSrcweir store_server($1); 267*cdf0e10cSrcweir }; 268*cdf0e10cSrcweir }; 269*cdf0e10cSrcweir close SERVER_LIST; 270*cdf0e10cSrcweir $server_list_time_stamp = $current_time_stamp; 271*cdf0e10cSrcweir}; 272*cdf0e10cSrcweir 273*cdf0e10cSrcweirsub request_job { 274*cdf0e10cSrcweir my ($message, $current_server, $current_port) = @_; 275*cdf0e10cSrcweir $message = "platform=$ENV_BACKUP{OUTPATH} pid=$$ osname=$^O" if (!$message); 276*cdf0e10cSrcweir # create the socket, connect to the port 277*cdf0e10cSrcweir socket(SOCKET, PF_INET, SOCK_STREAM, $proto) or die "socket: $!"; 278*cdf0e10cSrcweir connect(SOCKET, $paddr) or return '';#die "connect: $!"; 279*cdf0e10cSrcweir my $error_code = 1; 280*cdf0e10cSrcweir $message .= "\n"; 281*cdf0e10cSrcweir syswrite SOCKET, $message, length $message; 282*cdf0e10cSrcweir while (my $line = <SOCKET>) { 283*cdf0e10cSrcweir chomp $line; 284*cdf0e10cSrcweir if ($line eq 'No job') { 285*cdf0e10cSrcweir close SOCKET or die "close: $!"; 286*cdf0e10cSrcweir return $line; 287*cdf0e10cSrcweir }; 288*cdf0e10cSrcweir if ($line eq "Wrong platform") { 289*cdf0e10cSrcweir if (!defined $platform_rejects{$paddr}) { 290*cdf0e10cSrcweir $platform_rejects{$paddr}++; 291*cdf0e10cSrcweir print STDERR $line . "\n"; 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir close SOCKET or die "close: $!"; 294*cdf0e10cSrcweir delete $hosts_ports{$current_server}; 295*cdf0e10cSrcweir return ''; 296*cdf0e10cSrcweir } elsif (defined $platform_rejects{$paddr}) { 297*cdf0e10cSrcweir delete $platform_rejects{$paddr}; 298*cdf0e10cSrcweir }; 299*cdf0e10cSrcweir $got_job++; 300*cdf0e10cSrcweir $error_code = do_job($line . " server=$current_server port=$current_port"); 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir close SOCKET or die "close: $!"; 303*cdf0e10cSrcweir return("result=$error_code pid=$$"); 304*cdf0e10cSrcweir} 305*cdf0e10cSrcweir 306*cdf0e10cSrcweirsub do_job { 307*cdf0e10cSrcweir my @job_parameters = split(/ /, shift); 308*cdf0e10cSrcweir my %job_hash = (); 309*cdf0e10cSrcweir my $last_param; 310*cdf0e10cSrcweir my $error_code; 311*cdf0e10cSrcweir print "Client $$@" . "$host\n"; 312*cdf0e10cSrcweir foreach (@job_parameters) { 313*cdf0e10cSrcweir if (/(=)/) { 314*cdf0e10cSrcweir $job_hash{$`} = $'; 315*cdf0e10cSrcweir $last_param = $`; 316*cdf0e10cSrcweir } else { 317*cdf0e10cSrcweir $job_hash{$last_param} .= " $_"; 318*cdf0e10cSrcweir }; 319*cdf0e10cSrcweir }; 320*cdf0e10cSrcweir $env_alias = $job_hash{server_pid} . '@' . $job_hash{server} . ':' . $job_hash{port}; 321*cdf0e10cSrcweir my $result = "1"; # default value 322*cdf0e10cSrcweir my $cmd_file = File::Temp::tmpnam($ENV_BACKUP{TMP}); 323*cdf0e10cSrcweir my $tmp_log_file = File::Temp::tmpnam($ENV_BACKUP{TMP}); 324*cdf0e10cSrcweir $job_temp_files{$tmp_log_file} = $job_hash{log}; 325*cdf0e10cSrcweir my $setenv_string = ''; 326*cdf0e10cSrcweir if (defined $job_hash{setenv_string}) { 327*cdf0e10cSrcweir # use configuration string from server 328*cdf0e10cSrcweir $setenv_string .= $job_hash{setenv_string}; 329*cdf0e10cSrcweir print "Environment: $setenv_string\n"; 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir my $directory = $job_hash{job_dir}; 332*cdf0e10cSrcweir open (COMMAND_FILE, ">$cmd_file"); 333*cdf0e10cSrcweir print COMMAND_FILE "$setenv_string\n"; 334*cdf0e10cSrcweir if (!defined $job_hash{job_dir}) { 335*cdf0e10cSrcweir close COMMAND_FILE; 336*cdf0e10cSrcweir print "No job_dir, cmd file: $cmd_file\n"; 337*cdf0e10cSrcweir foreach (keys %job_hash) { 338*cdf0e10cSrcweir print "key: $_ $job_hash{$_}\n"; 339*cdf0e10cSrcweir }; 340*cdf0e10cSrcweir exit (1); 341*cdf0e10cSrcweir }; 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir print COMMAND_FILE "pushd $job_hash{job_dir} && "; 344*cdf0e10cSrcweir print COMMAND_FILE $job_hash{job} ." >& $tmp_log_file\n"; 345*cdf0e10cSrcweir print COMMAND_FILE "exit \$?\n"; 346*cdf0e10cSrcweir close COMMAND_FILE; 347*cdf0e10cSrcweir $job_temp_files{$cmd_file} = 0; 348*cdf0e10cSrcweir $job_temp_files{$tmp_log_file} = $job_hash{log}; 349*cdf0e10cSrcweir $error_code = system($ENV{SHELL}, $cmd_file); 350*cdf0e10cSrcweir unlink $cmd_file or system("rm -rf $cmd_file"); 351*cdf0e10cSrcweir delete $job_temp_files{$cmd_file}; 352*cdf0e10cSrcweir } else { 353*cdf0e10cSrcweir # generate setsolar string 354*cdf0e10cSrcweir if (!defined $environments{$env_alias}) { 355*cdf0e10cSrcweir $error_code = get_setsolar_environment(\%job_hash); 356*cdf0e10cSrcweir return($error_code) if ($error_code); 357*cdf0e10cSrcweir }; 358*cdf0e10cSrcweir my $solar_vars = $environments{$env_alias}; 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir delete $ENV{$_} foreach (keys %ENV); 361*cdf0e10cSrcweir $ENV{$_} = $$solar_vars{$_} foreach (keys %$solar_vars); 362*cdf0e10cSrcweir print 'Workspace: '; 363*cdf0e10cSrcweir if (defined $ENV{CWS_WORK_STAMP}) { 364*cdf0e10cSrcweir print $ENV{CWS_WORK_STAMP}; 365*cdf0e10cSrcweir } else { 366*cdf0e10cSrcweir print $ENV{SOLARSRC}; 367*cdf0e10cSrcweir }; 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir print "\nplatform: $ENV{INPATH} $^O"; 370*cdf0e10cSrcweir print "\ndir: $job_hash{job_dir}\n"; 371*cdf0e10cSrcweir print "job: $job_hash{job}\n"; 372*cdf0e10cSrcweir chdir $job_hash{job_dir}; 373*cdf0e10cSrcweir getcwd(); 374*cdf0e10cSrcweir my $job_string = $job_hash{job} . ' > ' . $tmp_log_file . ' 2>&1'; 375*cdf0e10cSrcweir $error_code = system($job_string); 376*cdf0e10cSrcweir# rename($tmp_log_file, $job_hash{log}) or system("mv", $tmp_log_file, $job_hash{log}); 377*cdf0e10cSrcweir# delete $job_temp_files{$tmp_log_file};# = $job_hash{log}; 378*cdf0e10cSrcweir }; 379*cdf0e10cSrcweir rename($tmp_log_file, $job_hash{log}) or system("mv", $tmp_log_file, $job_hash{log}); 380*cdf0e10cSrcweir delete $job_temp_files{$tmp_log_file}; 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir if ($error_code) { 383*cdf0e10cSrcweir print "Error code = $error_code\n\n"; 384*cdf0e10cSrcweir } else { 385*cdf0e10cSrcweir print "Success!!\n\n"; 386*cdf0e10cSrcweir }; 387*cdf0e10cSrcweir return $error_code; 388*cdf0e10cSrcweir}; 389*cdf0e10cSrcweir 390*cdf0e10cSrcweirsub get_setsolar_environment { 391*cdf0e10cSrcweir my $job_hash = shift; 392*cdf0e10cSrcweir my $server_pid = $$job_hash{server_pid}; 393*cdf0e10cSrcweir my $setsolar_string = $$job_hash{setsolar_cmd}; 394*cdf0e10cSrcweir # Prepare the string for the client 395*cdf0e10cSrcweir $setsolar_string =~ s/\s-file\s\S+//g; 396*cdf0e10cSrcweir my $error_code = 0; 397*cdf0e10cSrcweir my $cmd_file = File::Temp::tmpnam($ENV_BACKUP{TMP}); 398*cdf0e10cSrcweir my $tmp_log_file = File::Temp::tmpnam($ENV_BACKUP{TMP}); 399*cdf0e10cSrcweir if (defined $$job_hash{updater}) { 400*cdf0e10cSrcweir $ENV{UPDATER} = $$job_hash{updater}; 401*cdf0e10cSrcweir } else { 402*cdf0e10cSrcweir undef $ENV{UPDATER} if (defined $ENV{UPDATER}); 403*cdf0e10cSrcweir }; 404*cdf0e10cSrcweir if (defined $$job_hash{source_root}) { 405*cdf0e10cSrcweir $ENV{SOURCE_ROOT} = $$job_hash{source_root}; 406*cdf0e10cSrcweir } else { 407*cdf0e10cSrcweir undef $ENV{SOURCE_ROOT} if (defined $ENV{SOURCE_ROOT}); 408*cdf0e10cSrcweir }; 409*cdf0e10cSrcweir $error_code = system("$setsolar_string -file $cmd_file"); 410*cdf0e10cSrcweir store_env_hash($cmd_file); 411*cdf0e10cSrcweir return $error_code; 412*cdf0e10cSrcweir}; 413*cdf0e10cSrcweir 414*cdf0e10cSrcweirsub print_error { 415*cdf0e10cSrcweir my $message = shift; 416*cdf0e10cSrcweir print STDERR "\nERROR: $message\n"; 417*cdf0e10cSrcweir exit(1); 418*cdf0e10cSrcweir}; 419*cdf0e10cSrcweirsub store_env_hash { 420*cdf0e10cSrcweir my $ss_setenv_file = shift;#($$job_hash{server_pid}.$$job_hash{setsolar_cmd}, $cmd_file); 421*cdf0e10cSrcweir my %solar_vars = (); 422*cdf0e10cSrcweir my $cmd_file = File::Temp::tmpnam($ENV_BACKUP{TMP}); 423*cdf0e10cSrcweir my $env_vars_file = File::Temp::tmpnam($ENV_BACKUP{TMP}); 424*cdf0e10cSrcweir print "$cmd_file $env_vars_file\n"; 425*cdf0e10cSrcweir #get all env variables in $env_vars_file 426*cdf0e10cSrcweir open (COMMAND_FILE, ">$cmd_file"); 427*cdf0e10cSrcweir print COMMAND_FILE "source $ss_setenv_file\n"; 428*cdf0e10cSrcweir print COMMAND_FILE "env > $env_vars_file\n"; 429*cdf0e10cSrcweir close COMMAND_FILE; 430*cdf0e10cSrcweir system($ENV{SHELL}, $cmd_file); 431*cdf0e10cSrcweir print_error($?) if ($?); 432*cdf0e10cSrcweir unlink $cmd_file or system("rm -rf $cmd_file"); 433*cdf0e10cSrcweir unlink $ss_setenv_file or system("rm -rf $ss_setenv_file"); 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir open SOLARTABLE, "<$env_vars_file" or die "can�t open solarfile $env_vars_file"; 436*cdf0e10cSrcweir while(<SOLARTABLE>) { 437*cdf0e10cSrcweir chomp; 438*cdf0e10cSrcweir s/\r\n//o; 439*cdf0e10cSrcweir /(=)/; 440*cdf0e10cSrcweir $solar_vars{$`} = $'; 441*cdf0e10cSrcweir }; 442*cdf0e10cSrcweir close SOLARTABLE; 443*cdf0e10cSrcweir unlink $env_vars_file or system("rm -rf $env_vars_file"); 444*cdf0e10cSrcweir $environments{$env_alias} = \%solar_vars; 445*cdf0e10cSrcweir}; 446