diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2001-11-20 20:50:01 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2001-11-20 20:50:01 +0000 |
commit | a773d207e5326979dbae610af9f727ba9d9aab9a (patch) | |
tree | 25eae41092ce63d11c23e2bde172d49858a6b094 /usr.bin/mail/main.c | |
parent | 65d78d4142675bd4f69ddc0d983e59907c358f64 (diff) |
Major signal overhaul. We no longer longjmp all over the place.
Instead, routines responsible to gathering user input (or in some
cases outputting data) catch the signals and set flags as needed.
Because of this some handlers are install without the SA_RESTART
flag so syscalls are not restarted and we can check the flag. All
signal handlers are now safe.
This should make the flow of control a bit more grokable but the
code is still ugly.
Diffstat (limited to 'usr.bin/mail/main.c')
-rw-r--r-- | usr.bin/mail/main.c | 77 |
1 files changed, 38 insertions, 39 deletions
diff --git a/usr.bin/mail/main.c b/usr.bin/mail/main.c index e8ffac609eb..e08b15135fd 100644 --- a/usr.bin/mail/main.c +++ b/usr.bin/mail/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.14 2001/10/11 20:59:46 millert Exp $ */ +/* $OpenBSD: main.c,v 1.15 2001/11/20 20:50:00 millert Exp $ */ /* $NetBSD: main.c,v 1.7 1997/05/13 06:15:57 mikel Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 4/20/95"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.14 2001/10/11 20:59:46 millert Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.15 2001/11/20 20:50:00 millert Exp $"; #endif #endif /* not lint */ @@ -54,6 +54,7 @@ static char rcsid[] = "$OpenBSD: main.c,v 1.14 2001/10/11 20:59:46 millert Exp $ #include "extern.h" int main __P((int, char **)); +__dead void usage __P((void)); /* * Mail -- a mail program @@ -61,8 +62,6 @@ int main __P((int, char **)); * Startup -- interface with user. */ -sigjmp_buf hdrjmp; - int main(argc, argv) int argc; @@ -73,8 +72,8 @@ main(argc, argv) char *subject; char *ef; char nosrc = 0; - sig_t prevint; char *rc; + extern char *version; /* * Set up a reasonable environment. @@ -82,6 +81,7 @@ main(argc, argv) * start the SIGCHLD catcher, and so forth. */ (void)signal(SIGCHLD, sigchild); + (void)signal(SIGPIPE, SIG_IGN); if (isatty(0)) assign("interactive", ""); image = -1; @@ -188,13 +188,9 @@ main(argc, argv) */ bcc = cat(bcc, nalloc(optarg, GBCC)); break; - case '?': - fprintf(stderr, "\ -Usage: %s [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...\n\ - [- sendmail-options ...]\n\ - %s [-iInNv] -f [name]\n\ - %s [-iInNv] [-u user]\n", __progname, __progname, __progname); - exit(1); + default: + usage(); + /*NOTREACHED*/ } } for (i = optind; (argv[i]) && (*argv[i] != '-'); i++) @@ -208,6 +204,15 @@ Usage: %s [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...\n\ errx(1, "You must specify direct recipients with -s, -c, or -b"); if (ef != NULL && to != NIL) errx(1, "Cannot give -f and people to send to"); + /* + * Block SIGINT except where we install an explicit handler for it. + */ + sigemptyset(&intset); + sigaddset(&intset, SIGINT); + (void)sigprocmask(SIG_BLOCK, &intset, NULL); + /* + * Initialization. + */ tinit(); setscreensize(); input = stdin; @@ -238,40 +243,21 @@ Usage: %s [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...\n\ ef = "%"; if (setfile(ef) < 0) exit(1); /* error already reported */ - if (sigsetjmp(hdrjmp, 1) == 0) { - extern char *version; - if ((prevint = signal(SIGINT, SIG_IGN)) != SIG_IGN) - (void)signal(SIGINT, hdrstop); - if (value("quiet") == NULL) - (void)printf("Mail version %s. Type ? for help.\n", - version); - announce(); - (void)fflush(stdout); - (void)signal(SIGINT, prevint); - } + if (value("quiet") == NULL) + (void)printf("Mail version %s. Type ? for help.\n", + version); + announce(); + (void)fflush(stdout); commands(); - (void)signal(SIGHUP, SIG_IGN); - (void)signal(SIGINT, SIG_IGN); - (void)signal(SIGQUIT, SIG_IGN); + (void)ignoresig(SIGHUP, NULL, NULL); + (void)ignoresig(SIGINT, NULL, NULL); + (void)ignoresig(SIGQUIT, NULL, NULL); quit(); exit(0); } /* - * Interrupt printing of the headers. - */ -void -hdrstop(signo) - int signo; -{ - - fflush(stdout); - fputs("\nInterrupt\n", stderr); - siglongjmp(hdrjmp, 1); -} - -/* * Compute what the screen size for printing headers should be. * We use the following algorithm for the height: * If baud rate < 1200, use 9 @@ -305,3 +291,16 @@ setscreensize() if ((screenwidth = ws.ws_col) == 0) screenwidth = 80; } + +__dead void +usage() +{ + + fprintf(stderr, "usage: %s [-iInv] [-s subject] [-c cc-addr] " + "[-b bcc-addr] to-addr ...\n", __progname); + fprintf(stderr, " %*s [- sendmail-options ...]\n", + (int)strlen(__progname), ""); + fprintf(stderr, " %s [-iInNv] -f [name]\n", __progname); + fprintf(stderr, " %s [-iInNv] [-u user]\n", __progname); + exit(1); +} |