Skip to content

Commit eb22e10

Browse files
committed
add some signal handling, and shutdown cleanup to do our best to avoid zombie processes
1 parent 520a7ce commit eb22e10

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

trunk/nuv_export/shared_utils.pm

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,10 @@ package nuv_export::shared_utils;
4343
our $DEBUG;
4444
our $NICE;
4545

46-
# Remove any temporary files, and make sure child processes are cleaned up.
46+
# Make sure cleanup happens
47+
$SIG{'INT'} = \&sig_end;
4748
END {
48-
if (!$is_child) {
49-
# Clean up temp files/directories
50-
wipe_tmpfiles();
51-
# Make sure any child processes also go away
52-
if (%children) {
53-
foreach my $child (keys %children) {
54-
kill('INT', $child);
55-
}
56-
usleep(100000) while (wait > 0);
57-
}
58-
}
49+
&shutdown_cleanup;
5950
}
6051

6152
# Set up the terminal commands we need to send a clear-screen character
@@ -84,6 +75,28 @@ package nuv_export::shared_utils;
8475
$NICE = find_program('nice');
8576
die "You need nice in order to use nuvexport.\n\n" unless ($NICE);
8677

78+
# Exit from a signal
79+
sub sig_end {
80+
exit 0;
81+
}
82+
83+
# Clean up child processes, etc
84+
sub shutdown_cleanup {
85+
# Nothing to do for forked versions
86+
return if ($is_child);
87+
# Clean up temp files/directories
88+
print "\nCleaning up temp files.\n";
89+
wipe_tmpfiles();
90+
# Make sure any child processes also go away
91+
if (%children) {
92+
print "Cleaning up child processes.\n";
93+
foreach my $child (keys %children) {
94+
kill('INT', $child);
95+
}
96+
usleep(100000) while (wait > 0);
97+
}
98+
}
99+
87100
# Clear the screen
88101
sub clear {
89102
print $DEBUG ? "\n" : $terminal->Tputs('cl');

0 commit comments

Comments
 (0)