Skip to content

Commit 3d7146a

Browse files
committed
safe exit for interactive scripts
1 parent ae6e05e commit 3d7146a

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
archive/
22
build-peb-*/
3-
logs/
43
perl/bin
54
perl/lib
6-
qt/
5+
resources/logs/
76

87
*.autosave
98
Makefile

resources/app/perl/interactive.pl

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
# but first print a confirmation for a normal exit.
5050
if ($stdin =~ "_close_") {
5151
print "_closed_";
52-
exit();
52+
shutdown_procedure();
5353
}
5454

5555
# Read input text from STDIN:
@@ -76,22 +76,41 @@
7676
interval => 0.5,
7777
cb => sub {
7878
if ($mode =~ "unix-epoch") {
79+
my $output_string;
80+
7981
if (length($input_text) == 0) {
80-
print "Seconds from the Unix epoch: ".time or die;
82+
$output_string = "Seconds from the Unix epoch: ".time;
8183
} else {
82-
print "Seconds from the Unix epoch: ".time."<br>Last input: ".$input_text or die;
84+
$output_string =
85+
"Seconds from the Unix epoch: ".time."<br>Last input: ".$input_text;
8386
}
87+
88+
print $output_string or shutdown_procedure();
8489
}
8590

8691
if ($mode =~ "local-time") {
92+
my $output_string;
8793
my $formatted_time = strftime('%d %B %Y %H:%M:%S', localtime);
94+
8895
if (length($input_text) == 0) {
89-
print "Local date and time: ".$formatted_time or die;
96+
$output_string = "Local date and time: ".$formatted_time;
9097
} else {
91-
print "Local date and time: ".$formatted_time."<br>Last input: ".$input_text or die;
98+
$output_string =
99+
"Local date and time: ".$formatted_time."<br>Last input: ".$input_text;
92100
}
101+
102+
print $output_string or shutdown_procedure();
93103
}
94104
},
95105
);
96106

97107
$event_loop->recv;
108+
109+
# Using a function one can implement a much complex shutdown procedure,
110+
# called when a shutdown command is received from PEB or
111+
# when PEB unexpectedly crashes and script loses its STDOUT stream.
112+
# This function must not be named 'shutdown' -
113+
# this is a reserved name for a Perl prototype function!
114+
sub shutdown_procedure {
115+
exit();
116+
}

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ int main(int argc, char **argv)
314314
mainWindow.setCentralWidget(mainWindow.webViewWidget);
315315

316316
// ==============================
317-
// Entry point:
317+
// Entry file:
318318
// ==============================
319319
bool startFileFound = false;
320320

@@ -326,7 +326,7 @@ int main(int argc, char **argv)
326326
QFile startPageFile(startPageFilePath);
327327
QFile localServerSettingsFile(localServerSettingsFilePath);
328328

329-
// Static start page:
329+
// Local file:
330330
if (startPageFile.exists()) {
331331
startFileFound = true;
332332

0 commit comments

Comments
 (0)