From 046867d40907d5ade612ed34c2b84bbf3c01ad02 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 22 Jul 1997 18:54:46 +0000 Subject: grabh() now returns SIGINT if it was interrupted (previously always returned 0 and the return val was always ignored). Add gethfromtty() to get a header (using grabh) from the tty and quit on two ^C's. Use gethfromtty() when getting Subject, Cc, and Bcc headers so we can quit nicely. Closes PR #291. Don't use longs where it doesn't make sense. --- usr.bin/mail/cmd1.c | 6 +++--- usr.bin/mail/collect.c | 50 +++++++++++++++++++++++++++++++++++--------------- usr.bin/mail/extern.h | 5 +++-- usr.bin/mail/send.c | 16 +++------------- usr.bin/mail/tty.c | 11 +++++++---- 5 files changed, 51 insertions(+), 37 deletions(-) diff --git a/usr.bin/mail/cmd1.c b/usr.bin/mail/cmd1.c index 567ef6c37e3..e6e0c783043 100644 --- a/usr.bin/mail/cmd1.c +++ b/usr.bin/mail/cmd1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd1.c,v 1.8 1997/07/14 00:24:24 millert Exp $ */ +/* $OpenBSD: cmd1.c,v 1.9 1997/07/22 18:54:34 millert Exp $ */ /* $NetBSD: cmd1.c,v 1.9 1997/07/09 05:29:48 mikel Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)cmd1.c 8.2 (Berkeley) 4/20/95"; #else -static char rcsid[] = "$OpenBSD: cmd1.c,v 1.8 1997/07/14 00:24:24 millert Exp $"; +static char rcsid[] = "$OpenBSD: cmd1.c,v 1.9 1997/07/22 18:54:34 millert Exp $"; #endif #endif /* not lint */ @@ -409,7 +409,7 @@ top(v) if (!lineb) putchar('\n'); for (lines = 0; lines < c && lines <= topl; lines++) { - if (readline(ibuf, linebuf, LINESIZE) < 0) + if (readline(ibuf, linebuf, sizeof(linebuf)) < 0) break; puts(linebuf); lineb = blankline(linebuf); diff --git a/usr.bin/mail/collect.c b/usr.bin/mail/collect.c index 3c79a49ca1f..32bac7934d8 100644 --- a/usr.bin/mail/collect.c +++ b/usr.bin/mail/collect.c @@ -1,4 +1,4 @@ -/* $OpenBSD: collect.c,v 1.10 1997/07/22 18:26:24 millert Exp $ */ +/* $OpenBSD: collect.c,v 1.11 1997/07/22 18:54:36 millert Exp $ */ /* $NetBSD: collect.c,v 1.9 1997/07/09 05:25:45 mikel Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)collect.c 8.2 (Berkeley) 4/19/94"; #else -static char rcsid[] = "$OpenBSD: collect.c,v 1.10 1997/07/22 18:26:24 millert Exp $"; +static char rcsid[] = "$OpenBSD: collect.c,v 1.11 1997/07/22 18:54:36 millert Exp $"; #endif #endif /* not lint */ @@ -152,16 +152,8 @@ collect(hp, printheaders) longline = 0; if (!sigsetjmp(colljmp, 1)) { - if (getsub && grabh(hp, GSUBJECT) == SIGINT) { - fflush(stdout); - fputs("\n(Interrupt -- one more to kill letter)\n", - stderr); - if (grabh(hp, GSUBJECT) == SIGINT) { - hadintr++; - collint(SIGINT); - exit(1); - } - } + if (getsub) + gethfromtty(hp, GSUBJECT); } else { /* * Come here for printing the after-signal message. @@ -401,6 +393,18 @@ cont: goto cont; } } + + if (value("interactive") != NULL) { + if (value("askcc") != NULL || value("askbcc") != NULL) { + if (value("askcc") != NULL) + gethfromtty(hp, GCC); + if (value("askbcc") != NULL) + gethfromtty(hp, GBCC); + } else { + puts("EOT"); + (void)fflush(stdout); + } + } goto out; err: if (collf != NULL) { @@ -435,8 +439,7 @@ exwrite(name, fp, f) { register FILE *of; register int c; - long cc; - int lc; + ssize_t cc, lc; struct stat junk; if (f) { @@ -467,7 +470,7 @@ exwrite(name, fp, f) } } (void)Fclose(of); - printf("%d/%ld\n", lc, cc); + printf("%d/%d\n", lc, cc); fflush(stdout); return(0); } @@ -678,3 +681,20 @@ savedeadletter(fp) (void)Fclose(dbuf); rewind(fp); } + +void +gethfromtty(hp, gflags) + struct header *hp; + int gflags; +{ + if (grabh(hp, gflags) == SIGINT) { + fflush(stdout); + fputs("\n(Interrupt -- one more to kill letter)\n", + stderr); + if (grabh(hp, gflags) == SIGINT) { + hadintr++; + collint(SIGINT); + exit(1); + } + } +} diff --git a/usr.bin/mail/extern.h b/usr.bin/mail/extern.h index 852f74be5a4..73ece3ffa21 100644 --- a/usr.bin/mail/extern.h +++ b/usr.bin/mail/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.6 1997/07/13 21:21:12 millert Exp $ */ +/* $OpenBSD: extern.h,v 1.7 1997/07/22 18:54:38 millert Exp $ */ /* $NetBSD: extern.h,v 1.7 1997/07/09 05:22:00 mikel Exp $ */ /*- @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)extern.h 8.2 (Berkeley) 4/20/95 - * $OpenBSD: extern.h,v 1.6 1997/07/13 21:21:12 millert Exp $ + * $OpenBSD: extern.h,v 1.7 1997/07/22 18:54:38 millert Exp $ */ struct name; @@ -141,6 +141,7 @@ int from __P((void *)); off_t fsize __P((FILE *)); int getfold __P((char *, int)); int gethfield __P((FILE *, char [], int, char **)); +void gethfromtty __P((struct header *, int)); int getmsglist __P((char *, int *, int)); int getrawlist __P((char [], char **, int)); int getuserid __P((char [])); diff --git a/usr.bin/mail/send.c b/usr.bin/mail/send.c index a86a8bcc7aa..85183bf2b55 100644 --- a/usr.bin/mail/send.c +++ b/usr.bin/mail/send.c @@ -1,4 +1,4 @@ -/* $OpenBSD: send.c,v 1.6 1997/07/14 15:56:25 millert Exp $ */ +/* $OpenBSD: send.c,v 1.7 1997/07/22 18:54:41 millert Exp $ */ /* $NetBSD: send.c,v 1.6 1996/06/08 19:48:39 christos Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)send.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: send.c,v 1.6 1997/07/14 15:56:25 millert Exp $"; +static char rcsid[] = "$OpenBSD: send.c,v 1.7 1997/07/22 18:54:41 millert Exp $"; #endif #endif /* not lint */ @@ -65,7 +65,7 @@ send(mp, obuf, doign, prefix) struct ignoretab *doign; char *prefix; { - long count; + int count; register FILE *ibuf; char line[LINESIZE]; int ishead, infld, ignoring = 0, dostat, firstline; @@ -315,16 +315,6 @@ mail1(hp, printheaders) */ if ((mtf = collect(hp, printheaders)) == NULL) return; - if (value("interactive") != NULL) - if (value("askcc") != NULL || value("askbcc") != NULL) { - if (value("askcc") != NULL) - grabh(hp, GCC); - if (value("askbcc") != NULL) - grabh(hp, GBCC); - } else { - puts("EOT"); - (void)fflush(stdout); - } if (fsize(mtf) == 0) if (hp->h_subject == NULL) puts("No message, no subject; hope that's ok"); diff --git a/usr.bin/mail/tty.c b/usr.bin/mail/tty.c index b05645662a6..c22ac812282 100644 --- a/usr.bin/mail/tty.c +++ b/usr.bin/mail/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.6 1997/07/14 15:56:25 millert Exp $ */ +/* $OpenBSD: tty.c,v 1.7 1997/07/22 18:54:45 millert Exp $ */ /* $NetBSD: tty.c,v 1.7 1997/07/09 05:25:46 mikel Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)tty.c 8.2 (Berkeley) 4/20/95"; #else -static char rcsid[] = "$OpenBSD: tty.c,v 1.6 1997/07/14 15:56:25 millert Exp $"; +static char rcsid[] = "$OpenBSD: tty.c,v 1.7 1997/07/22 18:54:45 millert Exp $"; #endif #endif /* not lint */ @@ -79,13 +79,14 @@ grabh(hp, gflags) sig_t savetstp; sig_t savettou; sig_t savettin; - int errs; + int errs = 0; #ifdef __GNUC__ /* Avoid siglongjmp clobbering */ #ifdef TIOCSTI (void)&extproc; #endif (void)&saveint; + (void)&errs; #endif savetstp = signal(SIGTSTP, SIG_DFL); @@ -117,8 +118,10 @@ grabh(hp, gflags) warn("TIOCEXT: off"); } # endif /* TIOCEXT */ - if (sigsetjmp(intjmp, 1)) + if (sigsetjmp(intjmp, 1)) { + errs = SIGINT; goto out; + } saveint = signal(SIGINT, ttyint); #endif if (gflags & GTO) { -- cgit v1.2.3