projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
date and time created 87/02/15 16:03:36 by lepreau
[unix-history]
/
usr
/
src
/
usr.bin
/
mail
/
collect.c
diff --git
a/usr/src/usr.bin/mail/collect.c
b/usr/src/usr.bin/mail/collect.c
index
765b745
..
954e31c
100644
(file)
--- a/
usr/src/usr.bin/mail/collect.c
+++ b/
usr/src/usr.bin/mail/collect.c
@@
-1,4
+1,12
@@
-#
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char *sccsid = "@(#)collect.c 5.2 (Berkeley) %G%";
+#endif not lint
/*
* Mail -- a mail program
/*
* Mail -- a mail program
@@
-7,8
+15,6
@@
* ~ escapes.
*/
* ~ escapes.
*/
-static char *SccsId = "@(#)collect.c 2.3 %G%";
-
#include "rcv.h"
#include <sys/stat.h>
#include "rcv.h"
#include <sys/stat.h>
@@
-27,7
+33,9
@@
static char *SccsId = "@(#)collect.c 2.3 %G%";
static int (*savesig)(); /* Previous SIGINT value */
static int (*savehup)(); /* Previous SIGHUP value */
static int (*savesig)(); /* Previous SIGINT value */
static int (*savehup)(); /* Previous SIGHUP value */
+# ifdef VMUNIX
static int (*savecont)(); /* Previous SIGCONT value */
static int (*savecont)(); /* Previous SIGCONT value */
+# endif VMUNIX
static FILE *newi; /* File for saving away */
static FILE *newo; /* Output side of same */
static int hf; /* Ignore interrups */
static FILE *newi; /* File for saving away */
static FILE *newo; /* Output side of same */
static int hf; /* Ignore interrups */
@@
-45,6
+53,8
@@
collect(hp)
char linebuf[LINESIZE], *cp;
extern char tempMail[];
int notify();
char linebuf[LINESIZE], *cp;
extern char tempMail[];
int notify();
+ extern collintsig(), collhupsig();
+ char getsub;
noreset++;
ibuf = obuf = NULL;
noreset++;
ibuf = obuf = NULL;
@@
-53,11
+63,16
@@
collect(hp)
else
hf = 0;
hadintr = 0;
else
hf = 0;
hadintr = 0;
+# ifdef VMUNIX
if ((savesig = sigset(SIGINT, SIG_IGN)) != SIG_IGN)
if ((savesig = sigset(SIGINT, SIG_IGN)) != SIG_IGN)
- sigset(SIGINT, hf ? intack : collrub), sig
hold(SIGINT
);
+ sigset(SIGINT, hf ? intack : collrub), sig
block(sigmask(SIGINT)
);
if ((savehup = sigset(SIGHUP, SIG_IGN)) != SIG_IGN)
if ((savehup = sigset(SIGHUP, SIG_IGN)) != SIG_IGN)
- sigset(SIGHUP, collrub), sig
hold(SIGINT
);
+ sigset(SIGHUP, collrub), sig
block(sigmask(SIGHUP)
);
savecont = sigset(SIGCONT, collcont);
savecont = sigset(SIGCONT, collcont);
+# else VMUNIX
+ savesig = signal(SIGINT, SIG_IGN);
+ savehup = signal(SIGHUP, SIG_IGN);
+# endif VMUNIX
newi = NULL;
newo = NULL;
if ((obuf = fopen(tempMail, "w")) == NULL) {
newi = NULL;
newo = NULL;
if ((obuf = fopen(tempMail, "w")) == NULL) {
@@
-81,24
+96,35
@@
collect(hp)
*/
t = GTO|GSUBJECT|GCC|GNL;
*/
t = GTO|GSUBJECT|GCC|GNL;
-
c
= 0;
+
getsub
= 0;
if (intty && sflag == NOSTR && hp->h_subject == NOSTR && value("ask"))
if (intty && sflag == NOSTR && hp->h_subject == NOSTR && value("ask"))
- t &= ~GNL,
c
++;
+ t &= ~GNL,
getsub
++;
if (hp->h_seq != 0) {
puthead(hp, stdout, t);
fflush(stdout);
}
if (hp->h_seq != 0) {
puthead(hp, stdout, t);
fflush(stdout);
}
- if (c)
- grabh(hp, GSUBJECT);
escape = ESCAPE;
if ((cp = value("escape")) != NOSTR)
escape = *cp;
eof = 0;
for (;;) {
escape = ESCAPE;
if ((cp = value("escape")) != NOSTR)
escape = *cp;
eof = 0;
for (;;) {
+ int omask = sigblock(0) &~ (sigmask(SIGINT)|sigmask(SIGHUP));
+
setjmp(coljmp);
setjmp(coljmp);
- sigrelse(SIGINT);
- sigrelse(SIGHUP);
- flush();
+# ifdef VMUNIX
+ sigsetmask(omask);
+# else VMUNIX
+ if (savesig != SIG_IGN)
+ signal(SIGINT, hf ? intack : collintsig);
+ if (savehup != SIG_IGN)
+ signal(SIGHUP, collhupsig);
+# endif VMUNIX
+ fflush(stdout);
+ if (getsub) {
+ grabh(hp, GSUBJECT);
+ getsub = 0;
+ continue;
+ }
if (readline(stdin, linebuf) <= 0) {
if (intty && value("ignoreeof") != NOSTR) {
if (++eof > 35)
if (readline(stdin, linebuf) <= 0) {
if (intty && value("ignoreeof") != NOSTR) {
if (++eof > 35)
@@
-111,7
+137,8
@@
collect(hp)
}
eof = 0;
hadintr = 0;
}
eof = 0;
hadintr = 0;
- if (intty && equal(".", linebuf) && value("dot") != NOSTR)
+ if (intty && equal(".", linebuf) &&
+ (value("dot") != NOSTR || value("ignoreeof") != NOSTR))
break;
if (linebuf[0] != escape || rflag != NOSTR) {
if ((t = putline(obuf, linebuf)) < 0)
break;
if (linebuf[0] != escape || rflag != NOSTR) {
if ((t = putline(obuf, linebuf)) < 0)
@@
-159,13
+186,14
@@
collect(hp)
*/
execute(&linebuf[2], 1);
*/
execute(&linebuf[2], 1);
+ printf("(continue)\n");
break;
case '.':
/*
* Simulate end of file on input.
*/
break;
case '.':
/*
* Simulate end of file on input.
*/
- goto eof;
+ goto eof
l
;
case 'q':
case 'Q':
case 'q':
case 'Q':
@@
-258,7
+286,7
@@
collect(hp)
break;
}
printf("\"%s\" ", cp);
break;
}
printf("\"%s\" ", cp);
- f
lush(
);
+ f
flush(stdout
);
lc = 0;
cc = 0;
while (readline(fbuf, linebuf) > 0) {
lc = 0;
cc = 0;
while (readline(fbuf, linebuf) > 0) {
@@
-315,7
+343,7
@@
collect(hp)
case '?':
if ((fbuf = fopen(THELPFILE, "r")) == NULL) {
case '?':
if ((fbuf = fopen(THELPFILE, "r")) == NULL) {
- p
rintf("No help just now.\n"
);
+ p
error(THELPFILE
);
break;
}
t = getc(fbuf);
break;
}
t = getc(fbuf);
@@
-372,15
+400,17
@@
collect(hp)
ibuf = newi;
printf("(continue)\n");
break;
ibuf = newi;
printf("(continue)\n");
break;
- break;
}
}
}
}
-eof:
+eof
l
:
fclose(obuf);
rewind(ibuf);
sigset(SIGINT, savesig);
sigset(SIGHUP, savehup);
fclose(obuf);
rewind(ibuf);
sigset(SIGINT, savesig);
sigset(SIGHUP, savehup);
+# ifdef VMUNIX
sigset(SIGCONT, savecont);
sigset(SIGCONT, savecont);
+ sigsetmask(0);
+# endif VMUNIX
noreset = 0;
return(ibuf);
noreset = 0;
return(ibuf);
@@
-391,7
+421,10
@@
err:
fclose(obuf);
sigset(SIGINT, savesig);
sigset(SIGHUP, savehup);
fclose(obuf);
sigset(SIGINT, savesig);
sigset(SIGHUP, savehup);
+# ifdef VMUNIX
sigset(SIGCONT, savecont);
sigset(SIGCONT, savecont);
+ sigsetmask(0);
+# endif VMUNIX
noreset = 0;
return(NULL);
}
noreset = 0;
return(NULL);
}
@@
-427,7
+460,7
@@
exwrite(name, ibuf, f)
printf("\"%s\" ", name);
fflush(stdout);
}
printf("\"%s\" ", name);
fflush(stdout);
}
- if (stat(name, &junk) >= 0) {
+ if (stat(name, &junk) >= 0
&& (junk.st_mode & S_IFMT) == S_IFREG
) {
if (!f)
fprintf(stderr, "%s: ", name);
fprintf(stderr, "File exists\n", name);
if (!f)
fprintf(stderr, "%s: ", name);
fprintf(stderr, "File exists\n", name);
@@
-471,13
+504,15
@@
mesedit(ibuf, obuf, c)
int pid, s;
FILE *fbuf;
register int t;
int pid, s;
FILE *fbuf;
register int t;
- int (*sig)(), (*scont)(),
foonly
();
+ int (*sig)(), (*scont)(),
signull
();
struct stat sbuf;
extern char tempMail[], tempEdit[];
register char *edit;
sig = sigset(SIGINT, SIG_IGN);
struct stat sbuf;
extern char tempMail[], tempEdit[];
register char *edit;
sig = sigset(SIGINT, SIG_IGN);
- scont = sigset(SIGCONT, foonly);
+# ifdef VMUNIX
+ scont = sigset(SIGCONT, signull);
+# endif VMUNIX
if (stat(tempEdit, &sbuf) >= 0) {
printf("%s: file exists\n", tempEdit);
goto out;
if (stat(tempEdit, &sbuf) >= 0) {
printf("%s: file exists\n", tempEdit);
goto out;
@@
-505,6
+540,7
@@
mesedit(ibuf, obuf, c)
edit = c == 'e' ? EDITOR : VISUAL;
pid = vfork();
if (pid == 0) {
edit = c == 'e' ? EDITOR : VISUAL;
pid = vfork();
if (pid == 0) {
+ sigchild();
if (sig != SIG_IGN)
sigsys(SIGINT, SIG_DFL);
execl(edit, edit, tempEdit, 0);
if (sig != SIG_IGN)
sigsys(SIGINT, SIG_DFL);
execl(edit, edit, tempEdit, 0);
@@
-518,7
+554,7
@@
mesedit(ibuf, obuf, c)
}
while (wait(&s) != pid)
;
}
while (wait(&s) != pid)
;
- if (
s
!= 0) {
+ if (
(s & 0377)
!= 0) {
printf("Fatal error in \"%s\"\n", edit);
remove(tempEdit);
goto out;
printf("Fatal error in \"%s\"\n", edit);
remove(tempEdit);
goto out;
@@
-547,19
+583,14
@@
mesedit(ibuf, obuf, c)
fix:
perror(tempEdit);
out:
fix:
perror(tempEdit);
out:
+# ifdef VMUNIX
sigset(SIGCONT, scont);
sigset(SIGCONT, scont);
+# endif VMUNIX
sigset(SIGINT, sig);
newi = ibuf;
return(obuf);
}
sigset(SIGINT, sig);
newi = ibuf;
return(obuf);
}
-/*
- * Currently, Berkeley virtual VAX/UNIX will not let you change the
- * disposition of SIGCONT, except to trap it somewhere new.
- * Hence, sigset(SIGCONT, foonly) is used to ignore continue signals.
- */
-foonly() {}
-
/*
* Pipe the message through the command.
* Old message is on stdin of command;
/*
* Pipe the message through the command.
* Old message is on stdin of command;
@@
-604,6
+635,7
@@
mespipe(ibuf, obuf, cmd)
* stdout = new message.
*/
* stdout = new message.
*/
+ sigchild();
close(0);
dup(fileno(ibuf));
close(1);
close(0);
dup(fileno(ibuf));
close(1);
@@
-650,7
+682,6
@@
err:
* the message temporary. The flag argument is 'm' if we
* should shift over and 'f' if not.
*/
* the message temporary. The flag argument is 'm' if we
* should shift over and 'f' if not.
*/
-
forward(ms, obuf, f)
char ms[];
FILE *obuf;
forward(ms, obuf, f)
char ms[];
FILE *obuf;
@@
-676,12
+707,12
@@
forward(ms, obuf, f)
touch(*ip);
printf(" %d", *ip);
if (f == 'm') {
touch(*ip);
printf(" %d", *ip);
if (f == 'm') {
- if (transmit(&message[*ip-1], obuf) < 0) {
+ if (transmit(&message[*ip-1], obuf) < 0
L
) {
perror(tempMail);
return(-1);
}
} else
perror(tempMail);
return(-1);
}
} else
- if (send(&message[*ip-1], obuf) < 0) {
+ if (send(&message[*ip-1], obuf
, 0
) < 0) {
perror(tempMail);
return(-1);
}
perror(tempMail);
return(-1);
}
@@
-697,28
+728,30
@@
forward(ms, obuf, f)
* on error.
*/
* on error.
*/
+long
transmit(mailp, obuf)
struct message *mailp;
FILE *obuf;
{
register struct message *mp;
transmit(mailp, obuf)
struct message *mailp;
FILE *obuf;
{
register struct message *mp;
- register int c, ch;
- int n, bol;
+ register int ch;
+ long c, n;
+ int bol;
FILE *ibuf;
mp = mailp;
ibuf = setinput(mp);
FILE *ibuf;
mp = mailp;
ibuf = setinput(mp);
- c = m
size(mp)
;
+ c = m
p->m_size
;
n = c;
bol = 1;
n = c;
bol = 1;
- while (c-- > 0) {
+ while (c-- > 0
L
) {
if (bol) {
bol = 0;
putc('\t', obuf);
n++;
if (ferror(obuf)) {
perror("/tmp");
if (bol) {
bol = 0;
putc('\t', obuf);
n++;
if (ferror(obuf)) {
perror("/tmp");
- return(-1);
+ return(-1
L
);
}
}
ch = getc(ibuf);
}
}
ch = getc(ibuf);
@@
-727,7
+760,7
@@
transmit(mailp, obuf)
putc(ch, obuf);
if (ferror(obuf)) {
perror("/tmp");
putc(ch, obuf);
if (ferror(obuf)) {
perror("/tmp");
- return(-1);
+ return(-1
L
);
}
}
return(n);
}
}
return(n);
@@
-751,6
+784,20
@@
collcont(s)
* were previously set anyway.
*/
* were previously set anyway.
*/
+# ifndef VMUNIX
+collintsig()
+{
+ signal(SIGINT, SIG_IGN);
+ collrub(SIGINT);
+}
+
+collhupsig()
+{
+ signal(SIGHUP, SIG_IGN);
+ collrub(SIGHUP);
+}
+# endif VMUNIX
+
collrub(s)
{
register FILE *dbuf;
collrub(s)
{
register FILE *dbuf;
@@
-758,9
+805,8
@@
collrub(s)
if (s == SIGINT && hadintr == 0) {
hadintr++;
if (s == SIGINT && hadintr == 0) {
hadintr++;
- clrbuf(stdout);
- printf("\n(Interrupt -- one more to kill letter)\n");
- sigrelse(s);
+ fflush(stdout);
+ fprintf(stderr, "\n(Interrupt -- one more to kill letter)\n");
longjmp(coljmp, 1);
}
fclose(newo);
longjmp(coljmp, 1);
}
fclose(newo);
@@
-778,7
+824,9
@@
done:
fclose(newi);
sigset(SIGINT, savesig);
sigset(SIGHUP, savehup);
fclose(newi);
sigset(SIGINT, savesig);
sigset(SIGHUP, savehup);
+# ifdef VMUNIX
sigset(SIGCONT, savecont);
sigset(SIGCONT, savecont);
+# endif VMUNIX
if (rcvmode) {
if (s == SIGHUP)
hangup(SIGHUP);
if (rcvmode) {
if (s == SIGHUP)
hangup(SIGHUP);
@@
-796,7
+844,6
@@
done:
intack(s)
{
intack(s)
{
- sigrelse(SIGCONT);
puts("@");
fflush(stdout);
clearerr(stdin);
puts("@");
fflush(stdout);
clearerr(stdin);