=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mail/quit.c,v retrieving revision 1.2 retrieving revision 1.3 diff -c -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 **** ! /* $OpenBSD: quit.c,v 1.2 1996/06/11 12:53:48 deraadt Exp $ */ /* $NetBSD: quit.c,v 1.5 1996/06/08 19:48:37 christos Exp $ */ /* --- 1,4 ---- ! /* $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,44 **** #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 $"; #endif #endif /* not lint */ --- 38,44 ---- #if 0 static char sccsid[] = "@(#)quit.c 8.1 (Berkeley) 6/6/93"; #else ! static char rcsid[] = "$OpenBSD: quit.c,v 1.3 1997/03/29 03:01:47 millert Exp $"; #endif #endif /* not lint */ *************** *** 113,125 **** 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; rbuf = NULL; if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) { printf("New mail has arrived.\n"); --- 113,126 ---- if (fbuf == NULL) goto newmail; if (flock(fileno(fbuf), LOCK_EX) == -1) { perror("Unable to lock mailbox"); Fclose(fbuf); return; } ! 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,205 **** printf("Held %d message%s in %s\n", p, p == 1 ? "" : "s", mailname); Fclose(fbuf); ! dot_unlock(mailname); return; } if (c == 0) { if (p != 0) { writeback(rbuf); Fclose(fbuf); ! dot_unlock(mailname); return; } goto cream; --- 193,206 ---- printf("Held %d message%s in %s\n", p, p == 1 ? "" : "s", mailname); Fclose(fbuf); ! spool_unlock(); return; } if (c == 0) { if (p != 0) { writeback(rbuf); Fclose(fbuf); ! spool_unlock(); return; } goto cream; *************** *** 218,224 **** if ((obuf = Fopen(tempQuit, "w")) == NULL) { perror(tempQuit); Fclose(fbuf); ! dot_unlock(mailname); return; } if ((ibuf = Fopen(tempQuit, "r")) == NULL) { --- 219,225 ---- if ((obuf = Fopen(tempQuit, "w")) == NULL) { perror(tempQuit); Fclose(fbuf); ! spool_unlock(); return; } if ((ibuf = Fopen(tempQuit, "r")) == NULL) { *************** *** 226,232 **** rm(tempQuit); Fclose(obuf); Fclose(fbuf); ! dot_unlock(mailname); return; } rm(tempQuit); --- 227,233 ---- rm(tempQuit); Fclose(obuf); Fclose(fbuf); ! spool_unlock(); return; } rm(tempQuit); *************** *** 240,246 **** Fclose(ibuf); Fclose(obuf); Fclose(fbuf); ! dot_unlock(mailname); return; } Fclose(obuf); --- 241,247 ---- Fclose(ibuf); Fclose(obuf); Fclose(fbuf); ! spool_unlock(); return; } Fclose(obuf); *************** *** 249,255 **** perror(mbox); Fclose(ibuf); Fclose(fbuf); ! dot_unlock(mailname); return; } } --- 250,256 ---- perror(mbox); Fclose(ibuf); Fclose(fbuf); ! spool_unlock(); return; } } *************** *** 257,263 **** if ((obuf = Fopen(mbox, "a")) == NULL) { perror(mbox); Fclose(fbuf); ! dot_unlock(mailname); return; } fchmod(fileno(obuf), 0600); --- 258,264 ---- if ((obuf = Fopen(mbox, "a")) == NULL) { perror(mbox); Fclose(fbuf); ! spool_unlock(); return; } fchmod(fileno(obuf), 0600); *************** *** 269,275 **** Fclose(ibuf); Fclose(obuf); Fclose(fbuf); ! dot_unlock(mailname); return; } --- 270,276 ---- Fclose(ibuf); Fclose(obuf); Fclose(fbuf); ! spool_unlock(); return; } *************** *** 296,302 **** perror(mbox); Fclose(obuf); Fclose(fbuf); ! dot_unlock(mailname); return; } Fclose(obuf); --- 297,303 ---- perror(mbox); Fclose(obuf); Fclose(fbuf); ! spool_unlock(); return; } Fclose(obuf); *************** *** 313,319 **** if (p != 0) { writeback(rbuf); Fclose(fbuf); ! dot_unlock(mailname); return; } --- 314,320 ---- if (p != 0) { writeback(rbuf); Fclose(fbuf); ! spool_unlock(); return; } *************** *** 334,352 **** Fclose(abuf); alter(mailname); Fclose(fbuf); ! dot_unlock(mailname); return; } demail(); Fclose(fbuf); ! dot_unlock(mailname); return; newmail: printf("Thou hast new mail.\n"); if (fbuf != NULL) { Fclose(fbuf); ! dot_unlock(mailname); } } --- 335,353 ---- Fclose(abuf); alter(mailname); Fclose(fbuf); ! spool_unlock(); return; } demail(); Fclose(fbuf); ! spool_unlock(); return; newmail: printf("Thou hast new mail.\n"); if (fbuf != NULL) { Fclose(fbuf); ! spool_unlock(); } } *************** *** 418,424 **** register struct message *mp; FILE *obuf, *ibuf, *readstat = NULL; struct stat statb; ! char *tempname; if (readonly) return; --- 419,425 ---- register struct message *mp; FILE *obuf, *ibuf, *readstat = NULL; struct stat statb; ! char tempname[MAXPATHLEN]; if (readonly) return; *************** *** 447,455 **** goto done; ibuf = NULL; if (stat(mailname, &statb) >= 0 && statb.st_size > mailsize) { ! tempname = tempnam(tmpdir, "mbox"); ! if ((obuf = Fopen(tempname, "w")) == NULL) { perror(tempname); relsesigs(); reset(0); --- 448,459 ---- goto done; ibuf = NULL; if (stat(mailname, &statb) >= 0 && statb.st_size > mailsize) { ! int fd; ! snprintf(tempname, sizeof(tempname), "%s/%s", tmpdir, ! "mboxXXXXXXXXXX"); ! if ((fd = mkstemp(tempname)) == -1 || ! (obuf = Fdopen(fd, "w")) == NULL) { perror(tempname); relsesigs(); reset(0); *************** *** 473,479 **** reset(0); } rm(tempname); - free(tempname); } printf("\"%s\" ", mailname); fflush(stdout); --- 477,482 ----