Add a cleanup function (set with atexit()) that shuts down curses nicely

and unmounts any filesystems left mounted when sysinst exits under any
circumstances.
This commit is contained in:
simonb 1997-12-05 13:38:59 +00:00
parent 5dda445628
commit 424f55f4b5
3 changed files with 27 additions and 12 deletions

View File

@ -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");
}

View File

@ -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",

View File

@ -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",