1*9780544fSAndrew Rist#**************************************************************
2*9780544fSAndrew Rist#
3*9780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
4*9780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
5*9780544fSAndrew Rist#  distributed with this work for additional information
6*9780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
7*9780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
8*9780544fSAndrew Rist#  "License"); you may not use this file except in compliance
9*9780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
10*9780544fSAndrew Rist#
11*9780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
12*9780544fSAndrew Rist#
13*9780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
14*9780544fSAndrew Rist#  software distributed under the License is distributed on an
15*9780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
17*9780544fSAndrew Rist#  specific language governing permissions and limitations
18*9780544fSAndrew Rist#  under the License.
19*9780544fSAndrew Rist#
20*9780544fSAndrew Rist#**************************************************************
21*9780544fSAndrew Rist
22*9780544fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweirpackage installer::exiter;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse installer::files;
27cdf0e10cSrcweiruse installer::globals;
28cdf0e10cSrcweiruse installer::logger;
29cdf0e10cSrcweiruse installer::systemactions;
30cdf0e10cSrcweiruse installer::worker;
31cdf0e10cSrcweir
32cdf0e10cSrcweir############################################
33cdf0e10cSrcweir# Exiting the program with an error
34cdf0e10cSrcweir# This function is used instead of "die"
35cdf0e10cSrcweir############################################
36cdf0e10cSrcweir
37cdf0e10cSrcweirsub exit_program
38cdf0e10cSrcweir{
39cdf0e10cSrcweir	my ($message, $function) = @_;
40cdf0e10cSrcweir
41cdf0e10cSrcweir	# If an installation set is currently created, the directory name is saved in $installer::globals::saveinstalldir
42cdf0e10cSrcweir	# If this directory name matches with "_inprogress", it has to be renamed into "_witherror"
43cdf0e10cSrcweir
44cdf0e10cSrcweir	if ( $installer::globals::saveinstalldir =~ /_inprogress/ ) { installer::systemactions::rename_string_in_directory($installer::globals::saveinstalldir, "_inprogress", "_witherror");	}
45cdf0e10cSrcweir
46cdf0e10cSrcweir	# Cleaning files from pool tooling
47cdf0e10cSrcweir	if ( $installer::globals::processhaspoolcheckfile ) { unlink $installer::globals::poolcheckfilename; }
48cdf0e10cSrcweir	if ( $installer::globals::processhaspoollockfile ) { unlink $installer::globals::poollockfilename; }
49cdf0e10cSrcweir
50cdf0e10cSrcweir	installer::worker::clean_output_tree();	# removing directories created in the output tree
51cdf0e10cSrcweir
52cdf0e10cSrcweir	# If @installer::globals::logfileinfo is not empty, it can be used.
53cdf0e10cSrcweir	# Otherwise the content of @installer::globals::globallogfileinfo has to be used.
54cdf0e10cSrcweir
55cdf0e10cSrcweir	my $infoline;
56cdf0e10cSrcweir
57cdf0e10cSrcweir	$installer::globals::logfilename = $installer::globals::exitlog . $installer::globals::logfilename;
58cdf0e10cSrcweir
59cdf0e10cSrcweir	if ( ! $installer::globals::globalinfo_copied ) { installer::logger::copy_globalinfo_into_logfile(); }
60cdf0e10cSrcweir
61cdf0e10cSrcweir	if ( $#installer::globals::logfileinfo > -1 )
62cdf0e10cSrcweir	{
63cdf0e10cSrcweir		$infoline = "\n***************************************************************\n";
64cdf0e10cSrcweir		push(@installer::globals::logfileinfo, $infoline);
65cdf0e10cSrcweir
66cdf0e10cSrcweir		$infoline = "$message\n";
67cdf0e10cSrcweir		push(@installer::globals::logfileinfo, $infoline);
68cdf0e10cSrcweir
69cdf0e10cSrcweir		$infoline = "in function: $function\n";
70cdf0e10cSrcweir		push(@installer::globals::logfileinfo, $infoline);
71cdf0e10cSrcweir
72cdf0e10cSrcweir		$infoline = "***************************************************************\n";
73cdf0e10cSrcweir		push(@installer::globals::logfileinfo, $infoline);
74cdf0e10cSrcweir
75cdf0e10cSrcweir		installer::files::save_file($installer::globals::logfilename ,\@installer::globals::logfileinfo);
76cdf0e10cSrcweir	}
77cdf0e10cSrcweir	else
78cdf0e10cSrcweir	{
79cdf0e10cSrcweir		$infoline = "\n***************************************************************\n";
80cdf0e10cSrcweir		push(@installer::globals::globallogfileinfo, $infoline);
81cdf0e10cSrcweir
82cdf0e10cSrcweir		$infoline = "$message\n";
83cdf0e10cSrcweir		push(@installer::globals::globallogfileinfo, $infoline);
84cdf0e10cSrcweir
85cdf0e10cSrcweir		$infoline = "in function: $function\n";
86cdf0e10cSrcweir		push(@installer::globals::globallogfileinfo, $infoline);
87cdf0e10cSrcweir
88cdf0e10cSrcweir		$infoline = "***************************************************************\n";
89cdf0e10cSrcweir		push(@installer::globals::globallogfileinfo, $infoline);
90cdf0e10cSrcweir
91cdf0e10cSrcweir		installer::files::save_file($installer::globals::logfilename ,\@installer::globals::globallogfileinfo);
92cdf0e10cSrcweir	}
93cdf0e10cSrcweir	installer::logger::print_error("$message\nin function: $function");
94cdf0e10cSrcweir	installer::logger::print_error("Saved logfile: $installer::globals::logfilename\n");
95cdf0e10cSrcweir
96cdf0e10cSrcweir	# Saving the debug info
97cdf0e10cSrcweir
98cdf0e10cSrcweir	if ( $installer::globals::debug ) { installer::logger::savedebug($installer::globals::exitlog);	}
99cdf0e10cSrcweir
100cdf0e10cSrcweir	installer::logger::stoptime();
101cdf0e10cSrcweir
102cdf0e10cSrcweir    if (defined($installer::globals::exithandler)) {
103cdf0e10cSrcweir        &$installer::globals::exithandler;
104cdf0e10cSrcweir    }
105cdf0e10cSrcweir
106cdf0e10cSrcweir	exit(-1);
107cdf0e10cSrcweir}
108cdf0e10cSrcweir
109cdf0e10cSrcweir1;
110