summaryrefslogtreecommitdiff
path: root/usr.bin/mail/quit.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-06-11 12:54:26 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-06-11 12:54:26 +0000
commit1c5940ab5503bf389f03195f3d01a93353919abb (patch)
treea1e9691c11b7f36906f0943dc7d8464a56b98adc /usr.bin/mail/quit.c
parent5f733ec731243d90e1e65f27ce29e683e7a253a6 (diff)
from christos;
- Fix PR/105: Implement dot locking protocol and check return value of flock. - Fix PR/2247: Don't call unknown users "ubluit". Issue an error message. - Fix/add prototypes. - Fix warnings. - Use POSIX signal mask calls.
Diffstat (limited to 'usr.bin/mail/quit.c')
-rw-r--r--usr.bin/mail/quit.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/usr.bin/mail/quit.c b/usr.bin/mail/quit.c
index 0acb222c40d..bf63671f4cb 100644
--- a/usr.bin/mail/quit.c
+++ b/usr.bin/mail/quit.c
@@ -1,3 +1,6 @@
+/* $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 $ */
+
/*
* Copyright (c) 1980, 1993
* The Regents of the University of California. All rights reserved.
@@ -32,8 +35,11 @@
*/
#ifndef lint
-static char sccsid[] = "from: @(#)quit.c 8.1 (Berkeley) 6/6/93";
-static char rcsid[] = "$Id: quit.c,v 1.1 1995/10/18 08:45:39 deraadt Exp $";
+#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 */
#include "rcv.h"
@@ -50,7 +56,8 @@ static char rcsid[] = "$Id: quit.c,v 1.1 1995/10/18 08:45:39 deraadt Exp $";
* The "quit" command.
*/
int
-quitcmd()
+quitcmd(v)
+ void *v;
{
/*
* If we are sourcing, then return 1 so execute() can handle it.
@@ -70,7 +77,7 @@ void
quit()
{
int mcount, p, modify, autohold, anystat, holdbit, nohold;
- FILE *ibuf, *obuf, *fbuf, *rbuf, *readstat, *abuf;
+ FILE *ibuf = NULL, *obuf, *fbuf, *rbuf, *readstat = NULL, *abuf;
register struct message *mp;
register int c;
extern char *tempQuit, *tempResid;
@@ -105,7 +112,14 @@ quit()
fbuf = Fopen(mailname, "r");
if (fbuf == NULL)
goto newmail;
- flock(fileno(fbuf), LOCK_EX);
+ 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");
@@ -178,12 +192,14 @@ quit()
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;
@@ -202,6 +218,7 @@ quit()
if ((obuf = Fopen(tempQuit, "w")) == NULL) {
perror(tempQuit);
Fclose(fbuf);
+ dot_unlock(mailname);
return;
}
if ((ibuf = Fopen(tempQuit, "r")) == NULL) {
@@ -209,6 +226,7 @@ quit()
rm(tempQuit);
Fclose(obuf);
Fclose(fbuf);
+ dot_unlock(mailname);
return;
}
rm(tempQuit);
@@ -222,6 +240,7 @@ quit()
Fclose(ibuf);
Fclose(obuf);
Fclose(fbuf);
+ dot_unlock(mailname);
return;
}
Fclose(obuf);
@@ -230,13 +249,15 @@ quit()
perror(mbox);
Fclose(ibuf);
Fclose(fbuf);
+ dot_unlock(mailname);
return;
}
}
- if (value("append") != NOSTR) {
+ else {
if ((obuf = Fopen(mbox, "a")) == NULL) {
perror(mbox);
Fclose(fbuf);
+ dot_unlock(mailname);
return;
}
fchmod(fileno(obuf), 0600);
@@ -248,6 +269,7 @@ quit()
Fclose(ibuf);
Fclose(obuf);
Fclose(fbuf);
+ dot_unlock(mailname);
return;
}
@@ -274,6 +296,7 @@ quit()
perror(mbox);
Fclose(obuf);
Fclose(fbuf);
+ dot_unlock(mailname);
return;
}
Fclose(obuf);
@@ -290,6 +313,7 @@ quit()
if (p != 0) {
writeback(rbuf);
Fclose(fbuf);
+ dot_unlock(mailname);
return;
}
@@ -310,16 +334,20 @@ cream:
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)
+ if (fbuf != NULL) {
Fclose(fbuf);
+ dot_unlock(mailname);
+ }
}
/*
@@ -388,7 +416,7 @@ edstop()
extern char *tmpdir;
register int gotcha, c;
register struct message *mp;
- FILE *obuf, *ibuf, *readstat;
+ FILE *obuf, *ibuf, *readstat = NULL;
struct stat statb;
char *tempname;