Detect more errors while manipulating mailbox files and tell the user

about them.  Don't truncate mailbox files when a write error has occured.
This commit is contained in:
bad 1997-11-25 17:58:15 +00:00
parent 6598e022b2
commit 2f2497e5de
4 changed files with 62 additions and 19 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: collect.c,v 1.16 1997/10/31 22:21:37 mycroft Exp $ */
/* $NetBSD: collect.c,v 1.17 1997/11/25 17:58:15 bad Exp $ */
/*
* Copyright (c) 1980, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)collect.c 8.2 (Berkeley) 4/19/94";
#else
__RCSID("$NetBSD: collect.c,v 1.16 1997/10/31 22:21:37 mycroft Exp $");
__RCSID("$NetBSD: collect.c,v 1.17 1997/11/25 17:58:15 bad Exp $");
#endif
#endif /* not lint */
@ -434,7 +434,7 @@ exwrite(name, fp, f)
return(-1);
}
if ((of = Fopen(name, "w")) == NULL) {
perror(NOSTR);
perror(name);
return(-1);
}
lc = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: edit.c,v 1.6 1997/10/19 05:03:18 lukem Exp $ */
/* $NetBSD: edit.c,v 1.7 1997/11/25 17:58:17 bad Exp $ */
/*
* Copyright (c) 1980, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)edit.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: edit.c,v 1.6 1997/10/19 05:03:18 lukem Exp $");
__RCSID("$NetBSD: edit.c,v 1.7 1997/11/25 17:58:17 bad Exp $");
#endif
#endif /* not lint */
@ -174,10 +174,6 @@ run_editor(fp, size, type, readonly)
while ((t = getc(fp)) != EOF)
(void) putc(t, nf);
(void) fflush(nf);
if (fstat(fileno(nf), &statb) < 0)
modtime = 0;
else
modtime = statb.st_mtime;
if (ferror(nf)) {
(void) Fclose(nf);
perror(tempEdit);
@ -185,6 +181,10 @@ run_editor(fp, size, type, readonly)
nf = NULL;
goto out;
}
if (fstat(fileno(nf), &statb) < 0)
modtime = 0;
else
modtime = statb.st_mtime;
if (Fclose(nf) < 0) {
perror(tempEdit);
(void) unlink(tempEdit);

View File

@ -1,4 +1,4 @@
/* $NetBSD: names.c,v 1.6 1997/10/19 05:03:41 lukem Exp $ */
/* $NetBSD: names.c,v 1.7 1997/11/25 17:58:18 bad Exp $ */
/*
* Copyright (c) 1980, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)names.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: names.c,v 1.6 1997/10/19 05:03:41 lukem Exp $");
__RCSID("$NetBSD: names.c,v 1.7 1997/11/25 17:58:18 bad Exp $");
#endif
#endif /* not lint */
@ -273,8 +273,12 @@ outof(names, fo, hp)
rewind(fo);
(void) putc('\n', fout);
(void) fflush(fout);
if (ferror(fout))
if (ferror(fout)) {
perror(tempEdit);
senderr++;
(void) Fclose(fout);
goto cant;
}
(void) Fclose(fout);
}
@ -330,8 +334,13 @@ outof(names, fo, hp)
rewind(fin);
while ((c = getc(fin)) != EOF)
(void) putc(c, fout);
if (ferror(fout))
senderr++, perror(fname);
if (ferror(fout)) {
perror(fname);
senderr++;
(void) Fclose(fout);
(void) Fclose(fin);
goto cant;
}
(void) Fclose(fout);
(void) Fclose(fin);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: quit.c,v 1.7 1997/10/19 05:03:49 lukem Exp $ */
/* $NetBSD: quit.c,v 1.8 1997/11/25 17:58:19 bad Exp $ */
/*
* Copyright (c) 1980, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)quit.c 8.2 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: quit.c,v 1.7 1997/10/19 05:03:49 lukem Exp $");
__RCSID("$NetBSD: quit.c,v 1.8 1997/11/25 17:58:19 bad Exp $");
#endif
#endif /* not lint */
@ -138,6 +138,14 @@ nolock:
(void) putc(c, rbuf);
}
#endif
(void) fflush(rbuf);
if (ferror(rbuf)) {
perror(tempResid);
Fclose(rbuf);
Fclose(fbuf);
dot_unlock(mailname);
return;
}
Fclose(rbuf);
if ((rbuf = Fopen(tempResid, "r")) == NULL)
goto newmail;
@ -290,7 +298,8 @@ nolock:
Fclose(ibuf);
}
fflush(obuf);
trunc(obuf);
if (!ferror(obuf))
trunc(obuf); /* XXX or should we truncate? */
if (ferror(obuf)) {
perror(mbox);
Fclose(obuf);
@ -328,6 +337,14 @@ cream:
goto newmail;
while ((c = getc(rbuf)) != EOF)
(void) putc(c, abuf);
(void) fflush(abuf);
if (ferror(obuf)) {
perror(mailname);
Fclose(abuf);
Fclose(fbuf);
dot_unlock(mailname);
return;
}
Fclose(rbuf);
trunc(abuf);
Fclose(abuf);
@ -369,9 +386,16 @@ writeback(res)
return(-1);
}
#ifndef APPEND
if (res != NULL)
if (res != NULL) {
while ((c = getc(res)) != EOF)
(void) putc(c, obuf);
(void) fflush(obuf);
if (ferror(obuf)) {
perror(mailname);
Fclose(obuf);
return(-1);
}
}
#endif
for (mp = &message[0]; mp < &message[msgCount]; mp++)
if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) {
@ -388,7 +412,8 @@ writeback(res)
(void) putc(c, obuf);
#endif
fflush(obuf);
trunc(obuf);
if (!ferror(obuf))
trunc(obuf); /* XXX or show we truncate? */
if (ferror(obuf)) {
perror(mailname);
Fclose(obuf);
@ -463,6 +488,15 @@ edstop()
fseek(ibuf, (long)mailsize, 0);
while ((c = getc(ibuf)) != EOF)
(void) putc(c, obuf);
(void) fflush(obuf);
if (ferror(obuf)) {
perror(tempname);
Fclose(obuf);
Fclose(ibuf);
rm(tempname);
relsesigs();
reset(0);
}
Fclose(ibuf);
Fclose(obuf);
if ((ibuf = Fopen(tempname, "r")) == NULL) {