summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ctm
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1995-02-23 04:51:36 +0000
committerphk <phk@FreeBSD.org>1995-02-23 04:51:36 +0000
commit5f6ea960908c00743493efa5d8a357a49b8ccba1 (patch)
treee5c60eb19fd8f76412bb619d57cc4b1254e24aec /usr.sbin/ctm
parent8f431ad70aa5f27676cd31f2cf4008e8762ebcae (diff)
downloadFreeBSD-src-5f6ea960908c00743493efa5d8a357a49b8ccba1.zip
FreeBSD-src-5f6ea960908c00743493efa5d8a357a49b8ccba1.tar.gz
Make us a little safer, by writing to a tempfile, and rename when done.
Still needs more locking I belive.
Diffstat (limited to 'usr.sbin/ctm')
-rw-r--r--usr.sbin/ctm/ctm_rmail/ctm_rmail.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/usr.sbin/ctm/ctm_rmail/ctm_rmail.c b/usr.sbin/ctm/ctm_rmail/ctm_rmail.c
index 04eef38..b7d8134 100644
--- a/usr.sbin/ctm/ctm_rmail/ctm_rmail.c
+++ b/usr.sbin/ctm/ctm_rmail/ctm_rmail.c
@@ -213,6 +213,7 @@ read_piece(char *input_file)
char line[200];
char delta[30];
char pname[1000];
+ char tname[1000];
char junk[2];
ifp = stdin;
@@ -241,9 +242,10 @@ read_piece(char *input_file)
*s = '_';
mk_piece_name(pname, delta, pce, npieces);
- if ((ofp = fopen(pname, "w")) == NULL)
+ sprintf(tname,"tmp.%s",pname);
+ if ((ofp = fopen(tname, "w")) == NULL)
{
- err("cannot open '%s' for writing", pname);
+ err("cannot open '%s' for writing", tname);
status++;
continue;
}
@@ -267,7 +269,7 @@ read_piece(char *input_file)
fclose(ofp);
if (e)
- err("error writing %s", pname);
+ err("error writing %s", tname);
if (cksum != claimed_cksum)
err("checksum: read %d, calculated %d", claimed_cksum, cksum);
@@ -275,7 +277,15 @@ read_piece(char *input_file)
if (e || cksum != claimed_cksum)
{
err("%s %d/%d discarded", delta, pce, npieces);
- unlink(pname);
+ unlink(tname);
+ status++;
+ continue;
+ }
+
+ if (rename(tname, pname) < 0)
+ {
+ err("error renaming %s to %s",tname,pname);
+ unlink(tname);
status++;
continue;
}
OpenPOWER on IntegriCloud