all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Maximiliano Sandoval <m.sandoval@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 1/2] exit process gracefully
Date: Fri, 16 Jun 2023 12:57:42 +0200	[thread overview]
Message-ID: <20230616105743.105209-2-m.sandoval@proxmox.com> (raw)
In-Reply-To: <20230616105743.105209-1-m.sandoval@proxmox.com>

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





  reply	other threads:[~2023-06-16 10:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-16 10:57 [pve-devel] [PATCH installer 0/2] Close app gracefully Maximiliano Sandoval
2023-06-16 10:57 ` Maximiliano Sandoval [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230616105743.105209-2-m.sandoval@proxmox.com \
    --to=m.sandoval@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal