projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
install with -s
[unix-history]
/
usr
/
src
/
usr.bin
/
mail
/
quit.c
diff --git
a/usr/src/usr.bin/mail/quit.c
b/usr/src/usr.bin/mail/quit.c
index
10bd717
..
7b233ee
100644
(file)
--- a/
usr/src/usr.bin/mail/quit.c
+++ b/
usr/src/usr.bin/mail/quit.c
@@
-1,7
+1,10
@@
-#
+#ifndef lint
+static char *sccsid = "@(#)quit.c 2.9 (Berkeley) %G%";
+#endif
#include "rcv.h"
#include <sys/stat.h>
#include "rcv.h"
#include <sys/stat.h>
+#include <sys/file.h>
/*
* Rcv -- receive mail rationally.
/*
* Rcv -- receive mail rationally.
@@
-9,8
+12,6
@@
* Termination processing.
*/
* Termination processing.
*/
-static char *SccsId = "@(#)quit.c 2.5 %G%";
-
/*
* Save all of the undetermined messages at the top of "mbox"
* Save all untouched messages back in the system mailbox.
/*
* Save all of the undetermined messages at the top of "mbox"
* Save all untouched messages back in the system mailbox.
@@
-20,7
+21,7
@@
static char *SccsId = "@(#)quit.c 2.5 %G%";
quit()
{
int mcount, p, modify, autohold, anystat, holdbit, nohold;
quit()
{
int mcount, p, modify, autohold, anystat, holdbit, nohold;
- FILE *ibuf, *obuf, *fbuf, *rbuf, *readstat;
+ FILE *ibuf, *obuf, *fbuf, *rbuf, *readstat
, *abuf
;
register struct message *mp;
register int c;
extern char tempQuit[], tempResid[];
register struct message *mp;
register int c;
extern char tempQuit[], tempResid[];
@@
-47,19
+48,21
@@
quit()
* anything with the mailbox, unless mail locking works.
*/
* anything with the mailbox, unless mail locking works.
*/
- lock(mailname);
+ fbuf = fopen(mailname, "r");
+ if (fbuf == NULL)
+ goto newmail;
+ flock(fileno(fbuf), LOCK_EX);
#ifndef CANLOCK
if (selfsent) {
printf("You have new mail.\n");
#ifndef CANLOCK
if (selfsent) {
printf("You have new mail.\n");
-
unlock(
);
+
fclose(fbuf
);
return;
}
#endif
rbuf = NULL;
return;
}
#endif
rbuf = NULL;
- if (
stat(mailname
, &minfo) >= 0 && minfo.st_size > mailsize) {
+ if (
fstat(fileno(fbuf)
, &minfo) >= 0 && minfo.st_size > mailsize) {
printf("New mail has arrived.\n");
rbuf = fopen(tempResid, "w");
printf("New mail has arrived.\n");
rbuf = fopen(tempResid, "w");
- fbuf = fopen(mailname, "r");
if (rbuf == NULL || fbuf == NULL)
goto newmail;
#ifdef APPEND
if (rbuf == NULL || fbuf == NULL)
goto newmail;
#ifdef APPEND
@@
-75,7
+78,6
@@
quit()
putc(c, rbuf);
}
#endif
putc(c, rbuf);
}
#endif
- fclose(fbuf);
fclose(rbuf);
if ((rbuf = fopen(tempResid, "r")) == NULL)
goto newmail;
fclose(rbuf);
if ((rbuf = fopen(tempResid, "r")) == NULL)
goto newmail;
@@
-129,13
+131,13
@@
quit()
printf("Held 1 message in %s\n", mailname);
else
printf("Held %2d messages in %s\n", p, mailname);
printf("Held 1 message in %s\n", mailname);
else
printf("Held %2d messages in %s\n", p, mailname);
-
unlock(
);
+
fclose(fbuf
);
return;
}
if (c == 0) {
if (p != 0) {
writeback(rbuf);
return;
}
if (c == 0) {
if (p != 0) {
writeback(rbuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
goto cream;
return;
}
goto cream;
@@
-152,27
+154,27
@@
quit()
if (value("append") == NOSTR) {
if ((obuf = fopen(tempQuit, "w")) == NULL) {
perror(tempQuit);
if (value("append") == NOSTR) {
if ((obuf = fopen(tempQuit, "w")) == NULL) {
perror(tempQuit);
-
unlock(
);
+
fclose(fbuf
);
return;
}
if ((ibuf = fopen(tempQuit, "r")) == NULL) {
perror(tempQuit);
remove(tempQuit);
fclose(obuf);
return;
}
if ((ibuf = fopen(tempQuit, "r")) == NULL) {
perror(tempQuit);
remove(tempQuit);
fclose(obuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
remove(tempQuit);
return;
}
remove(tempQuit);
- if ((
f
buf = fopen(mbox, "r")) != NULL) {
- while ((c = getc(
f
buf)) != EOF)
+ if ((
a
buf = fopen(mbox, "r")) != NULL) {
+ while ((c = getc(
a
buf)) != EOF)
putc(c, obuf);
putc(c, obuf);
- fclose(
f
buf);
+ fclose(
a
buf);
}
if (ferror(obuf)) {
perror(tempQuit);
fclose(ibuf);
fclose(obuf);
}
if (ferror(obuf)) {
perror(tempQuit);
fclose(ibuf);
fclose(obuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
fclose(obuf);
return;
}
fclose(obuf);
@@
-180,14
+182,14
@@
quit()
if ((obuf = fopen(mbox, "r+")) == NULL) {
perror(mbox);
fclose(ibuf);
if ((obuf = fopen(mbox, "r+")) == NULL) {
perror(mbox);
fclose(ibuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
}
if (value("append") != NOSTR)
if ((obuf = fopen(mbox, "a")) == NULL) {
perror(mbox);
return;
}
}
if (value("append") != NOSTR)
if ((obuf = fopen(mbox, "a")) == NULL) {
perror(mbox);
-
unlock(
);
+
fclose(fbuf
);
return;
}
for (mp = &message[0]; mp < &message[msgCount]; mp++)
return;
}
for (mp = &message[0]; mp < &message[msgCount]; mp++)
@@
-196,7
+198,7
@@
quit()
perror(mbox);
fclose(ibuf);
fclose(obuf);
perror(mbox);
fclose(ibuf);
fclose(obuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
return;
}
@@
-218,10
+220,11
@@
quit()
fclose(ibuf);
fflush(obuf);
}
fclose(ibuf);
fflush(obuf);
}
+ trunc(obuf);
if (ferror(obuf)) {
perror(mbox);
fclose(obuf);
if (ferror(obuf)) {
perror(mbox);
fclose(obuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
fclose(obuf);
return;
}
fclose(obuf);
@@
-237,7
+240,7
@@
quit()
if (p != 0) {
writeback(rbuf);
if (p != 0) {
writeback(rbuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
return;
}
@@
-248,24
+251,26
@@
quit()
cream:
if (rbuf != NULL) {
cream:
if (rbuf != NULL) {
-
f
buf = fopen(mailname, "r+");
- if (
f
buf == NULL)
+
a
buf = fopen(mailname, "r+");
+ if (
a
buf == NULL)
goto newmail;
while ((c = getc(rbuf)) != EOF)
goto newmail;
while ((c = getc(rbuf)) != EOF)
- putc(c,
f
buf);
+ putc(c,
a
buf);
fclose(rbuf);
fclose(rbuf);
- fclose(fbuf);
+ trunc(abuf);
+ fclose(abuf);
alter(mailname);
alter(mailname);
-
unlock(
);
+
fclose(fbuf
);
return;
}
demail();
return;
}
demail();
-
unlock(
);
+
fclose(fbuf
);
return;
newmail:
printf("Thou hast new mail.\n");
return;
newmail:
printf("Thou hast new mail.\n");
- unlock();
+ if (fbuf != NULL)
+ fclose(fbuf);
}
/*
}
/*
@@
-306,6
+311,7
@@
writeback(res)
putc(c, obuf);
#endif
fflush(obuf);
putc(c, obuf);
#endif
fflush(obuf);
+ trunc(obuf);
if (ferror(obuf)) {
perror(mailname);
fclose(obuf);
if (ferror(obuf)) {
perror(mailname);
fclose(obuf);