Skip to content

Commit 63f5049

Browse files
committed
added a check so that the END block doesn't execute for child processes.
1 parent 257c16d commit 63f5049

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

trunk/nuv_utils.pm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ package nuv_utils;
44
our @ISA = qw/ Exporter /;
55
our @EXPORT = qw/ generate_showtime find_program nuv_info num_cpus fork_command shell_escape mysql_escape Quit /;
66

7+
# This is used to tell child processes apart from the parent, so that cleanup routines do NOT get run by children.
8+
our $is_child = 0;
9+
710
# Returns a nicely-formatted timestamp from a specified time
811
sub generate_showtime {
912
$showtime = '';
@@ -194,6 +197,7 @@ package nuv_utils;
194197
}
195198
# $pid defined means that this is now the forked child
196199
elsif (defined $pid) {
200+
$is_child = 1;
197201
system($command);
198202
# Don't forget to exit, or we'll keep going back into places that the child shouldn't play
199203
exit(0);
@@ -221,9 +225,9 @@ package nuv_utils;
221225
exit;
222226
}
223227

224-
# Allow the functions to clean up after themselves - and make sure that they can
228+
# Allow the functions to clean up after themselves - and make sure that they can, but not if they are marked as child processes
225229
END {
226-
if (@main::Functions) {
230+
if (!$is_child && @main::Functions) {
227231
foreach $function (@main::Functions) {
228232
$function->cleanup;
229233
}

0 commit comments

Comments
 (0)