move call to lock before the fopen for append; change decl of "k" in
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Mon, 11 Apr 1983 07:40:46 +0000 (23:40 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Mon, 11 Apr 1983 07:40:46 +0000 (23:40 -0800)
copylet from int to long for PDP-11's.  Thanks to Jay Lepreau for these.

SCCS-vsn: libexec/mail.local/mail.local.c 4.14

usr/src/libexec/mail.local/mail.local.c

index 3922b91..68404d0 100644 (file)
@@ -8,7 +8,7 @@
 #include <setjmp.h>
 #include <sysexits.h>
 
 #include <setjmp.h>
 #include <sysexits.h>
 
-static char SccsId[] = "@(#)mail.local.c       4.13    %G%";
+static char SccsId[] = "@(#)mail.local.c       4.14    %G%";
 
 #define SENDMAIL       "/usr/lib/sendmail"
 
 
 #define SENDMAIL       "/usr/lib/sendmail"
 
@@ -358,8 +358,12 @@ FILE *f1, *f2;
        let[nlet].adr = nextadr;        /* last plus 1 */
 }
 
        let[nlet].adr = nextadr;        /* last plus 1 */
 }
 
-copylet(n, f, type) FILE *f;
-{      int ch, k;
+copylet(n, f, type)
+       FILE *f;
+{
+       int ch;
+       long k;
+
        fseek(tmpf, let[n].adr, 0);
        k = let[n+1].adr - let[n].adr;
        while(k-- > 1 && (ch=fgetc(tmpf))!='\n')
        fseek(tmpf, let[n].adr, 0);
        k = let[n+1].adr - let[n].adr;
        while(k-- > 1 && (ch=fgetc(tmpf))!='\n')
@@ -633,13 +637,14 @@ char *fromaddr;
        mask = umask(MAILMODE);
        if (!safefile(file))
                return(0);
        mask = umask(MAILMODE);
        if (!safefile(file))
                return(0);
+       lock(file);
        malf = fopen(file, "a");
        umask(mask);
        if (malf == NULL) {
        malf = fopen(file, "a");
        umask(mask);
        if (malf == NULL) {
+               unlock();
                fprintf(stdout, "mail: cannot append to %s\n", file);
                return(0);
        }
                fprintf(stdout, "mail: cannot append to %s\n", file);
                return(0);
        }
-       lock(file);
        chown(file, pw->pw_uid, pw->pw_gid);
        {
                hp = gethostbyname("localhost");
        chown(file, pw->pw_uid, pw->pw_gid);
        {
                hp = gethostbyname("localhost");