public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH installer 0/2] Close app gracefully
@ 2023-06-16 10:57 Maximiliano Sandoval
  2023-06-16 10:57 ` [pve-devel] [PATCH installer 1/2] exit process gracefully Maximiliano Sandoval
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Maximiliano Sandoval @ 2023-06-16 10:57 UTC (permalink / raw)
  To: pve-devel

We make sure that the Glib main loop is closed before exiting the application.

Ideally all of this, among other things, is handled automatically when using
Gtk3::ApplicationWindow and Glib::IO::Application->run(), but that needs
https://metacpan.org/pod/Glib::IO to be packaged for debian.

As a side note, gtk_main() and related functions were removed for GTK 4.

Maximiliano Sandoval (2):
  exit process gracefully
  stop main loop when closing the main window

 proxinstall | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

-- 
2.39.2





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH installer 1/2] exit process gracefully
  2023-06-16 10:57 [pve-devel] [PATCH installer 0/2] Close app gracefully Maximiliano Sandoval
@ 2023-06-16 10:57 ` Maximiliano Sandoval
  2023-06-16 10:57 ` [pve-devel] [PATCH installer 2/2] stop main loop when closing the main window Maximiliano Sandoval
  2023-06-19  7:36 ` [pve-devel] applied: [PATCH installer 0/2] Close app gracefully Thomas Lamprecht
  2 siblings, 0 replies; 4+ messages in thread
From: Maximiliano Sandoval @ 2023-06-16 10:57 UTC (permalink / raw)
  To: pve-devel

We make sure that all exit calls quit the Glib main loop and child
processes.

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
---
 proxinstall | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/proxinstall b/proxinstall
index 2f63679..701133b 100755
--- a/proxinstall
+++ b/proxinstall
@@ -235,6 +235,18 @@ compatibility_level = 2
 _EOD
 
 
+sub app_quit {
+    my ($exit_code) = @_;
+
+    Gtk3->main_quit() if Gtk3->main_level() > 0;
+
+    # reap left over zombie processes
+    while ((my $child = waitpid(-1, POSIX::WNOHANG)) > 0) {
+	print "reaped child $child\n";
+    }
+    exit($exit_code);
+}
+
 sub detect_country {
     print "trying to detect country...\n";
     my $cpid = open2(my $TRACEROUTE_FH, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
@@ -491,7 +503,7 @@ sub ask_existing_vg_rename_or_abort {
 		die "could not rename VG from '$vg->{pvs}' ($vg_uuid) to '$new_vgname'!\n";
 	}
     } else {
-	set_next("_Reboot", sub { exit (0); } );
+	set_next("_Reboot", sub { app_quit(0); } );
 	display_html("fail.htm");
 	die "Cancled installation by user, due to already existing volume group '$vgname'\n";
     }
@@ -1529,7 +1541,7 @@ sub create_main_window {
     my $abort = Gtk3::Button->new('_Abort');
     $abort->set_can_focus(0);
     $cmdbox->pack_start($abort, 0, 0, 10);
-    $abort->signal_connect(clicked => sub { exit (-1); });
+    $abort->signal_connect(clicked => sub { app_quit(-1); });
 
     my $vbox2 = Gtk3::VBox->new(0, 0);
     $hbox->add($vbox2);
@@ -2968,7 +2980,7 @@ sub create_extract_view {
 
     $next->set_sensitive(1);
 
-    set_next("_Reboot", sub { exit (0); } );
+    set_next("_Reboot", sub { app_quit(0); } );
 
     if ($err) {
 	display_html("fail.htm");
@@ -2983,7 +2995,7 @@ sub create_extract_view {
 		    $autoreboot_seconds--;
 		    display_html("success.htm");
 		} else {
-		    exit(0);
+		    app_quit(0);
 		}
 	    });
 	}
@@ -3038,7 +3050,7 @@ my $initial_error = 0;
 	print "no harddisks found\n";
 	$initial_error = 1;
 	display_html("nohds.htm");
-	set_next("Reboot", sub { exit(0); } );
+	set_next("Reboot", sub { app_quit(0); } );
     } else {
 	foreach my $hd (@$cached_disks) {
 	    my ($disk, $devname) = @$hd;
@@ -3052,16 +3064,11 @@ if (!$initial_error && (scalar keys %{ $ipconf->{ifaces} } == 0)) {
     print "no network interfaces found\n";
     $initial_error = 1;
     display_html("nonics.htm");
-    set_next("Reboot", sub { exit(0); } );
+    set_next("Reboot", sub { app_quit(0); } );
 }
 
 create_intro_view () if !$initial_error;
 
 Gtk3->main;
 
-# reap left over zombie processes
-while ((my $child = waitpid(-1, POSIX::WNOHANG)) > 0) {
-    print "reaped child $child\n";
-}
-
-exit 0;
+app_quit(0);
-- 
2.39.2





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH installer 2/2] stop main loop when closing the main window
  2023-06-16 10:57 [pve-devel] [PATCH installer 0/2] Close app gracefully Maximiliano Sandoval
  2023-06-16 10:57 ` [pve-devel] [PATCH installer 1/2] exit process gracefully Maximiliano Sandoval
@ 2023-06-16 10:57 ` Maximiliano Sandoval
  2023-06-19  7:36 ` [pve-devel] applied: [PATCH installer 0/2] Close app gracefully Thomas Lamprecht
  2 siblings, 0 replies; 4+ messages in thread
From: Maximiliano Sandoval @ 2023-06-16 10:57 UTC (permalink / raw)
  To: pve-devel

Without this change closing the main window does not exit the main loop.

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
---
 proxinstall | 1 +
 1 file changed, 1 insertion(+)

diff --git a/proxinstall b/proxinstall
index 701133b..4f3c85b 100755
--- a/proxinstall
+++ b/proxinstall
@@ -1501,6 +1501,7 @@ sub create_main_window {
     $window->set_has_resize_grip(0);
     $window->fullscreen() if !is_test_mode();
     $window->set_decorated(0) if !is_test_mode();
+    $window->signal_connect(destroy => sub { Gtk3->main_quit(); });
 
     my $vbox = Gtk3::VBox->new(0, 0);
 
-- 
2.39.2





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] applied:  [PATCH installer 0/2] Close app gracefully
  2023-06-16 10:57 [pve-devel] [PATCH installer 0/2] Close app gracefully Maximiliano Sandoval
  2023-06-16 10:57 ` [pve-devel] [PATCH installer 1/2] exit process gracefully Maximiliano Sandoval
  2023-06-16 10:57 ` [pve-devel] [PATCH installer 2/2] stop main loop when closing the main window Maximiliano Sandoval
@ 2023-06-19  7:36 ` Thomas Lamprecht
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2023-06-19  7:36 UTC (permalink / raw)
  To: Proxmox VE development discussion, Maximiliano Sandoval

Am 16/06/2023 um 12:57 schrieb Maximiliano Sandoval:
> We make sure that the Glib main loop is closed before exiting the application.
> 
> Ideally all of this, among other things, is handled automatically when using
> Gtk3::ApplicationWindow and Glib::IO::Application->run(), but that needs
> https://metacpan.org/pod/Glib::IO to be packaged for debian.
> 
> As a side note, gtk_main() and related functions were removed for GTK 4.
> 
> Maximiliano Sandoval (2):
>   exit process gracefully
>   stop main loop when closing the main window
> 
>  proxinstall | 32 ++++++++++++++++++++------------
>  1 file changed, 20 insertions(+), 12 deletions(-)
> 


applied, thanks!




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-19  7:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-16 10:57 [pve-devel] [PATCH installer 0/2] Close app gracefully Maximiliano Sandoval
2023-06-16 10:57 ` [pve-devel] [PATCH installer 1/2] exit process gracefully Maximiliano Sandoval
2023-06-16 10:57 ` [pve-devel] [PATCH installer 2/2] stop main loop when closing the main window Maximiliano Sandoval
2023-06-19  7:36 ` [pve-devel] applied: [PATCH installer 0/2] Close app gracefully Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal