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 * Copyright (c) 1980, 1993
@ -38,7 +38,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)collect.c 8.2 (Berkeley) 4/19/94"; static char sccsid[] = "@(#)collect.c 8.2 (Berkeley) 4/19/94";
#else #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
#endif /* not lint */ #endif /* not lint */
@ -434,7 +434,7 @@ exwrite(name, fp, f)
return(-1); return(-1);
} }
if ((of = Fopen(name, "w")) == NULL) { if ((of = Fopen(name, "w")) == NULL) {
perror(NOSTR); perror(name);
return(-1); return(-1);
} }
lc = 0; 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 * Copyright (c) 1980, 1993
@ -38,7 +38,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)edit.c 8.1 (Berkeley) 6/6/93"; static char sccsid[] = "@(#)edit.c 8.1 (Berkeley) 6/6/93";
#else #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
#endif /* not lint */ #endif /* not lint */
@ -174,10 +174,6 @@ run_editor(fp, size, type, readonly)
while ((t = getc(fp)) != EOF) while ((t = getc(fp)) != EOF)
(void) putc(t, nf); (void) putc(t, nf);
(void) fflush(nf); (void) fflush(nf);
if (fstat(fileno(nf), &statb) < 0)
modtime = 0;
else
modtime = statb.st_mtime;
if (ferror(nf)) { if (ferror(nf)) {
(void) Fclose(nf); (void) Fclose(nf);
perror(tempEdit); perror(tempEdit);
@ -185,6 +181,10 @@ run_editor(fp, size, type, readonly)
nf = NULL; nf = NULL;
goto out; goto out;
} }
if (fstat(fileno(nf), &statb) < 0)
modtime = 0;
else
modtime = statb.st_mtime;
if (Fclose(nf) < 0) { if (Fclose(nf) < 0) {
perror(tempEdit); perror(tempEdit);
(void) unlink(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 * Copyright (c) 1980, 1993
@ -38,7 +38,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)names.c 8.1 (Berkeley) 6/6/93"; static char sccsid[] = "@(#)names.c 8.1 (Berkeley) 6/6/93";
#else #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
#endif /* not lint */ #endif /* not lint */
@ -273,8 +273,12 @@ outof(names, fo, hp)
rewind(fo); rewind(fo);
(void) putc('\n', fout); (void) putc('\n', fout);
(void) fflush(fout); (void) fflush(fout);
if (ferror(fout)) if (ferror(fout)) {
perror(tempEdit); perror(tempEdit);
senderr++;
(void) Fclose(fout);
goto cant;
}
(void) Fclose(fout); (void) Fclose(fout);
} }
@ -330,8 +334,13 @@ outof(names, fo, hp)
rewind(fin); rewind(fin);
while ((c = getc(fin)) != EOF) while ((c = getc(fin)) != EOF)
(void) putc(c, fout); (void) putc(c, fout);
if (ferror(fout)) if (ferror(fout)) {
senderr++, perror(fname); perror(fname);
senderr++;
(void) Fclose(fout);
(void) Fclose(fin);
goto cant;
}
(void) Fclose(fout); (void) Fclose(fout);
(void) Fclose(fin); (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 * Copyright (c) 1980, 1993
@ -38,7 +38,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)quit.c 8.2 (Berkeley) 4/28/95"; static char sccsid[] = "@(#)quit.c 8.2 (Berkeley) 4/28/95";
#else #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
#endif /* not lint */ #endif /* not lint */
@ -138,6 +138,14 @@ nolock:
(void) putc(c, rbuf); (void) putc(c, rbuf);
} }
#endif #endif
(void) fflush(rbuf);
if (ferror(rbuf)) {
perror(tempResid);
Fclose(rbuf);
Fclose(fbuf);
dot_unlock(mailname);
return;
}
Fclose(rbuf); Fclose(rbuf);
if ((rbuf = Fopen(tempResid, "r")) == NULL) if ((rbuf = Fopen(tempResid, "r")) == NULL)
goto newmail; goto newmail;
@ -290,7 +298,8 @@ nolock:
Fclose(ibuf); Fclose(ibuf);
} }
fflush(obuf); fflush(obuf);
trunc(obuf); if (!ferror(obuf))
trunc(obuf); /* XXX or should we truncate? */
if (ferror(obuf)) { if (ferror(obuf)) {
perror(mbox); perror(mbox);
Fclose(obuf); Fclose(obuf);
@ -328,6 +337,14 @@ cream:
goto newmail; goto newmail;
while ((c = getc(rbuf)) != EOF) while ((c = getc(rbuf)) != EOF)
(void) putc(c, abuf); (void) putc(c, abuf);
(void) fflush(abuf);
if (ferror(obuf)) {
perror(mailname);
Fclose(abuf);
Fclose(fbuf);
dot_unlock(mailname);
return;
}
Fclose(rbuf); Fclose(rbuf);
trunc(abuf); trunc(abuf);
Fclose(abuf); Fclose(abuf);
@ -369,9 +386,16 @@ writeback(res)
return(-1); return(-1);
} }
#ifndef APPEND #ifndef APPEND
if (res != NULL) if (res != NULL) {
while ((c = getc(res)) != EOF) while ((c = getc(res)) != EOF)
(void) putc(c, obuf); (void) putc(c, obuf);
(void) fflush(obuf);
if (ferror(obuf)) {
perror(mailname);
Fclose(obuf);
return(-1);
}
}
#endif #endif
for (mp = &message[0]; mp < &message[msgCount]; mp++) for (mp = &message[0]; mp < &message[msgCount]; mp++)
if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) { if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) {
@ -388,7 +412,8 @@ writeback(res)
(void) putc(c, obuf); (void) putc(c, obuf);
#endif #endif
fflush(obuf); fflush(obuf);
trunc(obuf); if (!ferror(obuf))
trunc(obuf); /* XXX or show we truncate? */
if (ferror(obuf)) { if (ferror(obuf)) {
perror(mailname); perror(mailname);
Fclose(obuf); Fclose(obuf);
@ -463,6 +488,15 @@ edstop()
fseek(ibuf, (long)mailsize, 0); fseek(ibuf, (long)mailsize, 0);
while ((c = getc(ibuf)) != EOF) while ((c = getc(ibuf)) != EOF)
(void) putc(c, obuf); (void) putc(c, obuf);
(void) fflush(obuf);
if (ferror(obuf)) {
perror(tempname);
Fclose(obuf);
Fclose(ibuf);
rm(tempname);
relsesigs();
reset(0);
}
Fclose(ibuf); Fclose(ibuf);
Fclose(obuf); Fclose(obuf);
if ((ibuf = Fopen(tempname, "r")) == NULL) { if ((ibuf = Fopen(tempname, "r")) == NULL) {