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