setup home directory for globbing
[unix-history] / usr / src / usr.bin / mail / edit.c
index f08f7aa..1971329 100644 (file)
@@ -10,7 +10,7 @@
  * Perform message editing functions.
  */
 
  * Perform message editing functions.
  */
 
-static char *SccsId = "@(#)edit.c      1.1 %G%";
+static char *SccsId = "@(#)edit.c      2.4 %G%";
 
 /*
  * Edit a message list.
 
 /*
  * Edit a message list.
@@ -53,7 +53,7 @@ edit1(msgvec, ed)
        register char *cp, *cp2;
        register int c;
        int *ip, pid, mesg, lines;
        register char *cp, *cp2;
        register int c;
        int *ip, pid, mesg, lines;
-       unsigned int ms;
+       long ms;
        int (*sigint)(), (*sigquit)();
        FILE *ibuf, *obuf;
        char edname[15], nbuf[10];
        int (*sigint)(), (*sigquit)();
        FILE *ibuf, *obuf;
        char edname[15], nbuf[10];
@@ -67,8 +67,8 @@ edit1(msgvec, ed)
         * Set signals; locate editor.
         */
 
         * Set signals; locate editor.
         */
 
-       sigint = signal(SIGINT, SIG_IGN);
-       sigquit = signal(SIGQUIT, SIG_IGN);
+       sigint = sigset(SIGINT, SIG_IGN);
+       sigquit = sigset(SIGQUIT, SIG_IGN);
 
        /*
         * Deal with each message to be edited . . .
 
        /*
         * Deal with each message to be edited . . .
@@ -108,7 +108,7 @@ edit1(msgvec, ed)
                        perror(edname);
                        goto out;
                }
                        perror(edname);
                        goto out;
                }
-               if (send(mp, obuf) < 0) {
+               if (send(mp, obuf, 0) < 0) {
                        perror(edname);
                        fclose(obuf);
                        remove(edname);
                        perror(edname);
                        fclose(obuf);
                        remove(edname);
@@ -122,6 +122,14 @@ edit1(msgvec, ed)
                }
                fclose(obuf);
 
                }
                fclose(obuf);
 
+               /*
+                * If we are in read only mode, make the
+                * temporary message file readonly as well.
+                */
+
+               if (readonly)
+                       chmod(edname, 0400);
+
                /*
                 * Fork/execl the editor on the edit file.
                 */
                /*
                 * Fork/execl the editor on the edit file.
                 */
@@ -136,10 +144,11 @@ edit1(msgvec, ed)
                        goto out;
                }
                if (pid == 0) {
                        goto out;
                }
                if (pid == 0) {
+                       sigchild();
                        if (sigint != SIG_IGN)
                        if (sigint != SIG_IGN)
-                               signal(SIGINT, SIG_DFL);
+                               sigsys(SIGINT, SIG_DFL);
                        if (sigquit != SIG_IGN)
                        if (sigquit != SIG_IGN)
-                               signal(SIGQUIT, SIG_DFL);
+                               sigsys(SIGQUIT, SIG_DFL);
                        execl(ed, ed, edname, 0);
                        perror(ed);
                        _exit(1);
                        execl(ed, ed, edname, 0);
                        perror(ed);
                        _exit(1);
@@ -147,6 +156,16 @@ edit1(msgvec, ed)
                while (wait(&mesg) != pid)
                        ;
 
                while (wait(&mesg) != pid)
                        ;
 
+               /*
+                * If in read only mode, just remove the editor
+                * temporary and return.
+                */
+
+               if (readonly) {
+                       remove(edname);
+                       continue;
+               }
+
                /*
                 * Now copy the message to the end of the
                 * temp file.
                /*
                 * Now copy the message to the end of the
                 * temp file.
@@ -170,7 +189,7 @@ edit1(msgvec, ed)
                size = fsize(otf);
                mp->m_block = blockof(size);
                mp->m_offset = offsetof(size);
                size = fsize(otf);
                mp->m_block = blockof(size);
                mp->m_offset = offsetof(size);
-               ms = 0;
+               ms = 0L;
                lines = 0;
                while ((c = getc(ibuf)) != EOF) {
                        if (c == '\n')
                lines = 0;
                while ((c = getc(ibuf)) != EOF) {
                        if (c == '\n')
@@ -192,6 +211,6 @@ edit1(msgvec, ed)
         */
 
 out:
         */
 
 out:
-       signal(SIGINT, sigint);
-       signal(SIGQUIT, sigquit);
+       sigset(SIGINT, sigint);
+       sigset(SIGQUIT, sigquit);
 }
 }