=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mail/quit.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- src/usr.bin/mail/quit.c 1996/06/11 12:53:48 1.2 +++ src/usr.bin/mail/quit.c 1997/03/29 03:01:47 1.3 @@ -1,4 +1,4 @@ -/* $OpenBSD: quit.c,v 1.2 1996/06/11 12:53:48 deraadt Exp $ */ +/* $OpenBSD: quit.c,v 1.3 1997/03/29 03:01:47 millert Exp $ */ /* $NetBSD: quit.c,v 1.5 1996/06/08 19:48:37 christos Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)quit.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: quit.c,v 1.2 1996/06/11 12:53:48 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: quit.c,v 1.3 1997/03/29 03:01:47 millert Exp $"; #endif #endif /* not lint */ @@ -113,13 +113,14 @@ if (fbuf == NULL) goto newmail; if (flock(fileno(fbuf), LOCK_EX) == -1) { -nolock: perror("Unable to lock mailbox"); Fclose(fbuf); return; } - if (dot_lock(mailname, 1, stdout, ".") == -1) - goto nolock; + if (!spool_lock()) { + Fclose(fbuf); + return; /* mail.local printed error for us */ + } rbuf = NULL; if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) { printf("New mail has arrived.\n"); @@ -192,14 +193,14 @@ printf("Held %d message%s in %s\n", p, p == 1 ? "" : "s", mailname); Fclose(fbuf); - dot_unlock(mailname); + spool_unlock(); return; } if (c == 0) { if (p != 0) { writeback(rbuf); Fclose(fbuf); - dot_unlock(mailname); + spool_unlock(); return; } goto cream; @@ -218,7 +219,7 @@ if ((obuf = Fopen(tempQuit, "w")) == NULL) { perror(tempQuit); Fclose(fbuf); - dot_unlock(mailname); + spool_unlock(); return; } if ((ibuf = Fopen(tempQuit, "r")) == NULL) { @@ -226,7 +227,7 @@ rm(tempQuit); Fclose(obuf); Fclose(fbuf); - dot_unlock(mailname); + spool_unlock(); return; } rm(tempQuit); @@ -240,7 +241,7 @@ Fclose(ibuf); Fclose(obuf); Fclose(fbuf); - dot_unlock(mailname); + spool_unlock(); return; } Fclose(obuf); @@ -249,7 +250,7 @@ perror(mbox); Fclose(ibuf); Fclose(fbuf); - dot_unlock(mailname); + spool_unlock(); return; } } @@ -257,7 +258,7 @@ if ((obuf = Fopen(mbox, "a")) == NULL) { perror(mbox); Fclose(fbuf); - dot_unlock(mailname); + spool_unlock(); return; } fchmod(fileno(obuf), 0600); @@ -269,7 +270,7 @@ Fclose(ibuf); Fclose(obuf); Fclose(fbuf); - dot_unlock(mailname); + spool_unlock(); return; } @@ -296,7 +297,7 @@ perror(mbox); Fclose(obuf); Fclose(fbuf); - dot_unlock(mailname); + spool_unlock(); return; } Fclose(obuf); @@ -313,7 +314,7 @@ if (p != 0) { writeback(rbuf); Fclose(fbuf); - dot_unlock(mailname); + spool_unlock(); return; } @@ -334,19 +335,19 @@ Fclose(abuf); alter(mailname); Fclose(fbuf); - dot_unlock(mailname); + spool_unlock(); return; } demail(); Fclose(fbuf); - dot_unlock(mailname); + spool_unlock(); return; newmail: printf("Thou hast new mail.\n"); if (fbuf != NULL) { Fclose(fbuf); - dot_unlock(mailname); + spool_unlock(); } } @@ -418,7 +419,7 @@ register struct message *mp; FILE *obuf, *ibuf, *readstat = NULL; struct stat statb; - char *tempname; + char tempname[MAXPATHLEN]; if (readonly) return; @@ -447,9 +448,12 @@ goto done; ibuf = NULL; if (stat(mailname, &statb) >= 0 && statb.st_size > mailsize) { - tempname = tempnam(tmpdir, "mbox"); + int fd; - if ((obuf = Fopen(tempname, "w")) == NULL) { + snprintf(tempname, sizeof(tempname), "%s/%s", tmpdir, + "mboxXXXXXXXXXX"); + if ((fd = mkstemp(tempname)) == -1 || + (obuf = Fdopen(fd, "w")) == NULL) { perror(tempname); relsesigs(); reset(0); @@ -473,7 +477,6 @@ reset(0); } rm(tempname); - free(tempname); } printf("\"%s\" ", mailname); fflush(stdout);