From 424f55f4b5d894e49346ee4725c73612c2f61d42 Mon Sep 17 00:00:00 2001 From: simonb Date: Fri, 5 Dec 1997 13:38:59 +0000 Subject: [PATCH] Add a cleanup function (set with atexit()) that shuts down curses nicely and unmounts any filesystems left mounted when sysinst exits under any circumstances. --- distrib/utils/sysinst/main.c | 31 ++++++++++++++++++++++-------- distrib/utils/sysinst/menus.mi.eng | 4 ++-- distrib/utils/sysinst/menus.mi.fr | 4 ++-- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/distrib/utils/sysinst/main.c b/distrib/utils/sysinst/main.c index f7d5f4099657..8d9c40f7d9ea 100644 --- a/distrib/utils/sysinst/main.c +++ b/distrib/utils/sysinst/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.7 1997/12/04 09:05:35 jonathan Exp $ */ +/* $NetBSD: main.c,v 1.8 1997/12/05 13:38:59 simonb Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -50,8 +50,11 @@ #include "menu_defs.h" int main(int argc, char **argv); -void usage (void); -void inthandler (int); +static void usage(void); +static void inthandler(int); +static void cleanup(void); + +static int exit_cleanly = 0; /* Did we finish nicely? */ int main(int argc, char **argv) { @@ -84,11 +87,13 @@ int main(int argc, char **argv) /* Watch for SIGINT and clean up */ (void) signal(SIGINT, inthandler); + (void) atexit(cleanup); /* Menu processing */ process_menu (MENU_netbsd); - return 0; + exit_cleanly = 1; + exit(0); } @@ -110,7 +115,7 @@ void toplevel(void) /* The usage ... */ -void +static void usage(void) { (void)fprintf (stderr, msg_string(MSG_usage)); @@ -118,10 +123,20 @@ usage(void) } /* ARGSUSED */ -void +static void inthandler(int notused) { - endwin(); - fprintf(stderr, "\n\n sysinst terminated.\n"); + /* atexit() wants a void function, so inthandler() just calls cleanup */ + cleanup(); exit(1); } + +static void +cleanup(void) +{ + endwin(); + unwind_mounts(); + run_prog("/sbin/umount /mnt2 2>/dev/null"); + if (!exit_cleanly) + fprintf(stderr, "\n\n sysinst terminated.\n"); +} diff --git a/distrib/utils/sysinst/menus.mi.eng b/distrib/utils/sysinst/menus.mi.eng index 9d9870360b3a..6bce09da8dfe 100644 --- a/distrib/utils/sysinst/menus.mi.eng +++ b/distrib/utils/sysinst/menus.mi.eng @@ -1,4 +1,4 @@ -/* $NetBSD: menus.mi.eng,v 1.15 1997/12/04 09:05:37 jonathan Exp $ */ +/* $NetBSD: menus.mi.eng,v 1.16 1997/12/05 13:39:01 simonb Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -66,7 +66,7 @@ menu netbsd, title " NetBSD-@@VERSION@@ Install System"; option "Reboot the computer", exit, action (endwin) { run_prog("/sbin/reboot"); }; option "Utility menu", sub menu utility; - option "Exit Install System", exit, action (endwin) {}; + option "Exit Install System", exit; menu utility, title " NetBSD-@@VERSION@@ Utility", exit; option "Run /bin/sh", diff --git a/distrib/utils/sysinst/menus.mi.fr b/distrib/utils/sysinst/menus.mi.fr index 1fe02e3f658e..c403eb24086d 100644 --- a/distrib/utils/sysinst/menus.mi.fr +++ b/distrib/utils/sysinst/menus.mi.fr @@ -1,4 +1,4 @@ -/* $NetBSD: menus.mi.fr,v 1.2 1997/12/04 09:05:36 jonathan Exp $ */ +/* $NetBSD: menus.mi.fr,v 1.3 1997/12/05 13:39:02 simonb Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -66,7 +66,7 @@ menu netbsd, title " NetBSD-@@VERSION@@ Programme d'installation"; option "Redémarrer l'ordinateur", exit, action (endwin) { run_prog("/sbin/reboot"); }; option "Menu utilitaire", sub menu utility; - option "Quitter le programme d'installation", exit, action (endwin) {}; + option "Quitter le programme d'installation", exit; menu utility, title " Utilitaires NetBSD-@@VERSION@@", exit; option "Exécuter /bin/sh",