Wait3 becomes wait2 if pdp11 is defined, stays wait3 if vax is defined.
[unix-history] / usr / src / usr.bin / mail / collect.c
index 765b745..080518f 100644 (file)
@@ -7,7 +7,7 @@
  * ~ escapes.
  */
 
  * ~ escapes.
  */
 
-static char *SccsId = "@(#)collect.c   2.3 %G%";
+static char *SccsId = "@(#)collect.c   2.11 %G%";
 
 #include "rcv.h"
 #include <sys/stat.h>
 
 #include "rcv.h"
 #include <sys/stat.h>
@@ -27,7 +27,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 +47,7 @@ collect(hp)
        char linebuf[LINESIZE], *cp;
        extern char tempMail[];
        int notify();
        char linebuf[LINESIZE], *cp;
        extern char tempMail[];
        int notify();
+       extern collintsig(), collhupsig();
 
        noreset++;
        ibuf = obuf = NULL;
 
        noreset++;
        ibuf = obuf = NULL;
@@ -53,11 +56,16 @@ collect(hp)
        else
                hf = 0;
        hadintr = 0;
        else
                hf = 0;
        hadintr = 0;
+# ifdef VMUNIX
        if ((savesig = sigset(SIGINT, SIG_IGN)) != SIG_IGN)
                sigset(SIGINT, hf ? intack : collrub), sighold(SIGINT);
        if ((savehup = sigset(SIGHUP, SIG_IGN)) != SIG_IGN)
        if ((savesig = sigset(SIGINT, SIG_IGN)) != SIG_IGN)
                sigset(SIGINT, hf ? intack : collrub), sighold(SIGINT);
        if ((savehup = sigset(SIGHUP, SIG_IGN)) != SIG_IGN)
-               sigset(SIGHUP, collrub), sighold(SIGINT);
+               sigset(SIGHUP, collrub), sighold(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) {
@@ -96,8 +104,15 @@ collect(hp)
        eof = 0;
        for (;;) {
                setjmp(coljmp);
        eof = 0;
        for (;;) {
                setjmp(coljmp);
+# ifdef VMUNIX
                sigrelse(SIGINT);
                sigrelse(SIGHUP);
                sigrelse(SIGINT);
                sigrelse(SIGHUP);
+# else VMUNIX
+               if (savesig != SIG_IGN)
+                       signal(SIGINT, hf ? intack : collintsig);
+               if (savehup != SIG_IGN)
+                       signal(SIGHUP, collhupsig);
+# endif VMUNIX
                flush();
                if (readline(stdin, linebuf) <= 0) {
                        if (intty && value("ignoreeof") != NOSTR) {
                flush();
                if (readline(stdin, linebuf) <= 0) {
                        if (intty && value("ignoreeof") != NOSTR) {
@@ -111,7 +126,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 +175,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 eofl;
 
                case 'q':
                case 'Q':
 
                case 'q':
                case 'Q':
@@ -375,12 +392,14 @@ collect(hp)
                        break;
                }
        }
                        break;
                }
        }
-eof:
+eofl:
        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);
+# endif VMUNIX
        noreset = 0;
        return(ibuf);
 
        noreset = 0;
        return(ibuf);
 
@@ -391,7 +410,9 @@ 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);
+# endif VMUNIX
        noreset = 0;
        return(NULL);
 }
        noreset = 0;
        return(NULL);
 }
@@ -427,7 +448,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);
@@ -477,7 +498,9 @@ mesedit(ibuf, obuf, c)
        register char *edit;
 
        sig = sigset(SIGINT, SIG_IGN);
        register char *edit;
 
        sig = sigset(SIGINT, SIG_IGN);
+# ifdef VMUNIX
        scont = sigset(SIGCONT, foonly);
        scont = sigset(SIGCONT, foonly);
+# 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 +528,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 +542,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,7 +571,9 @@ 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);
@@ -604,6 +630,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 +677,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;
@@ -681,7 +707,7 @@ forward(ms, obuf, f)
                                return(-1);
                        }
                } else
                                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);
                        }
@@ -751,6 +777,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;
@@ -760,7 +800,9 @@ collrub(s)
                hadintr++;
                clrbuf(stdout);
                printf("\n(Interrupt -- one more to kill letter)\n");
                hadintr++;
                clrbuf(stdout);
                printf("\n(Interrupt -- one more to kill letter)\n");
+# ifdef VMUNIX
                sigrelse(s);
                sigrelse(s);
+# endif VMUNIX
                longjmp(coljmp, 1);
        }
        fclose(newo);
                longjmp(coljmp, 1);
        }
        fclose(newo);
@@ -778,7 +820,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 +840,6 @@ done:
 intack(s)
 {
        
 intack(s)
 {
        
-       sigrelse(SIGCONT);
        puts("@");
        fflush(stdout);
        clearerr(stdin);
        puts("@");
        fflush(stdout);
        clearerr(stdin);