version 1.1, 1995/10/18 08:45:38 |
version 1.2, 1996/06/11 12:53:35 |
|
|
|
/* $OpenBSD$ */ |
|
/* $NetBSD: collect.c,v 1.6 1996/06/08 19:48:16 christos Exp $ */ |
|
|
/* |
/* |
* Copyright (c) 1980, 1993 |
* Copyright (c) 1980, 1993 |
* The Regents of the University of California. All rights reserved. |
* The Regents of the University of California. All rights reserved. |
|
|
*/ |
*/ |
|
|
#ifndef lint |
#ifndef lint |
static char sccsid[] = "from: @(#)collect.c 8.2 (Berkeley) 4/19/94"; |
#if 0 |
static char rcsid[] = "$Id$"; |
static char sccsid[] = "@(#)collect.c 8.2 (Berkeley) 4/19/94"; |
|
#else |
|
static char rcsid[] = "$OpenBSD$"; |
|
#endif |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
/* |
/* |
|
|
char linebuf[LINESIZE], *cp; |
char linebuf[LINESIZE], *cp; |
extern char *tempMail; |
extern char *tempMail; |
char getsub; |
char getsub; |
int omask; |
sigset_t oset, nset; |
void collint(), collhup(), collstop(); |
#if __GNUC__ |
|
/* Avoid longjmp clobbering */ |
|
(void) &escape; |
|
(void) &eofcount; |
|
(void) &getsub; |
|
#endif |
|
|
collf = NULL; |
collf = NULL; |
/* |
/* |
* Start catching signals from here, but we're still die on interrupts |
* Start catching signals from here, but we're still die on interrupts |
* until we're in the main loop. |
* until we're in the main loop. |
*/ |
*/ |
omask = sigblock(sigmask(SIGINT) | sigmask(SIGHUP)); |
sigemptyset(&nset); |
|
sigaddset(&nset, SIGINT); |
|
sigaddset(&nset, SIGHUP); |
|
sigprocmask(SIG_BLOCK, &nset, &oset); |
if ((saveint = signal(SIGINT, SIG_IGN)) != SIG_IGN) |
if ((saveint = signal(SIGINT, SIG_IGN)) != SIG_IGN) |
signal(SIGINT, collint); |
signal(SIGINT, collint); |
if ((savehup = signal(SIGHUP, SIG_IGN)) != SIG_IGN) |
if ((savehup = signal(SIGHUP, SIG_IGN)) != SIG_IGN) |
|
|
rm(tempMail); |
rm(tempMail); |
goto err; |
goto err; |
} |
} |
sigsetmask(omask & ~(sigmask(SIGINT) | sigmask(SIGHUP))); |
sigprocmask(SIG_SETMASK, &oset, NULL); |
|
|
noreset++; |
noreset++; |
if ((collf = Fopen(tempMail, "w+")) == NULL) { |
if ((collf = Fopen(tempMail, "w+")) == NULL) { |
|
|
/* |
/* |
* Dump core. |
* Dump core. |
*/ |
*/ |
core(); |
core(NULL); |
break; |
break; |
case '!': |
case '!': |
/* |
/* |
|
|
if (collf != NULL) |
if (collf != NULL) |
rewind(collf); |
rewind(collf); |
noreset--; |
noreset--; |
sigblock(sigmask(SIGINT) | sigmask(SIGHUP)); |
sigemptyset(&nset); |
|
sigaddset(&nset, SIGINT); |
|
sigaddset(&nset, SIGHUP); |
|
sigprocmask(SIG_BLOCK, &nset, &oset); |
signal(SIGINT, saveint); |
signal(SIGINT, saveint); |
signal(SIGHUP, savehup); |
signal(SIGHUP, savehup); |
signal(SIGTSTP, savetstp); |
signal(SIGTSTP, savetstp); |
signal(SIGTTOU, savettou); |
signal(SIGTTOU, savettou); |
signal(SIGTTIN, savettin); |
signal(SIGTTIN, savettin); |
sigsetmask(omask); |
sigprocmask(SIG_SETMASK, &oset, NULL); |
return collf; |
return collf; |
} |
} |
|
|
|
|
int s; |
int s; |
{ |
{ |
sig_t old_action = signal(s, SIG_DFL); |
sig_t old_action = signal(s, SIG_DFL); |
|
sigset_t nset; |
|
|
sigsetmask(sigblock(0) & ~sigmask(s)); |
sigemptyset(&nset); |
|
sigaddset(&nset, s); |
|
sigprocmask(SIG_UNBLOCK, &nset, NULL); |
kill(0, s); |
kill(0, s); |
sigblock(sigmask(s)); |
sigprocmask(SIG_BLOCK, &nset, NULL); |
signal(s, old_action); |
signal(s, old_action); |
if (colljmp_p) { |
if (colljmp_p) { |
colljmp_p = 0; |
colljmp_p = 0; |