summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1998-11-22 22:50:52 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1998-11-22 22:50:52 +0000
commitbe4ee36e868897170cb8ec0c66348f09abf68633 (patch)
tree861b42af29d93be39632711322b26a43a0191fe6 /usr.sbin
parent6eec0e9b0ca67faaacd87ae6e97858dcd37fa0d3 (diff)
race-less tempnam() use
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ctm/ctm/ctm.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/usr.sbin/ctm/ctm/ctm.c b/usr.sbin/ctm/ctm/ctm.c
index 4d02ca0dc13..cbd20f93857 100644
--- a/usr.sbin/ctm/ctm/ctm.c
+++ b/usr.sbin/ctm/ctm/ctm.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: ctm.c,v 1.1 1996/10/30 17:32:58 graichen Exp $
+ * $Id: ctm.c,v 1.2 1998/11/22 22:50:51 deraadt Exp $
*
* This is the client program of 'CTM'. It will apply a CTM-patch to a
* collection of files.
@@ -166,9 +166,24 @@ Proc(char *filename, unsigned applied)
/* If we cannot seek, we're doomed, so copy to a tmp-file in that case */
if(!p && -1 == fseek(f,0,SEEK_END)) {
- char *fn = tempnam(TmpDir,"CTMclient");
- FILE *f2 = fopen(fn,"w+");
- int i;
+ char *fn;
+ FILE *f2 = NULL;
+ int fd, i;
+
+ while (1) {
+ fn = tempnam(TmpDir,"CTMclient");
+ if (fn == NULL)
+ break;
+ fd = open(fn, O_CREAT|O_EXCL|O_RDWR);
+ if (fd == -1 && errno == EEXIST) {
+ free(fn);
+ continue;
+ }
+ if (fd == -1)
+ break;
+ f2 = fopen(fn,"w+");
+ break;
+ }
if(!f2) {
perror(fn);