From 1285035fe714995fa17d6b54e426b8da5a305a73 Mon Sep 17 00:00:00 2001 From: hubertf Date: Tue, 25 Aug 1998 00:12:16 +0000 Subject: [PATCH] Don't exit cleanup() functions if not called from signal handler - this will show error messages before aborting. Patch supplied by Jim Bernard in PR 6010, cleanup() in delete/perform.c prepared to be used as signal handler by me. --- usr.sbin/pkg_install/add/perform.c | 17 ++++++++++++----- usr.sbin/pkg_install/create/perform.c | 22 ++++++++++++++++++---- usr.sbin/pkg_install/delete/perform.c | 7 ++++--- usr.sbin/pkg_install/info/perform.c | 19 +++++++++++++++---- usr.sbin/pkg_install/lib/msg.c | 10 +++++----- 5 files changed, 54 insertions(+), 21 deletions(-) diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c index 2eab71fb62ee..cbfd578d6805 100644 --- a/usr.sbin/pkg_install/add/perform.c +++ b/usr.sbin/pkg_install/add/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.14 1998/07/12 14:05:51 hubertf Exp $ */ +/* $NetBSD: perform.c,v 1.15 1998/08/25 00:12:16 hubertf Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp"; #else -__RCSID("$NetBSD: perform.c,v 1.14 1998/07/12 14:05:51 hubertf Exp $"); +__RCSID("$NetBSD: perform.c,v 1.15 1998/08/25 00:12:16 hubertf Exp $"); #endif #endif @@ -495,14 +495,21 @@ void cleanup(int signo) { static int alreadyCleaning; + void (*oldint)(int); + void (*oldhup)(int); + oldint = signal(SIGINT, SIG_IGN); + oldhup = signal(SIGHUP, SIG_IGN); if (!alreadyCleaning) { alreadyCleaning = 1; if (signo) - printf("Signal %d received, cleaning up..\n", signo); + printf("Signal %d received, cleaning up..\n", signo); if (!Fake && LogDir[0]) - vsystem("%s -rf %s", REMOVE_CMD, LogDir); + vsystem("%s -rf %s", REMOVE_CMD, LogDir); leave_playpen(Home); + if (signo) + exit(1); } - exit(1); + signal(SIGINT, oldint); + signal(SIGHUP, oldhup); } diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c index ae465e75135d..88603182e7c6 100644 --- a/usr.sbin/pkg_install/create/perform.c +++ b/usr.sbin/pkg_install/create/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.7 1998/06/05 11:22:20 frueauf Exp $ */ +/* $NetBSD: perform.c,v 1.8 1998/08/25 00:12:16 hubertf Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.38 1997/10/13 15:03:51 jkh Exp"; #else -__RCSID("$NetBSD: perform.c,v 1.7 1998/06/05 11:22:20 frueauf Exp $"); +__RCSID("$NetBSD: perform.c,v 1.8 1998/08/25 00:12:16 hubertf Exp $"); #endif #endif @@ -314,6 +314,20 @@ sanity_check() void cleanup(int sig) { - leave_playpen(home); - exit(1); + static int alreadyCleaning; + void (*oldint)(int); + void (*oldhup)(int); + oldint = signal(SIGINT, SIG_IGN); + oldhup = signal(SIGHUP, SIG_IGN); + + if (!alreadyCleaning) { + alreadyCleaning = 1; + if (sig) + printf("Signal %d received, cleaning up..\n", sig); + leave_playpen(home); + if (sig) + exit(1); + } + signal(SIGINT, oldint); + signal(SIGHUP, oldhup); } diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c index 8f301752127f..ebef60d5ff25 100644 --- a/usr.sbin/pkg_install/delete/perform.c +++ b/usr.sbin/pkg_install/delete/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.4 1997/10/17 14:54:05 lukem Exp $ */ +/* $NetBSD: perform.c,v 1.5 1998/08/25 00:12:17 hubertf Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.15 1997/10/13 15:03:52 jkh Exp"; #else -__RCSID("$NetBSD: perform.c,v 1.4 1997/10/17 14:54:05 lukem Exp $"); +__RCSID("$NetBSD: perform.c,v 1.5 1998/08/25 00:12:17 hubertf Exp $"); #endif #endif @@ -168,7 +168,8 @@ void cleanup(int sig) { /* Nothing to do */ - exit(1); + if(sig) /* in case this is ever used as a signal handler */ + exit(1); } static void diff --git a/usr.sbin/pkg_install/info/perform.c b/usr.sbin/pkg_install/info/perform.c index 55e834227c1f..ccd7968ec47a 100644 --- a/usr.sbin/pkg_install/info/perform.c +++ b/usr.sbin/pkg_install/info/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.6 1998/07/09 17:49:51 hubertf Exp $ */ +/* $NetBSD: perform.c,v 1.7 1998/08/25 00:12:17 hubertf Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp"; #else -__RCSID("$NetBSD: perform.c,v 1.6 1998/07/09 17:49:51 hubertf Exp $"); +__RCSID("$NetBSD: perform.c,v 1.7 1998/08/25 00:12:17 hubertf Exp $"); #endif #endif @@ -247,6 +247,17 @@ pkg_do(char *pkg) void cleanup(int sig) { - leave_playpen(Home); - exit(1); + static int alreadyCleaning; + void (*oldint)(int); + oldint = signal(SIGINT, SIG_IGN); + + if (!alreadyCleaning) { + alreadyCleaning = 1; + if (sig) + printf("Signal %d received, cleaning up..\n", sig); + leave_playpen(Home); + if (sig) + exit(1); + } + signal(SIGINT, oldint); } diff --git a/usr.sbin/pkg_install/lib/msg.c b/usr.sbin/pkg_install/lib/msg.c index c3e500c53c35..a8588a148c5e 100644 --- a/usr.sbin/pkg_install/lib/msg.c +++ b/usr.sbin/pkg_install/lib/msg.c @@ -1,11 +1,11 @@ -/* $NetBSD: msg.c,v 1.4 1997/10/17 14:54:41 lukem Exp $ */ +/* $NetBSD: msg.c,v 1.5 1998/08/25 00:12:17 hubertf Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: msg.c,v 1.10 1997/10/13 15:03:55 jkh Exp"; #else -__RCSID("$NetBSD: msg.c,v 1.4 1997/10/17 14:54:41 lukem Exp $"); +__RCSID("$NetBSD: msg.c,v 1.5 1998/08/25 00:12:17 hubertf Exp $"); #endif #endif @@ -35,10 +35,10 @@ __RCSID("$NetBSD: msg.c,v 1.4 1997/10/17 14:54:41 lukem Exp $"); /* Die a relatively simple death */ void -upchuck(const char *err) +upchuck(const char *errstr) { - warn("fatal error during execution: %s", err); cleanup(0); + err(1, "fatal error during execution: %s", errstr); } /* @@ -59,8 +59,8 @@ y_or_n(Boolean def, const char *msg, ...) */ tty = fopen("/dev/tty", "r"); if (!tty) { - warnx("can't open /dev/tty!"); cleanup(0); + errx(1, "can't open /dev/tty!"); } while (ch != 'Y' && ch != 'N') { vfprintf(stderr, msg, args);