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
add imagen
[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
b044289
..
b19dff7
100644
(file)
--- a/
usr/src/usr.bin/mail/quit.c
+++ b/
usr/src/usr.bin/mail/quit.c
@@
-1,7
+1,16
@@
-#
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char *sccsid = "@(#)quit.c 5.2 (Berkeley) %G%";
+#endif not lint
#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
+18,6
@@
* Termination processing.
*/
* Termination processing.
*/
-static char *SccsId = "@(#)quit.c 2.2 %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.
@@
-19,8
+26,8
@@
static char *SccsId = "@(#)quit.c 2.2 %G%";
quit()
{
quit()
{
- int mcount, p, modify, autohold, anystat, holdbit;
- FILE *ibuf, *obuf, *fbuf, *rbuf, *readstat;
+ int mcount, p, modify, autohold, anystat, holdbit
, nohold
;
+ 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
+54,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
+84,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;
@@
-89,6
+97,9
@@
quit()
anystat = 0;
autohold = value("hold") != NOSTR;
holdbit = autohold ? MPRESERVE : MBOX;
anystat = 0;
autohold = value("hold") != NOSTR;
holdbit = autohold ? MPRESERVE : MBOX;
+ nohold = MBOX|MSAVED|MDELETED|MPRESERVE;
+ if (value("keepsave") != NOSTR)
+ nohold &= ~MSAVED;
for (mp = &message[0]; mp < &message[msgCount]; mp++) {
if (mp->m_flag & MNEW) {
mp->m_flag &= ~MNEW;
for (mp = &message[0]; mp < &message[msgCount]; mp++) {
if (mp->m_flag & MNEW) {
mp->m_flag &= ~MNEW;
@@
-98,7
+109,7
@@
quit()
anystat++;
if ((mp->m_flag & MTOUCH) == 0)
mp->m_flag |= MPRESERVE;
anystat++;
if ((mp->m_flag & MTOUCH) == 0)
mp->m_flag |= MPRESERVE;
- if ((mp->m_flag &
(MBOX|MSAVED|MDELETED|MPRESERVE)
) == 0)
+ if ((mp->m_flag &
nohold
) == 0)
mp->m_flag |= holdbit;
}
modify = 0;
mp->m_flag |= holdbit;
}
modify = 0;
@@
-126,13
+137,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;
@@
-149,51
+160,51
@@
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);
close(creat(mbox, 0600));
return;
}
fclose(obuf);
close(creat(mbox, 0600));
- if ((obuf = fopen(mbox, "
w
")) == NULL) {
+ if ((obuf = fopen(mbox, "
r+
")) == NULL) {
perror(mbox);
fclose(ibuf);
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++)
if (mp->m_flag & MBOX)
return;
}
for (mp = &message[0]; mp < &message[msgCount]; mp++)
if (mp->m_flag & MBOX)
- if (send(mp, obuf) < 0) {
+ if (send(mp, obuf
, 0
) < 0) {
perror(mbox);
fclose(ibuf);
fclose(obuf);
perror(mbox);
fclose(ibuf);
fclose(obuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
return;
}
@@
-215,10
+226,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);
@@
-234,7
+246,7
@@
quit()
if (p != 0) {
writeback(rbuf);
if (p != 0) {
writeback(rbuf);
-
unlock(
);
+
fclose(fbuf
);
return;
}
return;
}
@@
-245,24
+257,26
@@
quit()
cream:
if (rbuf != NULL) {
cream:
if (rbuf != NULL) {
-
fbuf = fopen(mailname, "w
");
- if (
f
buf == NULL)
+
abuf = 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);
}
/*
}
/*
@@
-271,7
+285,6
@@
newmail:
* saved. On any error, just return -1. Else return 0.
* Incorporate the any new mail that we found.
*/
* saved. On any error, just return -1. Else return 0.
* Incorporate the any new mail that we found.
*/
-
writeback(res)
register FILE *res;
{
writeback(res)
register FILE *res;
{
@@
-280,7
+293,7
@@
writeback(res)
FILE *obuf;
p = 0;
FILE *obuf;
p = 0;
- if ((obuf = fopen(mailname, "
w
")) == NULL) {
+ if ((obuf = fopen(mailname, "
r+
")) == NULL) {
perror(mailname);
return(-1);
}
perror(mailname);
return(-1);
}
@@
-292,7
+305,7
@@
writeback(res)
for (mp = &message[0]; mp < &message[msgCount]; mp++)
if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) {
p++;
for (mp = &message[0]; mp < &message[msgCount]; mp++)
if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) {
p++;
- if (send(mp, obuf) < 0) {
+ if (send(mp, obuf
, 0
) < 0) {
perror(mailname);
fclose(obuf);
return(-1);
perror(mailname);
fclose(obuf);
return(-1);
@@
-304,6
+317,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);